-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
matchers, err = syntax.ParseMatchers(req.Query, true) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
@@ -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)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use of make introduced blank values in the slice |
||
var uniqueValues []string | ||
for v := range values { | ||
uniqueValues = append(uniqueValues, v) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -370,17 +370,24 @@ func (q *IngesterQuerier) DetectedLabel(ctx context.Context, req *logproto.Detec | |
labelMap := make(map[string][]string) | ||
for _, resp := range ingesterResponses { | ||
thisIngester := resp.response.(*logproto.LabelToValuesResponse) | ||
for label, values := range thisIngester.Labels { | ||
uniqueValues := make([]string, len(values.Values)) | ||
allValues := thisIngester.Labels[label] | ||
uniqueValues = append(uniqueValues, allValues.Values...) | ||
|
||
labelMap[label] = uniqueValues | ||
for label, thisIngesterValues := range thisIngester.Labels { | ||
var combinedValues []string | ||
allIngesterValues, isLabelPresent := labelMap[label] | ||
if isLabelPresent { | ||
combinedValues = append(allIngesterValues, thisIngesterValues.Values...) | ||
} else { | ||
combinedValues = thisIngesterValues.Values | ||
} | ||
labelMap[label] = combinedValues | ||
} | ||
} | ||
|
||
// Dedupe all ingester values | ||
mergedResult := make(map[string]*logproto.UniqueLabelValues) | ||
for label, val := range labelMap { | ||
uniqueValues := slices.CompactFunc(val, strings.EqualFold) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Compact only works for dedupe if values are sorted |
||
slices.Sort(val) | ||
uniqueValues := slices.Compact(val) | ||
|
||
mergedResult[label] = &logproto.UniqueLabelValues{ | ||
Values: uniqueValues, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🥇 |
||
if !q.cfg.QueryStoreOnly && ingesterQueryInterval != nil { | ||
g.Go(func() error { | ||
var err error | ||
splitReq := *req | ||
|
@@ -932,6 +932,12 @@ func (q *SingleTenantQuerier) DetectedLabels(ctx context.Context, req *logproto. | |
return nil, err | ||
} | ||
|
||
if ingesterLabels == nil { | ||
return &logproto.DetectedLabelsResponse{ | ||
DetectedLabels: []*logproto.DetectedLabel{}, | ||
}, nil | ||
} | ||
|
||
for label, values := range ingesterLabels.Labels { | ||
if q.isLabelRelevant(label, values) { | ||
detectedLabels = append(detectedLabels, &logproto.DetectedLabel{Label: label, Cardinality: uint64(len(values.Values))}) | ||
|
There was a problem hiding this comment.
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 🧠