Skip to content
This repository has been archived by the owner on Jan 5, 2022. It is now read-only.

Unclear how to set metric filtering selectors #113

Open
sciurus opened this issue Sep 4, 2019 · 2 comments
Open

Unclear how to set metric filtering selectors #113

sciurus opened this issue Sep 4, 2019 · 2 comments

Comments

@sciurus
Copy link

sciurus commented Sep 4, 2019

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
Copy link
Author

sciurus commented Sep 4, 2019

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
Copy link
Author

sciurus commented Sep 16, 2019

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant