metricsForLabelMatchersCommon returns all the metrics which match a set of matchers. this should be used by MetricsForLabelMatchers and MetricsForLabelMatchersStream. the cleanup function should be called in order to close the querier
(ctx context.Context, req *client.MetricsForLabelMatchersRequest, acc func(labels.Labels) error)
| 2176 | // this should be used by MetricsForLabelMatchers and MetricsForLabelMatchersStream. |
| 2177 | // the cleanup function should be called in order to close the querier |
| 2178 | func (i *Ingester) metricsForLabelMatchersCommon(ctx context.Context, req *client.MetricsForLabelMatchersRequest, acc func(labels.Labels) error) (func(), error) { |
| 2179 | cleanup := func() {} |
| 2180 | if err := i.checkRunning(); err != nil { |
| 2181 | return cleanup, err |
| 2182 | } |
| 2183 | |
| 2184 | userID, err := users.TenantID(ctx) |
| 2185 | if err != nil { |
| 2186 | return cleanup, err |
| 2187 | } |
| 2188 | |
| 2189 | db, err := i.getTSDB(userID) |
| 2190 | if err != nil || db == nil { |
| 2191 | return cleanup, nil |
| 2192 | } |
| 2193 | |
| 2194 | if err := db.acquireReadLock(); err != nil { |
| 2195 | return cleanup, nil |
| 2196 | } |
| 2197 | defer db.releaseReadLock() |
| 2198 | |
| 2199 | // Parse the request |
| 2200 | _, _, limit, matchersSet, err := client.FromMetricsForLabelMatchersRequest(i.matchersCache, req) |
| 2201 | if err != nil { |
| 2202 | return cleanup, err |
| 2203 | } |
| 2204 | |
| 2205 | mint, maxt, err := metadataQueryRange(req.StartTimestampMs, req.EndTimestampMs, db, i.cfg.QueryIngestersWithin) |
| 2206 | if err != nil { |
| 2207 | return cleanup, err |
| 2208 | } |
| 2209 | |
| 2210 | q, err := db.Querier(mint, maxt) |
| 2211 | if err != nil { |
| 2212 | return cleanup, err |
| 2213 | } |
| 2214 | |
| 2215 | cleanup = func() { |
| 2216 | q.Close() |
| 2217 | } |
| 2218 | |
| 2219 | // Run a query for each matchers set and collect all the results. |
| 2220 | var ( |
| 2221 | sets []storage.SeriesSet |
| 2222 | mergedSet storage.SeriesSet |
| 2223 | ) |
| 2224 | |
| 2225 | hints := &storage.SelectHints{ |
| 2226 | Start: mint, |
| 2227 | End: maxt, |
| 2228 | Func: "series", // There is no series function, this token is used for lookups that don't need samples. |
| 2229 | Limit: limit, |
| 2230 | } |
| 2231 | if len(matchersSet) > 1 { |
| 2232 | for _, matchers := range matchersSet { |
| 2233 | // Interrupt if the context has been canceled. |
| 2234 | if ctx.Err() != nil { |
| 2235 | return cleanup, ctx.Err() |
no test coverage detected