Skip to content

Commit

Permalink
Fetch label values from index
Browse files Browse the repository at this point in the history
  • Loading branch information
shantanualsi committed Apr 4, 2024
1 parent 9398dfa commit 97cf8a3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
23 changes: 21 additions & 2 deletions pkg/ingester/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,9 +589,28 @@ type UniqueValues map[string]struct{}

// LabelsWithValues returns the label names with all the unique values depending on the request
func (i *instance) LabelsWithValues(ctx context.Context, startTime time.Time, matchers ...*labels.Matcher) (map[string]UniqueValues, error) {
// TODO (shantanu): Figure out how to get the label names from index directly when no matchers are given.

labelMap := make(map[string]UniqueValues)
if len(matchers) == 0 {
labelsFromIndex, err := i.index.LabelNames(startTime, nil)
if err != nil {
return nil, err
}

for _, label := range labelsFromIndex {
values, err := i.index.LabelValues(startTime, label, nil)
if err != nil {
return nil, err
}
existingValues, exists := labelMap[label]
if !exists {
existingValues = make(map[string]struct{})
}
for _, v := range values {
existingValues[v] = struct{}{}
}
}
}

err := i.forMatchingStreams(ctx, startTime, matchers, nil, func(s *stream) error {
for _, label := range s.labels {
v, exists := labelMap[label.Name]
Expand Down
12 changes: 0 additions & 12 deletions pkg/querier/queryrange/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,18 +268,6 @@ type DetectedLabelsRequest struct {
logproto.DetectedLabelsRequest
}

// NewDetectedLabelsRequest creates a new request for detected labels
func NewDetectedLabelsRequest(start, end time.Time, query, path string) *DetectedLabelsRequest {
return &DetectedLabelsRequest{
DetectedLabelsRequest: logproto.DetectedLabelsRequest{
Start: &start,
End: &end,
Query: query,
},
path: path,
}
}

func (r *DetectedLabelsRequest) AsProto() *logproto.DetectedLabelsRequest {
return &r.DetectedLabelsRequest
}
Expand Down

0 comments on commit 97cf8a3

Please sign in to comment.