Skip to content

Commit

Permalink
Merge pull request #1086 from cloudflare/cmd
Browse files Browse the repository at this point in the history
Fix benchmarks
  • Loading branch information
prymitive committed Aug 27, 2024
2 parents 7d0d534 + bc99058 commit 6630e3d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
9 changes: 8 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (cfg Config) String() string {
func (cfg *Config) GetChecksForEntry(ctx context.Context, gen *PrometheusGenerator, entry discovery.Entry) []checks.RuleChecker {
enabled := []checks.RuleChecker{}

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

if entry.PathError != nil || entry.Rule.Error.Err != nil {
Expand Down Expand Up @@ -229,3 +229,10 @@ func parseDuration(d string) (time.Duration, error) {
}
return time.Duration(mdur), nil
}

func commandFromContext(ctx context.Context) (cmd ContextCommandVal) {
if val := ctx.Value(CommandKey); val != nil {
cmd = val.(ContextCommandVal)
}
return cmd
}
2 changes: 1 addition & 1 deletion internal/config/match.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (m Match) validate(allowEmpty bool) error {
}

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

if m.Command != nil {
if cmd != *m.Command {
Expand Down
9 changes: 9 additions & 0 deletions internal/config/rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,15 @@ func TestMatch(t *testing.T) {
},
isMatch: true,
},
{
path: "foo.yaml",
entry: discovery.Entry{
Rule: parser.Rule{},
State: discovery.Noop,
},
match: config.Match{},
isMatch: true,
},
}

for i, tc := range testCases {
Expand Down

0 comments on commit 6630e3d

Please # to comment.