influxdata / tick-charts

A repository for Helm Charts for the full TICK Stack
Apache License 2.0
90 stars 74 forks source link

Unclear how to set metric filtering selectors #113

Open sciurus opened 5 years ago

sciurus commented 5 years ago

In the examples at https://github.com/influxdata/telegraf/blob/master/docs/CONFIGURATION.md#filtering-examples, I can see that tagpass is a table nested under it's input's entry in the array of tables. A valid config would be

[[inputs.disk]]
  [inputs.disk.tagpass]
    fstype = [ "ext4" ]

However, I don't see a way to get this helm chart to generate that TOML. If I try

    config:
      inputs:
        defaultdisk:
          disk:
            tagpass:
                fstype:
                    - ext4

I get

    [[inputs.disk]]
      [[inputs.disk.tagpass]]
        fstype = [
            "ext4"
        ]

Notice the double brackets around inputs.disk.tagpass instead of single brackets.

sciurus commented 5 years ago

My read of https://github.com/influxdata/tick-charts/blob/master/telegraf-s/templates/_helpers.tpl#L94-L175 is that it's essentially duplicated twice in order to handle multiple levels of nesting.

I.E. if I set

    config:
      inputs:
        defaultdisk:
          disk:
            tagpass:
                fstype:
                    - ext4
                foo:
                    bar:
                        - baz

then change the helper to

+++ b/libs/influx/k8s/charts/telegraf/templates/_helpers.tpl
@@ -95,7 +95,7 @@ We truncate at 24 chars because some Kubernetes name fields are limited to this
 {{- range $inputIdx, $configObject := . -}}
     {{- range $input, $config := . -}}

-    [[inputs.{{- $input }}]]
+    [[FIRSTinputs.{{- $input }}]]
     {{- if $config -}}
     {{- $tp := typeOf $config -}}
     {{- if eq $tp "map[string]interface {}" -}}
@@ -139,7 +139,7 @@ We truncate at 24 chars because some Kubernetes name fields are limited to this
       ]
           {{- end }}
           {{- if eq $tp "map[string]interface {}" }}
-      [[inputs.{{ $input }}.{{ $key }}]]
+      [[SECONDinputs.{{ $input }}.{{ $key }}]]
             {{- range $k, $v := $value }}
               {{- $tps := typeOf $v }}
               {{- if eq $tps "string" }}
@@ -160,7 +160,7 @@ We truncate at 24 chars because some Kubernetes name fields are limited to this
         ]
               {{- end }}
               {{- if eq $tps "map[string]interface {}"}}
-        [[inputs.{{ $input }}.{{ $key }}.{{ $k }}]]
+        [[THIRDinputs.{{ $input }}.{{ $key }}.{{ $k }}]]
                 {{- range $foo, $bar := $v }}
             {{ $foo }} = {{ $bar | quote }}
                 {{- end }}
@@ -172,4 +172,4 @@ We truncate at 24 chars because some Kubernetes name fields are limited to this

and render it I get the TOML

    [[FIRSTinputs.disk]]
      [[SECONDinputs.disk.tagpass]]
        [[THIRDinputs.disk.tagpass.foo]]
            bar = "[baz]"
        fstype = [
            "ext4",
        ]

(The way baz is rendered there is unexpected, but that tangential to what I'm after)

I guess the additional levels use [[in order to support plugins like postgresql_extensible, where you could have miltiple[[inputs.postgresql_extensible.query]] inside [[inputs.postgresql_extensible]]

The only fix that comes to my mind is to make this even more comples by adding some logic at https://github.com/influxdata/tick-charts/blob/master/telegraf-s/templates/_helpers.tpl#L141-L142 to check the key name against namepass, namedrop, tagpass, and tagdrop and use [] if they match and [[]] if they don't.

sciurus commented 5 years ago

I've solved our immediate issue by this diff to our fork of the chart:

diff --git a/libs/influx/k8s/charts/telegraf/templates/_helpers.tpl b/libs/influx/k8s/charts/telegraf/templates/_helpers.tpl
index 93ace660..322bfd60 100755
--- a/libs/influx/k8s/charts/telegraf/templates/_helpers.tpl
+++ b/libs/influx/k8s/charts/telegraf/templates/_helpers.tpl
@@ -139,7 +139,11 @@ We truncate at 24 chars because some Kubernetes name fields are limited to this
       ]
           {{- end }}
           {{- if eq $tp "map[string]interface {}" }}
+            {{- if eq $key "tagpass" }}
+      [inputs.{{ $input }}.{{ $key }}]
+            {{- else }}
       [[inputs.{{ $input }}.{{ $key }}]]
+            {{- end }}
             {{- range $k, $v := $value }}
               {{- $tps := typeOf $v }}
               {{- if eq $tps "string" }}
@@ -172,4 +176,4 @@ We truncate at 24 chars because some Kubernetes name fields are limited to this

If these charts are still maintained, I'm happy to sign a CLA and collaborate on a more general fix.