Select implements storage.Querier interface. The bool passed is ignored because the series is always sorted.
(ctx context.Context, sortSeries bool, sp *storage.SelectHints, matchers ...*labels.Matcher)
| 97 | // Select implements storage.Querier interface. |
| 98 | // The bool passed is ignored because the series is always sorted. |
| 99 | func (q *distributorQuerier) Select(ctx context.Context, sortSeries bool, sp *storage.SelectHints, matchers ...*labels.Matcher) storage.SeriesSet { |
| 100 | log, ctx := spanlogger.New(ctx, "distributorQuerier.Select") |
| 101 | defer log.Finish() |
| 102 | |
| 103 | minT, maxT := q.mint, q.maxt |
| 104 | if sp != nil { |
| 105 | minT, maxT = sp.Start, sp.End |
| 106 | } |
| 107 | |
| 108 | // We should manipulate the query mint to query samples up until |
| 109 | // now - queryIngestersWithin, because older time ranges are covered by the storage. This |
| 110 | // optimization is particularly important for the blocks storage where the blocks retention in the |
| 111 | // ingesters could be way higher than queryIngestersWithin. |
| 112 | if q.queryIngestersWithin > 0 { |
| 113 | now := time.Now() |
| 114 | origMinT := minT |
| 115 | minT = max(minT, util.TimeToMillis(now.Add(-q.queryIngestersWithin))) |
| 116 | |
| 117 | if origMinT != minT { |
| 118 | level.Debug(log).Log("msg", "the min time of the query to ingesters has been manipulated", "original", origMinT, "updated", minT) |
| 119 | } |
| 120 | |
| 121 | if minT > maxT { |
| 122 | level.Debug(log).Log("msg", "empty query time range after min time manipulation") |
| 123 | return storage.EmptySeriesSet() |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | partialDataEnabled := q.partialDataEnabled(ctx) |
| 128 | |
| 129 | // In the recent versions of Prometheus, we pass in the hint but with Func set to "series". |
| 130 | // See: https://github.com/prometheus/prometheus/pull/8050 |
| 131 | if sp != nil && sp.Func == "series" { |
| 132 | var ( |
| 133 | ms []labels.Labels |
| 134 | err error |
| 135 | ) |
| 136 | |
| 137 | if q.streamingMetadata { |
| 138 | ms, err = q.distributor.MetricsForLabelMatchersStream(ctx, model.Time(minT), model.Time(maxT), sp, partialDataEnabled, matchers...) |
| 139 | } else { |
| 140 | ms, err = q.distributor.MetricsForLabelMatchers(ctx, model.Time(minT), model.Time(maxT), sp, partialDataEnabled, matchers...) |
| 141 | } |
| 142 | |
| 143 | if err != nil && !partialdata.IsPartialDataError(err) { |
| 144 | return storage.ErrSeriesSet(err) |
| 145 | } |
| 146 | |
| 147 | seriesSet := series.LabelsSetToSeriesSet(sortSeries, ms) |
| 148 | |
| 149 | if partialdata.IsPartialDataError(err) { |
| 150 | warning := seriesSet.Warnings() |
| 151 | return series.NewSeriesSetWithWarnings(seriesSet, warning.Add(err)) |
| 152 | } |
| 153 | |
| 154 | return seriesSet |
| 155 | } |
| 156 |
nothing calls this directly
no test coverage detected