mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-25 13:44:05 -08:00
Use strict unmarshalling of rules (#7767)
* Fix unmarshalling of rules Fix #7042 Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
This commit is contained in:
parent
2899773b01
commit
fd06416057
|
@ -14,7 +14,9 @@
|
||||||
package rulefmt
|
package rulefmt
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -267,8 +269,11 @@ func Parse(content []byte) (*RuleGroups, []error) {
|
||||||
errs []error
|
errs []error
|
||||||
)
|
)
|
||||||
|
|
||||||
err := yaml.Unmarshal(content, &groups)
|
decoder := yaml.NewDecoder(bytes.NewReader(content))
|
||||||
if err != nil {
|
decoder.KnownFields(true)
|
||||||
|
err := decoder.Decode(&groups)
|
||||||
|
// Ignore io.EOF which happens with empty input.
|
||||||
|
if err != nil && err != io.EOF {
|
||||||
errs = append(errs, err)
|
errs = append(errs, err)
|
||||||
}
|
}
|
||||||
err = yaml.Unmarshal(content, &node)
|
err = yaml.Unmarshal(content, &node)
|
||||||
|
|
|
@ -67,6 +67,10 @@ func TestParseFileFailure(t *testing.T) {
|
||||||
filename: "invalid_record_name.bad.yaml",
|
filename: "invalid_record_name.bad.yaml",
|
||||||
errMsg: "invalid recording rule name",
|
errMsg: "invalid recording rule name",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
filename: "bad_field.bad.yaml",
|
||||||
|
errMsg: "field annotation not found",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range table {
|
for _, c := range table {
|
||||||
|
|
10
pkg/rulefmt/testdata/bad_field.bad.yaml
vendored
Normal file
10
pkg/rulefmt/testdata/bad_field.bad.yaml
vendored
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
groups:
|
||||||
|
- name: yolo
|
||||||
|
rules:
|
||||||
|
- alert: hola
|
||||||
|
expr: 1
|
||||||
|
labels:
|
||||||
|
instance: localhost
|
||||||
|
annotation:
|
||||||
|
summary: annonations is written without s above
|
||||||
|
|
Loading…
Reference in a new issue