Skip to content

Commit 6630e3d

Browse files
authored
Merge pull request #1086 from cloudflare/cmd
Fix benchmarks
2 parents 7d0d534 + bc99058 commit 6630e3d

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

internal/config/config.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func (cfg Config) String() string {
8383
func (cfg *Config) GetChecksForEntry(ctx context.Context, gen *PrometheusGenerator, entry discovery.Entry) []checks.RuleChecker {
8484
enabled := []checks.RuleChecker{}
8585

86-
defaultMatch := []Match{{State: defaultMatchStates(ctx.Value(CommandKey).(ContextCommandVal))}}
86+
defaultMatch := []Match{{State: defaultMatchStates(commandFromContext(ctx))}}
8787
proms := gen.ServersForPath(entry.Path.Name)
8888

8989
if entry.PathError != nil || entry.Rule.Error.Err != nil {
@@ -229,3 +229,10 @@ func parseDuration(d string) (time.Duration, error) {
229229
}
230230
return time.Duration(mdur), nil
231231
}
232+
233+
func commandFromContext(ctx context.Context) (cmd ContextCommandVal) {
234+
if val := ctx.Value(CommandKey); val != nil {
235+
cmd = val.(ContextCommandVal)
236+
}
237+
return cmd
238+
}

internal/config/match.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func (m Match) validate(allowEmpty bool) error {
105105
}
106106

107107
func (m Match) IsMatch(ctx context.Context, path string, e discovery.Entry) bool {
108-
cmd := ctx.Value(CommandKey).(ContextCommandVal)
108+
cmd := commandFromContext(ctx)
109109

110110
if m.Command != nil {
111111
if cmd != *m.Command {

internal/config/rule_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,15 @@ func TestMatch(t *testing.T) {
665665
},
666666
isMatch: true,
667667
},
668+
{
669+
path: "foo.yaml",
670+
entry: discovery.Entry{
671+
Rule: parser.Rule{},
672+
State: discovery.Noop,
673+
},
674+
match: config.Match{},
675+
isMatch: true,
676+
},
668677
}
669678

670679
for i, tc := range testCases {

0 commit comments

Comments
 (0)