telegraf icon indicating copy to clipboard operation
telegraf copied to clipboard

Plugin label cannot contain capitals

Open Hipska opened this issue 2 weeks ago • 6 comments

Relevant telegraf.conf

[[inputs.ping]]
  [inputs.ping.labels]
    key = "FOObar"

Logs from Telegraf

2025-12-09T11:42:24Z E! loading config file telegraf.conf failed: error parsing ping, invalid label in plugin inputs.ping: invalid value "FOObar"

System info

Telegraf 1.37.0

Docker

No response

Steps to reproduce

  1. Run telegraf config check

Expected behavior

According to TSD-010, the labels and their value could contain capital letters.

Actual behavior

Telegraf errors out when using capital letters in key or value for a label.

Additional info

No response

Hipska avatar Dec 09 '25 11:12 Hipska

cc @neelayu

Hipska avatar Dec 09 '25 11:12 Hipska

Thanks @Hipska for the finding. I think there was some confusion initially as I had implemented the functionality before the spec was proposed and that implementation did not have uppercase characters.

We can fix it in the regex here https://github.com/influxdata/telegraf/blob/5e24958c0bc517f8deec205c98c379da39cbd505/config/plugin_selector.go#L17-L18

neelayu avatar Dec 09 '25 12:12 neelayu

Also underscores do not work:

invalid label in plugin inputs.ping: invalid value "foo_bar"

Hipska avatar Dec 09 '25 12:12 Hipska

Why are special chars not allowed as the first or last character? Otherwise the Regex could be more simple:

reKey   = regexp.MustCompile(`^[\w\.\-]+$`)
reValue = regexp.MustCompile(`^\S+$`)

Hipska avatar Dec 09 '25 12:12 Hipska

Actually we should keep it loosely consistent with https://datatracker.ietf.org/doc/html/rfc1123

contain at most 63 characters contain only lowercase alphanumeric characters or '-' start with an alphabetic character end with an alphanumeric character

But since we need characters like * and ? for values we have deviated slightly from that. These characters are wildcards for values.

I think we will have to revisit this again. Ideally we should have-

  1. start and end with alphanumeric
  2. can contain - or _ or . Values can contain the wildcard chars and should be non empty.

neelayu avatar Dec 09 '25 12:12 neelayu

I don't see what these label keys or values have anything to do with internet hosts. I feel like its limiting too much without any technical reason..

Hipska avatar Dec 09 '25 14:12 Hipska

I don't feel like #18108 completely resolved this issue, see my comments.

Current nightly builds accepts this label:

[[inputs.ping]]
  [inputs.ping.labels]
    key = "FOObar?*"

Hipska avatar Dec 15 '25 08:12 Hipska

@Hipska that is correct. As you rightly pointed out, I missed calling the function. 🥹

neelayu avatar Dec 15 '25 09:12 neelayu