|
|
|
|
@ -5,6 +5,7 @@ import { AnnotationQueryRequest, DataSourceApi, DataFrame, dateTime, TimeRange } |
|
|
|
|
import { BackendSrv } from 'app/core/services/backend_srv'; |
|
|
|
|
import { TemplateSrv } from 'app/features/templating/template_srv'; |
|
|
|
|
import { CustomVariable } from 'app/features/templating/custom_variable'; |
|
|
|
|
import { makeMockLokiDatasource } from './mocks'; |
|
|
|
|
import { ExploreMode } from 'app/types'; |
|
|
|
|
import { of } from 'rxjs'; |
|
|
|
|
import omit from 'lodash/omit'; |
|
|
|
|
@ -357,6 +358,57 @@ describe('LokiDatasource', () => { |
|
|
|
|
expect(res[1].tags).toEqual(['value2']); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
describe('metricFindQuery', () => { |
|
|
|
|
const ds = new LokiDatasource(instanceSettings, backendSrv, templateSrvMock); |
|
|
|
|
const mocks = makeMetadataAndVersionsMocks(); |
|
|
|
|
|
|
|
|
|
mocks.forEach((mock, index) => { |
|
|
|
|
it(`should return label names for Loki v${index}`, async () => { |
|
|
|
|
ds.getVersion = mock.getVersion; |
|
|
|
|
ds.metadataRequest = mock.metadataRequest; |
|
|
|
|
const query = 'label_names()'; |
|
|
|
|
const res = await ds.metricFindQuery(query); |
|
|
|
|
expect(res[0].text).toEqual('label1'); |
|
|
|
|
expect(res[1].text).toEqual('label2'); |
|
|
|
|
expect(res.length).toBe(2); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
mocks.forEach((mock, index) => { |
|
|
|
|
it(`should return label names for Loki v${index}`, async () => { |
|
|
|
|
ds.getVersion = mock.getVersion; |
|
|
|
|
ds.metadataRequest = mock.metadataRequest; |
|
|
|
|
const query = 'label_names()'; |
|
|
|
|
const res = await ds.metricFindQuery(query); |
|
|
|
|
expect(res[0].text).toEqual('label1'); |
|
|
|
|
expect(res[1].text).toEqual('label2'); |
|
|
|
|
expect(res.length).toBe(2); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
mocks.forEach((mock, index) => { |
|
|
|
|
it(`should return label values for Loki v${index}`, async () => { |
|
|
|
|
ds.getVersion = mock.getVersion; |
|
|
|
|
ds.metadataRequest = mock.metadataRequest; |
|
|
|
|
const query = 'label_values(label1)'; |
|
|
|
|
const res = await ds.metricFindQuery(query); |
|
|
|
|
expect(res[0].text).toEqual('value1'); |
|
|
|
|
expect(res[1].text).toEqual('value2'); |
|
|
|
|
expect(res.length).toBe(2); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
mocks.forEach((mock, index) => { |
|
|
|
|
it(`should return empty array when incorrect query for Loki v${index}`, async () => { |
|
|
|
|
ds.getVersion = mock.getVersion; |
|
|
|
|
ds.metadataRequest = mock.metadataRequest; |
|
|
|
|
const query = 'incorrect_query'; |
|
|
|
|
const res = await ds.metricFindQuery(query); |
|
|
|
|
expect(res.length).toBe(0); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
type LimitTestArgs = { |
|
|
|
|
@ -418,3 +470,13 @@ function makeAnnotationQueryRequest(): AnnotationQueryRequest<LokiQuery> { |
|
|
|
|
rangeRaw: timeRange, |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function makeMetadataAndVersionsMocks() { |
|
|
|
|
const mocks = []; |
|
|
|
|
for (let i = 0; i <= 1; i++) { |
|
|
|
|
const mock: LokiDatasource = makeMockLokiDatasource({ label1: ['value1', 'value2'], label2: ['value3', 'value4'] }); |
|
|
|
|
mock.getVersion = jest.fn().mockReturnValue(`v${i}`); |
|
|
|
|
mocks.push(mock); |
|
|
|
|
} |
|
|
|
|
return mocks; |
|
|
|
|
} |
|
|
|
|
|