Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Bugfixes for detected labels API #12466

Merged
merged 2 commits into from
Apr 4, 2024
Merged

Conversation

shantanualsi
Copy link
Contributor

What this PR does / why we need it:
Fixes bug in the detected labels API.

  • Query does not work as matches are not recognized
  • Blank value increases the cardinality by 1
  • Dedupe does not work properly
  • panics if ingester labels are nil

@shantanualsi shantanualsi requested a review from a team as a code owner April 4, 2024 09:30
@shantanualsi shantanualsi changed the title Bugfixes for detected labels API fix: Bugfixes for detected labels API Apr 4, 2024
@@ -1403,7 +1403,7 @@ func (i *Ingester) GetDetectedLabels(ctx context.Context, req *logproto.Detected
}
result := make(map[string]*logproto.UniqueLabelValues)
for label, values := range labelMap {
uniqueValues := make([]string, len(values))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use of make introduced blank values in the slice

@@ -1389,7 +1389,7 @@ func (i *Ingester) GetDetectedLabels(ctx context.Context, req *logproto.Detected
}
var matchers []*labels.Matcher
if req.Query != "" {
matchers, err := syntax.ParseMatchers(req.Query, true)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:= again after declaring zero value above 🧠

mergedResult := make(map[string]*logproto.UniqueLabelValues)
for label, val := range labelMap {
uniqueValues := slices.CompactFunc(val, strings.EqualFold)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compact only works for dedupe if values are sorted

@@ -915,7 +915,7 @@ func (q *SingleTenantQuerier) DetectedLabels(ctx context.Context, req *logproto.

g, ctx := errgroup.WithContext(ctx)
ingesterQueryInterval, _ := q.buildQueryIntervals(*req.Start, *req.End)
if !q.cfg.QueryStoreOnly {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥇

@shantanualsi shantanualsi requested a review from cyriltovena April 4, 2024 09:41
Copy link
Contributor

@cyriltovena cyriltovena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Many bug fixes, few tests proving it's fixes. Please add more in follow up PR.

@cyriltovena cyriltovena merged commit 2c878c8 into main Apr 4, 2024
10 checks passed
@cyriltovena cyriltovena deleted the detected-labels-bugfixes branch April 4, 2024 09:52
rhnasc pushed a commit to inloco/loki that referenced this pull request Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants