Skip to content

Support any symbol in label names #3319

@yuri-tceretian

Description

@yuri-tceretian

Currently, Alertmanager supports only valid Prometheus label names, i.e. the ones that match the following regular expression ^[a-zA-Z_][a-zA-Z0-9_]*$.
This is a quite restrictive pattern and limits usage of the Alertmanager outside the Prometheus eco-system.

For example. Grafana uses Alertmanager for notifications, and because Grafana supports many different data sources (like Elasticsearch, Graphite, SQL, etc) where the format of label names usually does fit into a narrow range of characters Alertmanager accepts, it works around the limitation by overriding API level and config parsing logic.

I propose a feature request to expand the range of the allowed symbols in label names to accept any UTF-8 characters.

Looking at the code I did not find any technical limitations that would prevent Alertmanager from working with label names that contain any UTF-8 characters, and change is fairly simple.
The only problem spot is the parsing of Matchers

// Examples for valid input strings:
//
// {foo = "bar", dings != "bums", }
// foo=bar,dings!=bums
// foo=bar, dings!=bums
// {quote="She said: \"Hi, ladies! That's gender-neutral…\""}
// statuscode=~"5.."
//
// See ParseMatcher for details on how an individual Matcher is parsed.
func ParseMatchers(s string) ([]*Matcher, error) {
I think that we can support quoted label names. For example, the examples above will look like

"foo"=bar,dings!=bums
{"quote"="She said: \"Hi, ladies! That's gender-neutral…\""}

The idea is to distinguish between matcher type symbols (=~|=|!=|!~) and those sequences in label names. For example
"~=labeltest=~"=~"good label"

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions