mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24:05 -08:00
validates that the recording name to include only allowed characters. (#3305)
This commit is contained in:
parent
9ef8518b37
commit
3697075b8f
|
@ -127,6 +127,9 @@ func (r *Rule) Validate() (errs []error) {
|
|||
if r.For != 0 {
|
||||
errs = append(errs, errors.Errorf("invalid field 'for' in recording rule"))
|
||||
}
|
||||
if !model.IsValidMetricName(model.LabelValue(r.Record)) {
|
||||
errs = append(errs, errors.Errorf("invalid recording rule name: %s", r.Record))
|
||||
}
|
||||
}
|
||||
|
||||
for k, v := range r.Labels {
|
||||
|
|
|
@ -61,6 +61,10 @@ func TestParseFileFailure(t *testing.T) {
|
|||
filename: "bad_annotation.bad.yaml",
|
||||
errMsg: "invalid annotation name",
|
||||
},
|
||||
{
|
||||
filename: "invalid_record_name.bad.yaml",
|
||||
errMsg: "invalid recording rule name",
|
||||
},
|
||||
}
|
||||
|
||||
for _, c := range table {
|
||||
|
|
5
pkg/rulefmt/testdata/invalid_record_name.bad.yaml
vendored
Normal file
5
pkg/rulefmt/testdata/invalid_record_name.bad.yaml
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
groups:
|
||||
- name: yolo
|
||||
rules:
|
||||
- record: strawberry{flavor="sweet"}
|
||||
expr: 1
|
Loading…
Reference in a new issue