mirror of
https://github.com/grafana/grafana.git
synced 2024-12-01 04:59:15 -06:00
Loki: do not use the old labels-api (#48185)
* loki: do not use old labels-api * adjust allowed-url-list * fixed tests
This commit is contained in:
parent
fc0346fe5b
commit
c73b9d1818
@ -98,7 +98,7 @@ func (s *Service) CallResource(ctx context.Context, req *backend.CallResourceReq
|
||||
if req.Method != "GET" {
|
||||
return fmt.Errorf("invalid resource method: %s", req.Method)
|
||||
}
|
||||
if (!strings.HasPrefix(url, "/loki/api/v1/label?")) &&
|
||||
if (!strings.HasPrefix(url, "/loki/api/v1/labels?")) &&
|
||||
(!strings.HasPrefix(url, "/loki/api/v1/label/")) && // the `/label/$label_name/values` form
|
||||
(!strings.HasPrefix(url, "/loki/api/v1/series?")) {
|
||||
return fmt.Errorf("invalid resource URL: %s", url)
|
||||
|
@ -441,10 +441,10 @@ export class LokiDatasource
|
||||
async metadataRequest(url: string, params?: Record<string, string | number>) {
|
||||
if (config.featureToggles.lokiBackendMode) {
|
||||
const res = await this.getResource(url, params);
|
||||
return res.data || res.values || [];
|
||||
return res.data || [];
|
||||
} else {
|
||||
const res = await lastValueFrom(this._request(url, params, { hideFromInspector: true }));
|
||||
return res.data.data || res.data.values || [];
|
||||
return res.data.data || [];
|
||||
}
|
||||
}
|
||||
|
||||
@ -479,7 +479,7 @@ export class LokiDatasource
|
||||
}
|
||||
|
||||
async labelNamesQuery() {
|
||||
const url = `${LOKI_ENDPOINT}/label`;
|
||||
const url = `${LOKI_ENDPOINT}/labels`;
|
||||
const params = this.getTimeRangeParams();
|
||||
const result = await this.metadataRequest(url, params);
|
||||
return result.map((value: string) => ({ text: value }));
|
||||
|
@ -259,7 +259,7 @@ describe('Request URL', () => {
|
||||
|
||||
const instance = new LanguageProvider(datasourceWithLabels);
|
||||
instance.fetchLabels();
|
||||
const expectedUrl = '/loki/api/v1/label';
|
||||
const expectedUrl = '/loki/api/v1/labels';
|
||||
expect(datasourceSpy).toHaveBeenCalledWith(expectedUrl, rangeParams);
|
||||
});
|
||||
});
|
||||
|
@ -364,7 +364,7 @@ export default class LokiLanguageProvider extends LanguageProvider {
|
||||
* Fetches all label keys
|
||||
*/
|
||||
async fetchLabels(): Promise<string[]> {
|
||||
const url = '/loki/api/v1/label';
|
||||
const url = '/loki/api/v1/labels';
|
||||
const timeRange = this.datasource.getTimeRangeParams();
|
||||
this.labelFetchTs = Date.now().valueOf();
|
||||
|
||||
|
@ -21,7 +21,7 @@ export function makeMockLokiDatasource(labelsAndValues: Labels, series?: SeriesF
|
||||
const lokiLabelsAndValuesEndpointRegex = /^\/loki\/api\/v1\/label\/(\w*)\/values/;
|
||||
const lokiSeriesEndpointRegex = /^\/loki\/api\/v1\/series/;
|
||||
|
||||
const lokiLabelsEndpoint = `${LOKI_ENDPOINT}/label`;
|
||||
const lokiLabelsEndpoint = `${LOKI_ENDPOINT}/labels`;
|
||||
const rangeMock = {
|
||||
start: 1560153109000,
|
||||
end: 1560163909000,
|
||||
|
Loading…
Reference in New Issue
Block a user