labelNamesCommon return all the label names. this should be used by LabelNames and LabelNamesStream. the cleanup function should be called in order to close the querier
(ctx context.Context, req *client.LabelNamesRequest)
| 2045 | // this should be used by LabelNames and LabelNamesStream. |
| 2046 | // the cleanup function should be called in order to close the querier |
| 2047 | func (i *Ingester) labelNamesCommon(ctx context.Context, req *client.LabelNamesRequest) (*client.LabelNamesResponse, func(), error) { |
| 2048 | cleanup := func() {} |
| 2049 | if err := i.checkRunning(); err != nil { |
| 2050 | return nil, cleanup, err |
| 2051 | } |
| 2052 | |
| 2053 | startTimestampMs, endTimestampMs, limit, matchers, err := client.FromLabelNamesRequest(i.matchersCache, req) |
| 2054 | if err != nil { |
| 2055 | return nil, cleanup, err |
| 2056 | } |
| 2057 | |
| 2058 | userID, err := users.TenantID(ctx) |
| 2059 | if err != nil { |
| 2060 | return nil, cleanup, err |
| 2061 | } |
| 2062 | |
| 2063 | db, err := i.getTSDB(userID) |
| 2064 | if err != nil || db == nil { |
| 2065 | return &client.LabelNamesResponse{}, cleanup, nil |
| 2066 | } |
| 2067 | |
| 2068 | if err := db.acquireReadLock(); err != nil { |
| 2069 | return &client.LabelNamesResponse{}, cleanup, nil |
| 2070 | } |
| 2071 | defer db.releaseReadLock() |
| 2072 | |
| 2073 | mint, maxt, err := metadataQueryRange(startTimestampMs, endTimestampMs, db, i.cfg.QueryIngestersWithin) |
| 2074 | if err != nil { |
| 2075 | return nil, cleanup, err |
| 2076 | } |
| 2077 | |
| 2078 | q, err := db.Querier(mint, maxt) |
| 2079 | if err != nil { |
| 2080 | return nil, cleanup, err |
| 2081 | } |
| 2082 | |
| 2083 | cleanup = func() { |
| 2084 | q.Close() |
| 2085 | } |
| 2086 | |
| 2087 | c, err := i.trackInflightQueryRequest() |
| 2088 | if err != nil { |
| 2089 | return nil, cleanup, err |
| 2090 | } |
| 2091 | defer c() |
| 2092 | names, _, err := q.LabelNames(ctx, &storage.LabelHints{Limit: limit}, matchers...) |
| 2093 | if err != nil { |
| 2094 | return nil, cleanup, err |
| 2095 | } |
| 2096 | |
| 2097 | if limit > 0 && len(names) > limit { |
| 2098 | names = names[:limit] |
| 2099 | } |
| 2100 | |
| 2101 | return &client.LabelNamesResponse{ |
| 2102 | LabelNames: names, |
| 2103 | }, cleanup, nil |
| 2104 | } |
no test coverage detected