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:
Gábor Farkas 2022-04-26 11:51:26 +02:00 committed by GitHub
parent fc0346fe5b
commit c73b9d1818
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 7 additions and 7 deletions

View File

@ -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)

View File

@ -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 }));

View File

@ -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);
});
});

View File

@ -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();

View File

@ -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,