diff --git a/pkg/rulefmt/rulefmt.go b/pkg/rulefmt/rulefmt.go index 7a2179e7d..8267bc90e 100644 --- a/pkg/rulefmt/rulefmt.go +++ b/pkg/rulefmt/rulefmt.go @@ -186,7 +186,7 @@ func (r *RuleNode) Validate() (nodes []WrappedError) { } for k, v := range r.Labels { - if !model.LabelName(k).IsValid() { + if !model.LabelName(k).IsValid() || k == model.MetricNameLabel { nodes = append(nodes, WrappedError{ err: errors.Errorf("invalid label name: %s", k), }) diff --git a/pkg/rulefmt/rulefmt_test.go b/pkg/rulefmt/rulefmt_test.go index 4101b61b9..92967cf7d 100644 --- a/pkg/rulefmt/rulefmt_test.go +++ b/pkg/rulefmt/rulefmt_test.go @@ -71,6 +71,10 @@ func TestParseFileFailure(t *testing.T) { filename: "bad_field.bad.yaml", errMsg: "field annotation not found", }, + { + filename: "invalid_label_name.bad.yaml", + errMsg: "invalid label name", + }, } for _, c := range table { diff --git a/pkg/rulefmt/testdata/invalid_label_name.bad.yaml b/pkg/rulefmt/testdata/invalid_label_name.bad.yaml new file mode 100644 index 000000000..72f69faa9 --- /dev/null +++ b/pkg/rulefmt/testdata/invalid_label_name.bad.yaml @@ -0,0 +1,7 @@ +groups: +- name: yolo + rules: + - record: hola + expr: 1 + labels: + __name__: anything