Skip to content

Commit badc146

Browse files
authored
Always query series and labels from TSDB head (#2974)
Signed-off-by: Marco Pracucci <marco@pracucci.com>
1 parent 7014ff1 commit badc146

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
* [BUGFIX] Fixed ruler and store-gateway instance registration in the ring (when sharding is enabled) when a new instance replaces abruptly terminated one, and the only difference between the two instances is the address. #2954
110110
* [BUGFIX] Fixed `Missing chunks and index config causing silent failure` Absence of chunks and index from schema config is not validated. #2732
111111
* [BUGFIX] Fix panic caused by KVs from boltdb being used beyond their life. #2971
112+
* [BUGFIX] Experimental TSDB: `/api/v1/series`, `/api/v1/labels` and `/api/v1/label/{name}/values` only query the TSDB head regardless of the configured `-experimental.blocks-storage.tsdb.retention-period`. #2974
112113

113114
## 1.2.0 / 2020-07-01
114115

pkg/ingester/ingester_v2.go

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"fmt"
66
"io"
7-
"math"
87
"net/http"
98
"os"
109
"path/filepath"
@@ -608,9 +607,10 @@ func (i *Ingester) v2LabelValues(ctx context.Context, req *client.LabelValuesReq
608607
return &client.LabelValuesResponse{}, nil
609608
}
610609

611-
// Since we ingester runs with a very limited TSDB retention, we can (and should) query
612-
// label values without any time range bound.
613-
q, err := db.Querier(ctx, 0, math.MaxInt64)
610+
// Since ingester may run with a variable TSDB retention which could be few days long,
611+
// we only query the TSDB head time range in order to avoid heavy queries (which could
612+
// lead to ingesters out-of-memory) in case the TSDB retention is several days.
613+
q, err := db.Querier(ctx, db.Head().MinTime(), db.Head().MaxTime())
614614
if err != nil {
615615
return nil, err
616616
}
@@ -637,9 +637,10 @@ func (i *Ingester) v2LabelNames(ctx context.Context, req *client.LabelNamesReque
637637
return &client.LabelNamesResponse{}, nil
638638
}
639639

640-
// Since we ingester runs with a very limited TSDB retention, we can (and should) query
641-
// label names without any time range bound.
642-
q, err := db.Querier(ctx, 0, math.MaxInt64)
640+
// Since ingester may run with a variable TSDB retention which could be few days long,
641+
// we only query the TSDB head time range in order to avoid heavy queries (which could
642+
// lead to ingesters out-of-memory) in case the TSDB retention is several days.
643+
q, err := db.Querier(ctx, db.Head().MinTime(), db.Head().MaxTime())
643644
if err != nil {
644645
return nil, err
645646
}
@@ -672,11 +673,10 @@ func (i *Ingester) v2MetricsForLabelMatchers(ctx context.Context, req *client.Me
672673
return nil, err
673674
}
674675

675-
// Since ingester runs with a very limited TSDB retention, we can (and should) query
676-
// metrics without any time range bound, otherwise when we receive a request with a time
677-
// range older then the ingester's data we return an empty response instead of returning
678-
// the currently known series.
679-
q, err := db.Querier(ctx, 0, math.MaxInt64)
676+
// Since ingester may run with a variable TSDB retention which could be few days long,
677+
// we only query the TSDB head time range in order to avoid heavy queries (which could
678+
// lead to ingesters out-of-memory) in case the TSDB retention is several days.
679+
q, err := db.Querier(ctx, db.Head().MinTime(), db.Head().MaxTime())
680680
if err != nil {
681681
return nil, err
682682
}
@@ -689,14 +689,20 @@ func (i *Ingester) v2MetricsForLabelMatchers(ctx context.Context, req *client.Me
689689
}
690690

691691
for _, matchers := range matchersSet {
692+
// Interrupt if the context has been canceled.
693+
if ctx.Err() != nil {
694+
return nil, ctx.Err()
695+
}
696+
692697
seriesSet := q.Select(false, nil, matchers...)
693698
if seriesSet.Err() != nil {
694699
return nil, seriesSet.Err()
695700
}
696701

697702
for seriesSet.Next() {
698-
if seriesSet.Err() != nil {
699-
break
703+
// Interrupt if the context has been canceled.
704+
if ctx.Err() != nil {
705+
return nil, ctx.Err()
700706
}
701707

702708
// Given the same series can be matched by multiple matchers and we want to

0 commit comments

Comments
 (0)