about summary refs log tree commit diff
path: root/modules/services/logging
diff options
context:
space:
mode:
authorShea Levy <shea@shealevy.com>2012-07-11 11:59:00 -0400
committerShea Levy <shea@shealevy.com>2012-07-11 11:59:00 -0400
commit315087def17d0aba7d4cca976ef2e5bf80f098cb (patch)
tree5b22bed29a484bc0d26e7cb18d5cfa0a56435301 /modules/services/logging
parent3039caf5ad3657ffd8bc84929ffc9eca44d18292 (diff)
downloadnixlib-315087def17d0aba7d4cca976ef2e5bf80f098cb.tar
nixlib-315087def17d0aba7d4cca976ef2e5bf80f098cb.tar.gz
nixlib-315087def17d0aba7d4cca976ef2e5bf80f098cb.tar.bz2
nixlib-315087def17d0aba7d4cca976ef2e5bf80f098cb.tar.lz
nixlib-315087def17d0aba7d4cca976ef2e5bf80f098cb.tar.xz
nixlib-315087def17d0aba7d4cca976ef2e5bf80f098cb.tar.zst
nixlib-315087def17d0aba7d4cca976ef2e5bf80f098cb.zip
logstash: use {name=; value='} attrsets for repeated name-value pairs instead of parallel lists
Diffstat (limited to 'modules/services/logging')
-rw-r--r--modules/services/logging/logstash.nix26
1 files changed, 13 insertions, 13 deletions
diff --git a/modules/services/logging/logstash.nix b/modules/services/logging/logstash.nix
index f8b0d353cad6..2130ddcd2b94 100644
--- a/modules/services/logging/logstash.nix
+++ b/modules/services/logging/logstash.nix
@@ -17,7 +17,7 @@ let
       (concatStringsSep ", " (map attrNameToConfigList (attrNames attrs))) +
       " ]";
 
-  valueToConfig = name: value: 
+  valueToConfig = nvpair: let name = nvpair.name; value = nvpair.value; in
     if (isAttrs value) && ((!(value ? __type)) || value.__type == "repeated")
       then ''
         ${name} {
@@ -26,12 +26,15 @@ let
       ''
       else "${name} => ${exprToConfig value}";
 
-  repeatedAttrsToConfig = names: values:
-      concatStringsSep "\n" (zipListsWith valueToConfig names values);
+  repeatedAttrsToConfig = values:
+      concatStringsSep "\n" (map valueToConfig values);
 
   attrsToConfig = attrs:
     let
-      attrToConfig = name: valueToConfig name (getAttr name attrs);
+      attrToConfig = name: valueToConfig {
+        inherit name;
+        value = (getAttr name attrs);
+      };
     in
       concatStringsSep "\n" (map attrToConfig (attrNames attrs));
 
@@ -51,7 +54,7 @@ let
       if isFloat expr then expr.value else
       if isList expr then listToConfig expr else
       if isHash expr then hashToConfig expr.value else
-      if isRepeatedAttrs expr then repeatedAttrsToConfig expr.names expr.values
+      if isRepeatedAttrs expr then repeatedAttrsToConfig expr.values
       else attrsToConfig expr;
 
   mergeConfigs = configs:
@@ -60,14 +63,11 @@ let
         let
           isRepeated = newAttrs ? __type && newAttrs.__type == "repeated";
         in {
-            names = attrs.names ++
-              (if isRepeated then newAttrs.names else attrNames newAttrs);
-
-            values = attrs.values ++
-              (if isRepeated then newAttrs.values else attrValues newAttrs);
+            values = attrs.values ++ (if isRepeated then newAttrs.values else
+              map (name: { inherit name; value = getAttr name newAttrs; })
+              (attrNames newAttrs));
           };
-    in (foldl op { names = []; values = []; } configs) //
-      { __type = "repeated"; };
+    in (foldl op { values = []; } configs) // { __type = "repeated"; };
 
 in
 
@@ -92,7 +92,7 @@ in
           and names are strings that can be repeated. name-value pairs with no
           repeats are represented by attr sets. name-value pairs with repeats
           are represented by an attrset with attr "__type" = "repeated" and
-          attrs "names" and "values" as matching lists pairing name and value.
+          attr "values" as a list of {name; value;} attrsets.
           bools, strings, ints, and arrays are mapped directly. Floats are
           represented as an attrset with attr "__type" = "float" and attr value
           set to the string representation of the float. Hashes are represented