diff --git a/pkg/ingester/instance.go b/pkg/ingester/instance.go index 674cb8a76ea2b..6f2149b31af6b 100644 --- a/pkg/ingester/instance.go +++ b/pkg/ingester/instance.go @@ -562,8 +562,6 @@ func (i *instance) Label(ctx context.Context, req *logproto.LabelRequest, matche } labels := util.NewUniqueStrings(0) - // (shantanu) can create a map here to store label names::values and count the unique values - // just return a string to int map err := i.forMatchingStreams(ctx, *req.Start, matchers, nil, func(s *stream) error { for _, label := range s.labels { if req.Values && label.Name == req.Name { @@ -589,9 +587,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] diff --git a/pkg/querier/queryrange/codec.go b/pkg/querier/queryrange/codec.go index 7bc1913745ab2..d65c020dcd060 100644 --- a/pkg/querier/queryrange/codec.go +++ b/pkg/querier/queryrange/codec.go @@ -266,18 +266,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 }