mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Add fmt rule check: labels with the name __name__ are invalid (#7787)
Signed-off-by: Max Neverov <neverov.max@gmail.com>
This commit is contained in:
parent
21a753c4e2
commit
7c8bbd6bcb
|
@ -186,7 +186,7 @@ func (r *RuleNode) Validate() (nodes []WrappedError) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for k, v := range r.Labels {
|
for k, v := range r.Labels {
|
||||||
if !model.LabelName(k).IsValid() {
|
if !model.LabelName(k).IsValid() || k == model.MetricNameLabel {
|
||||||
nodes = append(nodes, WrappedError{
|
nodes = append(nodes, WrappedError{
|
||||||
err: errors.Errorf("invalid label name: %s", k),
|
err: errors.Errorf("invalid label name: %s", k),
|
||||||
})
|
})
|
||||||
|
|
|
@ -71,6 +71,10 @@ func TestParseFileFailure(t *testing.T) {
|
||||||
filename: "bad_field.bad.yaml",
|
filename: "bad_field.bad.yaml",
|
||||||
errMsg: "field annotation not found",
|
errMsg: "field annotation not found",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
filename: "invalid_label_name.bad.yaml",
|
||||||
|
errMsg: "invalid label name",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range table {
|
for _, c := range table {
|
||||||
|
|
7
pkg/rulefmt/testdata/invalid_label_name.bad.yaml
vendored
Normal file
7
pkg/rulefmt/testdata/invalid_label_name.bad.yaml
vendored
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
groups:
|
||||||
|
- name: yolo
|
||||||
|
rules:
|
||||||
|
- record: hola
|
||||||
|
expr: 1
|
||||||
|
labels:
|
||||||
|
__name__: anything
|
Loading…
Reference in a new issue