loki: add back frontend-mode metadata queries (#49297)

pull/49287/head
Gábor Farkas 3 years ago committed by GitHub
parent 93e299305c
commit 0caeaaafe3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      public/app/plugins/datasource/loki/datasource.test.ts
  2. 11
      public/app/plugins/datasource/loki/datasource.ts

@ -1002,7 +1002,7 @@ describe('LokiDatasource', () => {
describe('importing queries', () => {
it('keeps all labels when no labels are loaded', async () => {
const ds = createLokiDSForTests();
ds.getResource = () => Promise.resolve({ data: [] });
fetchMock.mockImplementation(() => of(createFetchResponse({ data: [] })));
const queries = await ds.importFromAbstractQueries([
{
refId: 'A',
@ -1017,9 +1017,7 @@ describe('LokiDatasource', () => {
it('filters out non existing labels', async () => {
const ds = createLokiDSForTests();
ds.getResource = () => {
return Promise.resolve({ data: ['foo'] });
};
fetchMock.mockImplementation(() => of(createFetchResponse({ data: ['foo'] })));
const queries = await ds.importFromAbstractQueries([
{
refId: 'A',

@ -467,8 +467,15 @@ export class LokiDatasource
if (url.startsWith('/')) {
throw new Error(`invalid metadata request url: ${url}`);
}
const res = await this.getResource(url, params);
return res.data || [];
if (this.useBackendMode) {
const res = await this.getResource(url, params);
return res.data || [];
} else {
const lokiURL = `${LOKI_ENDPOINT}/${url}`;
const res = await lastValueFrom(this._request(lokiURL, params, { hideFromInspector: true }));
return res.data.data || [];
}
}
async metricFindQuery(query: string) {

Loading…
Cancel
Save