Skip to content

Commit

Permalink
Do not parse string of empty matchers (#5980)
Browse files Browse the repository at this point in the history
This fixes a bug in the index gateway when querying values for a label.
Since the gRPC handler for LabelValuesForMetricName in the index gateway
allows empty matchers in the LabelValuesForMetricNameRequest, we need to
check if the matchers string is an empty matcher (`{}`) before we parse
the string.

This bug was introduced with the index gateway api refactoring in #5892

Fixes: #5965

Signed-off-by: Christian Haudum <christian.haudum@gmail.com>
  • Loading branch information
chaudum committed Apr 21, 2022
1 parent 52cd46c commit 7e191dd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
6 changes: 5 additions & 1 deletion pkg/logql/syntax/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ import (
"github.com/grafana/loki/pkg/util"
)

const errAtleastOneEqualityMatcherRequired = "queries require at least one regexp or equality matcher that does not have an empty-compatible value. For instance, app=~\".*\" does not meet this requirement, but app=~\".+\" will"
const (
EmptyMatchers = "{}"

errAtleastOneEqualityMatcherRequired = "queries require at least one regexp or equality matcher that does not have an empty-compatible value. For instance, app=~\".*\" does not meet this requirement, but app=~\".+\" will"
)

var parserPool = sync.Pool{
New: func() interface{} {
Expand Down
11 changes: 8 additions & 3 deletions pkg/storage/stores/shipper/indexgateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,14 @@ func (g *Gateway) LabelValuesForMetricName(ctx context.Context, req *indexgatewa
if err != nil {
return nil, err
}
matchers, err := syntax.ParseMatchers(req.Matchers)
if err != nil {
return nil, err
var matchers []*labels.Matcher
// An empty matchers string cannot be parsed,
// therefore we check the string representation of the the matchers.
if req.Matchers != syntax.EmptyMatchers {
matchers, err = syntax.ParseMatchers(req.Matchers)
if err != nil {
return nil, err
}
}
names, err := g.indexQuerier.LabelValuesForMetricName(ctx, instanceID, req.From, req.Through, req.MetricName, req.LabelName, matchers...)
if err != nil {
Expand Down

0 comments on commit 7e191dd

Please sign in to comment.