Skip to content

Commit

Permalink
fix: remove shared state noParserHints to avoid data race (grafana#11685
Browse files Browse the repository at this point in the history
)

**What this PR does / why we need it**:

A data race introduced in grafana#11587 was
caught in the [backport to
k184](grafana#11668). This removes the
shared state of a single global `noParserHints` in favor of creating an
empty `Hint` object for each label builder, since the `Hints` is keeping
state of `extracted` and `requiredLabels`.
  • Loading branch information
trevorwhitney authored and rhnasc committed Apr 12, 2024
1 parent 69ee5ed commit 3fc7785
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 57 deletions.
4 changes: 2 additions & 2 deletions pkg/logql/log/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ type LabelsBuilder struct {
// NewBaseLabelsBuilderWithGrouping creates a new base labels builder with grouping to compute results.
func NewBaseLabelsBuilderWithGrouping(groups []string, parserKeyHints ParserHint, without, noLabels bool) *BaseLabelsBuilder {
if parserKeyHints == nil {
parserKeyHints = noParserHints
parserKeyHints = NoParserHints()
}

const labelsCapacity = 16
Expand All @@ -179,7 +179,7 @@ func NewBaseLabelsBuilderWithGrouping(groups []string, parserKeyHints ParserHint

// NewBaseLabelsBuilder creates a new base labels builder.
func NewBaseLabelsBuilder() *BaseLabelsBuilder {
return NewBaseLabelsBuilderWithGrouping(nil, noParserHints, false, false)
return NewBaseLabelsBuilderWithGrouping(nil, NoParserHints(), false, false)
}

// ForLabels creates a labels builder for a given labels set as base.
Expand Down
4 changes: 3 additions & 1 deletion pkg/logql/log/parser_hints.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
"github.com/grafana/loki/pkg/logqlmodel"
)

var noParserHints = &Hints{}
func NoParserHints() ParserHint {
return &Hints{}
}

// ParserHint are hints given to LogQL parsers.
// This is specially useful for parser that extract implicitly all possible label keys.
Expand Down

0 comments on commit 3fc7785

Please sign in to comment.