Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[telegraf] fix: add starlark_processor template #546

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

hungran
Copy link

@hungran hungran commented Mar 12, 2023

Hi,
This is another way intend to fix this issue #544
Related: #545 & #239

values.yaml looks like:

config:
  processors: 
    - starlark: true
    - foo: 
        bar: a

result:

---


apiVersion: v1
kind: ConfigMap
metadata:
  name: example
  labels:
    helm.sh/chart: example-0.1.0
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/name: example
    app.kubernetes.io/instance: example
data:
  telegraf.conf: |+
    
    [agent]
    
    [[processors.starlark]]
      ## The Starlark source can be set as a string in this configuration file, or
      ## by referencing a file containing the script.  Only one source or script
      ## should be set at once.
    
      ## Source of the Starlark script.
      source = '''
    def apply(metric):
       if metric.name == "prometheus_remote_write":
            for k, v in metric.fields.items():
                metric.name = k
                metric.fields["value"] = v
                metric.fields.pop(k)
       return metric
    '''
    [[processors.foo]]
      bar = "a"

I don't know if the starlark has another scripts so I put source only like instruction
can do if there are any field could be needed under starlark

  • CHANGELOG.md updated
  • Rebased/mergable
  • Tests pass
  • Sign CLA (if not already signed)

@hungran hungran changed the title fix: add starlark_processor template [telegraf] fix: add starlark_processor template Mar 12, 2023
@hungran
Copy link
Author

hungran commented Mar 12, 2023

@powersj can you have a look?

@hungran
Copy link
Author

hungran commented Mar 13, 2023

could have this under tmpl func if we need another script for starlark

{{/*
Helper function to create a starlark processor configuration block
*/}}
{{- define "telegraf.starlark_processor" -}}
[[processors.starlark]]
{{- range $key, $value := . -}}
{{- if $value -}}
{{- $tp := typeOf $value -}}
{{- if eq $tp "string" -}}
{{ $key | nindent 2 }} = {{ $value | nindent 2 }}
{{- end }}
{{- if eq $tp "float64" }}
{{ $key }} = {{ $value | int64 }}
{{- end }}
{{- if eq $tp "int" }}
{{ $key }} = {{ $value | int64 }}
{{- end }}
{{- if eq $tp "bool" }}
{{ $key }} = {{ $value }}
{{- end }}
{{- end }}
{{- end }}
{{- end -}}

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

Successfully merging this pull request may close these issues.

1 participant