mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-27 13:42:31 -08:00
Correctly handle {__name__="a"} (#5552)
This can cause problems in alerts. Signed-off-by: Brian Brazil <brian.brazil@robustperception.io>
This commit is contained in:
parent
3a7a743bc4
commit
36dbf042e3
|
@ -179,8 +179,8 @@ func (node *UnaryExpr) String() string {
|
||||||
func (node *VectorSelector) String() string {
|
func (node *VectorSelector) String() string {
|
||||||
labelStrings := make([]string, 0, len(node.LabelMatchers)-1)
|
labelStrings := make([]string, 0, len(node.LabelMatchers)-1)
|
||||||
for _, matcher := range node.LabelMatchers {
|
for _, matcher := range node.LabelMatchers {
|
||||||
// Only include the __name__ label if its no equality matching.
|
// Only include the __name__ label if its equality matching and matches the name.
|
||||||
if matcher.Name == labels.MetricName && matcher.Type == labels.MatchEqual {
|
if matcher.Name == labels.MetricName && matcher.Type == labels.MatchEqual && matcher.Value == node.Name {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
labelStrings = append(labelStrings, matcher.String())
|
labelStrings = append(labelStrings, matcher.String())
|
||||||
|
|
|
@ -81,6 +81,9 @@ func TestExprString(t *testing.T) {
|
||||||
{
|
{
|
||||||
in: `a[5m] offset 1m`,
|
in: `a[5m] offset 1m`,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
in: `{__name__="a"}`,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range inputs {
|
for _, test := range inputs {
|
||||||
|
|
Loading…
Reference in a new issue