Add fmt rule check: labels with the name __name__ are invalid (#7787)

Signed-off-by: Max Neverov <neverov.max@gmail.com>
pull/7790/head
Max Neverov 4 years ago committed by GitHub
parent 21a753c4e2
commit 7c8bbd6bcb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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 {

@ -0,0 +1,7 @@
groups:
- name: yolo
rules:
- record: hola
expr: 1
labels:
__name__: anything
Loading…
Cancel
Save