File tree Expand file tree Collapse file tree 3 files changed +18
-2
lines changed
Expand file tree Collapse file tree 3 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -83,7 +83,7 @@ func (cfg Config) String() string {
8383func (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+ }
Original file line number Diff line number Diff line change @@ -105,7 +105,7 @@ func (m Match) validate(allowEmpty bool) error {
105105}
106106
107107func (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 {
Original file line number Diff line number Diff 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 {
You can’t perform that action at this time.
0 commit comments