labelsValuesCommon returns all label values that are associated with a given label name. this should be used by LabelValues and LabelValuesStream the cleanup function should be called in order to close the querier
(ctx context.Context, req *client.LabelValuesRequest)
| 1929 | // this should be used by LabelValues and LabelValuesStream |
| 1930 | // the cleanup function should be called in order to close the querier |
| 1931 | func (i *Ingester) labelsValuesCommon(ctx context.Context, req *client.LabelValuesRequest) (*client.LabelValuesResponse, func(), error) { |
| 1932 | cleanup := func() {} |
| 1933 | if err := i.checkRunning(); err != nil { |
| 1934 | return nil, cleanup, err |
| 1935 | } |
| 1936 | |
| 1937 | labelName, startTimestampMs, endTimestampMs, limit, matchers, err := client.FromLabelValuesRequest(i.matchersCache, req) |
| 1938 | if err != nil { |
| 1939 | return nil, cleanup, err |
| 1940 | } |
| 1941 | |
| 1942 | userID, err := users.TenantID(ctx) |
| 1943 | if err != nil { |
| 1944 | return nil, cleanup, err |
| 1945 | } |
| 1946 | |
| 1947 | db, err := i.getTSDB(userID) |
| 1948 | if err != nil || db == nil { |
| 1949 | return &client.LabelValuesResponse{}, cleanup, nil |
| 1950 | } |
| 1951 | |
| 1952 | if err := db.acquireReadLock(); err != nil { |
| 1953 | return &client.LabelValuesResponse{}, cleanup, nil |
| 1954 | } |
| 1955 | defer db.releaseReadLock() |
| 1956 | |
| 1957 | mint, maxt, err := metadataQueryRange(startTimestampMs, endTimestampMs, db, i.cfg.QueryIngestersWithin) |
| 1958 | if err != nil { |
| 1959 | return nil, cleanup, err |
| 1960 | } |
| 1961 | |
| 1962 | q, err := db.Querier(mint, maxt) |
| 1963 | if err != nil { |
| 1964 | return nil, cleanup, err |
| 1965 | } |
| 1966 | |
| 1967 | cleanup = func() { |
| 1968 | q.Close() |
| 1969 | } |
| 1970 | |
| 1971 | c, err := i.trackInflightQueryRequest() |
| 1972 | if err != nil { |
| 1973 | return nil, cleanup, err |
| 1974 | } |
| 1975 | defer c() |
| 1976 | vals, _, err := q.LabelValues(ctx, labelName, &storage.LabelHints{Limit: limit}, matchers...) |
| 1977 | if err != nil { |
| 1978 | return nil, cleanup, err |
| 1979 | } |
| 1980 | |
| 1981 | if limit > 0 && len(vals) > limit { |
| 1982 | vals = vals[:limit] |
| 1983 | } |
| 1984 | |
| 1985 | return &client.LabelValuesResponse{ |
| 1986 | LabelValues: vals, |
| 1987 | }, cleanup, nil |
| 1988 | } |
no test coverage detected