Skip to content

Commit

Permalink
strict rule unmarshaling (#2580)
Browse files Browse the repository at this point in the history
  • Loading branch information
owen-d authored Aug 31, 2020
1 parent e1ee189 commit 4032c92
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
5 changes: 2 additions & 3 deletions pkg/ruler/manager/compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,9 @@ func (groupLoader) parseRules(content []byte) (*rulefmt.RuleGroups, []error) {
)

decoder := yaml.NewDecoder(bytes.NewReader(content))
err := decoder.Decode(&groups)
decoder.KnownFields(true)

// err := yaml.Unmarshal(content, &groups)
if err != nil {
if err := decoder.Decode(&groups); err != nil {
errs = append(errs, err)
}

Expand Down
18 changes: 18 additions & 0 deletions pkg/ruler/manager/compat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,24 @@ groups:
desc: "fail invalid annotation",
match: "invalid annotation name:",
data: `
groups:
- name: grp1
interval: 0s
rules:
- alert: HighThroughputLogStreams
expr: sum by (cluster, job, pod) (rate({namespace=~"%s"} |~ "http(s?)://(\\w+):(\\w+)@" [5m]) > 0)
for: 2m
labels:
severity: page
annotations:
's.ummary': High request latency
`,
},
{
desc: "unknown fields",
match: "field unknown not found",
data: `
unknown: true
groups:
- name: grp1
interval: 0s
Expand Down

0 comments on commit 4032c92

Please sign in to comment.