Add missing lock to ExtractSelectors

Now that we are parallel walking we need to ensure that the visitor methods are concurrent-safe. Surprisingly this doesn't show up in `-race

Fixes https://github.com/jacksontj/promxy/issues/579
This commit is contained in:
Thomas Jackson 2023-03-30 08:10:25 -07:00 committed by Rishabh Kumar
parent 2b58f7d126
commit a95115a6da

View file

@ -382,11 +382,16 @@ func Walk(ctx context.Context, v Visitor, s *EvalStmt, node Node, path []Node, n
}
func ExtractSelectors(expr Expr) [][]*labels.Matcher {
var selectors [][]*labels.Matcher
var (
selectors [][]*labels.Matcher
l sync.Mutex
)
Inspect(context.TODO(), &EvalStmt{Expr: expr}, func(node Node, _ []Node) error {
vs, ok := node.(*VectorSelector)
if ok {
l.Lock()
selectors = append(selectors, vs.LabelMatchers)
l.Unlock()
}
return nil
}, nil)