Skip to content

Commit

Permalink
Also improve IndexStats API and fix wrong for loop
Browse files Browse the repository at this point in the history
  • Loading branch information
cyriltovena committed Aug 26, 2024
1 parent 65a5301 commit 9eb557c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2234,7 +2234,7 @@ func (dec *Decoder) prepSeries(b []byte, lbls *labels.Labels, chks *[]ChunkMeta)
// prepSeriesBy returns series labels and chunks for a series and only returning selected `by` label names.
// If `by` is empty, it returns all labels for the series.
func (dec *Decoder) prepSeriesBy(b []byte, lbls *labels.Labels, chks *[]ChunkMeta, by map[string]struct{}) (*encoding.Decbuf, uint64, error) {
if len(by) == 0 {
if by == nil {
return dec.prepSeries(b, lbls, chks)
}
*lbls = (*lbls)[:0]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,15 @@ func (i *TSDBIndex) Stats(ctx context.Context, _ string, from, through model.Tim
// TODO(owen-d): use pool
var ls labels.Labels
var filterer chunk.Filterer
by := make(map[string]struct{})
if i.chunkFilter != nil {
filterer = i.chunkFilter.ForRequest(ctx)
for _, k := range i.chunkFilter.ForRequest(ctx).RequiredLabelNames() {
by[k] = struct{}{}
}
}

for p.Next() {
fp, stats, err := i.reader.ChunkStats(p.At(), int64(from), int64(through), &ls, nil)
fp, stats, err := i.reader.ChunkStats(p.At(), int64(from), int64(through), &ls, by)
if err != nil {
return err
}
Expand Down Expand Up @@ -365,11 +368,10 @@ func (i *TSDBIndex) Volume(
for k := range labelsToMatch {
by[k] = struct{}{}
}
if len(labelsToMatch) > 0 {
for k := range labelsToMatch {
by[k] = struct{}{}
}
for _, k := range targetLabels {
by[k] = struct{}{}
}

// If we are aggregating by series, we need to include all labels in the series required for filtering chunks.
if i.chunkFilter != nil {
for _, k := range i.chunkFilter.ForRequest(ctx).RequiredLabelNames() {
Expand Down

0 comments on commit 9eb557c

Please sign in to comment.