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:
Max Neverov 2020-08-12 23:37:31 +02:00 committed by GitHub
parent 21a753c4e2
commit 7c8bbd6bcb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 1 deletions

View file

@ -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),
})

View file

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

View file

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