Skip to content

Commit

Permalink
feat: switched to strict unmarshal in rule check
Browse files Browse the repository at this point in the history
  • Loading branch information
FUSAKLA committed May 11, 2019
1 parent 7631da5 commit 864a74c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
17 changes: 13 additions & 4 deletions cmd/thanos/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
thanosrule "github.com/improbable-eng/thanos/pkg/rule"
"github.com/oklog/run"
"github.com/opentracing/opentracing-go"
"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -56,6 +55,16 @@ func checkRulesFiles(logger log.Logger, files *[]string) error {
return nil
}

type ThanosRuleGroup struct{
PartialResponseStrategy string `yaml:"partial_response_strategy"`
rulefmt.RuleGroup `yaml:",inline"`
}

type ThanosRuleGroups struct {
Groups []ThanosRuleGroup `yaml:"groups"`
}


func checkRules(logger log.Logger, filename string) (int, tsdb.MultiError) {
level.Info(logger).Log("msg", "checking", "filename", filename)
checkErrors := tsdb.MultiError{}
Expand All @@ -66,8 +75,8 @@ func checkRules(logger log.Logger, filename string) (int, tsdb.MultiError) {
return 0, checkErrors
}

var rgs thanosrule.RuleGroups
if err := yaml.Unmarshal(b, &rgs); err != nil {
var rgs ThanosRuleGroups
if err := yaml.UnmarshalStrict(b, &rgs); err != nil {
checkErrors.Add(err)
return 0, checkErrors
}
Expand All @@ -89,7 +98,7 @@ func checkRules(logger log.Logger, filename string) (int, tsdb.MultiError) {
return numRules, checkErrors
}

func thanosRuleGroupsToPromRuleGroups(ruleGroups thanosrule.RuleGroups) rulefmt.RuleGroups {
func thanosRuleGroupsToPromRuleGroups(ruleGroups ThanosRuleGroups) rulefmt.RuleGroups {
promRuleGroups := rulefmt.RuleGroups{Groups: []rulefmt.RuleGroup{}}
for _, g := range ruleGroups.Groups {
group := rulefmt.RuleGroup{
Expand Down
1 change: 1 addition & 0 deletions cmd/thanos/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func Test_checkRules(t *testing.T) {
[]string{"./testdata/rules-files/non-existing-file.yaml"},
[]string{"./testdata/rules-files/invalid-yaml-format.yaml"},
[]string{"./testdata/rules-files/invalid-rules-data.yaml"},
[]string{"./testdata/rules-files/invalid-unknown-field.yaml"},
}

logger := log.NewNopLogger()
Expand Down
2 changes: 0 additions & 2 deletions cmd/thanos/testdata/rules-files/valid.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ groups:
interval: 2m
rules:
- alert: TestAlert
partial_response_strategy: "warn"
expr: 1
labels:
key: value
Expand All @@ -17,4 +16,3 @@ groups:
rules:
- record: test_metric
expr: 1
partial_response_strategy: "warn"

0 comments on commit 864a74c

Please sign in to comment.