mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24: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
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -267,8 +269,11 @@ func Parse(content []byte) (*RuleGroups, []error) {
|
|||
errs []error
|
||||
)
|
||||
|
||||
err := yaml.Unmarshal(content, &groups)
|
||||
if err != nil {
|
||||
decoder := yaml.NewDecoder(bytes.NewReader(content))
|
||||
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)
|
||||
}
|
||||
err = yaml.Unmarshal(content, &node)
|
||||
|
|
|
@ -67,6 +67,10 @@ func TestParseFileFailure(t *testing.T) {
|
|||
filename: "invalid_record_name.bad.yaml",
|
||||
errMsg: "invalid recording rule name",
|
||||
},
|
||||
{
|
||||
filename: "bad_field.bad.yaml",
|
||||
errMsg: "field annotation not found",
|
||||
},
|
||||
}
|
||||
|
||||
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