Skip to content

feat: Templated names and tags for Consul targets#610

Merged
karimra merged 3 commits intoopenconfig:mainfrom
nlgotz:ng/consul-target-name
Mar 13, 2025
Merged

feat: Templated names and tags for Consul targets#610
karimra merged 3 commits intoopenconfig:mainfrom
nlgotz:ng/consul-target-name

Conversation

@nlgotz
Copy link
Contributor

@nlgotz nlgotz commented Feb 24, 2025

This adds the ability to use Go Templates on Consul targets to set both the name of the target as well as event-tags. The primary driving force for this comes from Telegraf's Prometheus Input Plugin which also has Consul support and allows for using Go templates to set the name/tags as well.

As an example, you are now able to do something like:

loader:
    type: consul
    address: consul:8500
    datacenter: "dc99"
    services:
        - name: gnmic-sros
          target-name: "{{.Meta.device}}"
          target-tags:
              region: "{{.Meta.region}}"
              geo: "{{.Meta.geo}}"
              test: "{{.Meta.test}}"

This also removes a debugging statement in pkg/config/loader.go that could potentially expose passwords in log messages

@karimra
Copy link
Collaborator

karimra commented Feb 24, 2025

Why not use the existing fields under config? They can be set to some Go template, the only missing piece is to execute them.
To use your example, it would look like:

loader:
    type: consul
    address: consul:8500
    datacenter: "dc99"
    services:
        - name: gnmic-sros
          config:
            name: "{{.Meta.device}}"
            event-tags:
              region: "{{.Meta.region}}"
              geo: "{{.Meta.geo}}"
              test: "{{.Meta.test}}"

@nlgotz
Copy link
Contributor Author

nlgotz commented Feb 24, 2025

@karimra - updated to use the config section to work with that example config. It's is much cleaner

@karimra karimra merged commit b1b5e07 into openconfig:main Mar 13, 2025
2 checks passed
@karimra
Copy link
Collaborator

karimra commented Mar 13, 2025

Thanks for the contribution! And sorry for the delay.

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.

2 participants