mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Loki: Remove getQueryOptions as not needed in tests (#80747)
* Loki: Remove getQueryOptions as not needed in tests * Update to not assert
This commit is contained in:
parent
a1a9813d05
commit
120e9044c7
@ -1,6 +1,5 @@
|
|||||||
import { of } from 'rxjs';
|
import { of } from 'rxjs';
|
||||||
import { take } from 'rxjs/operators';
|
import { take } from 'rxjs/operators';
|
||||||
import { getQueryOptions } from 'test/helpers/getQueryOptions';
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
AbstractLabelOperator,
|
AbstractLabelOperator,
|
||||||
@ -18,6 +17,7 @@ import {
|
|||||||
toDataFrame,
|
toDataFrame,
|
||||||
TimeRange,
|
TimeRange,
|
||||||
ToggleFilterAction,
|
ToggleFilterAction,
|
||||||
|
DataQueryRequest,
|
||||||
} from '@grafana/data';
|
} from '@grafana/data';
|
||||||
import {
|
import {
|
||||||
BackendSrv,
|
BackendSrv,
|
||||||
@ -122,6 +122,17 @@ const mockTimeRange = {
|
|||||||
raw: { from: dateTime(0), to: dateTime(1) },
|
raw: { from: dateTime(0), to: dateTime(1) },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const baseRequestOptions = {
|
||||||
|
requestId: '',
|
||||||
|
interval: '',
|
||||||
|
intervalMs: 1,
|
||||||
|
range: mockTimeRange,
|
||||||
|
scopedVars: {},
|
||||||
|
timezone: '',
|
||||||
|
app: '',
|
||||||
|
startTime: 1,
|
||||||
|
};
|
||||||
|
|
||||||
interface AdHocFilter {
|
interface AdHocFilter {
|
||||||
condition: string;
|
condition: string;
|
||||||
key: string;
|
key: string;
|
||||||
@ -160,10 +171,11 @@ describe('LokiDatasource', () => {
|
|||||||
// and applyTemplateVariables is a convenient place to do that.
|
// and applyTemplateVariables is a convenient place to do that.
|
||||||
const spy = jest.spyOn(ds, 'applyTemplateVariables');
|
const spy = jest.spyOn(ds, 'applyTemplateVariables');
|
||||||
|
|
||||||
const options = getQueryOptions<LokiQuery>({
|
const options: DataQueryRequest<LokiQuery> = {
|
||||||
|
...baseRequestOptions,
|
||||||
targets: [{ expr: '{a="b"}', refId: 'B', maxLines: queryMaxLines }],
|
targets: [{ expr: '{a="b"}', refId: 'B', maxLines: queryMaxLines }],
|
||||||
app: app ?? CoreApp.Dashboard,
|
app: app ?? CoreApp.Dashboard,
|
||||||
});
|
};
|
||||||
|
|
||||||
const fetchMock = jest.fn().mockReturnValue(of({ data: testLogsResponse }));
|
const fetchMock = jest.fn().mockReturnValue(of({ data: testLogsResponse }));
|
||||||
setBackendSrv({ ...origBackendSrv, fetch: fetchMock });
|
setBackendSrv({ ...origBackendSrv, fetch: fetchMock });
|
||||||
@ -1239,36 +1251,40 @@ describe('LokiDatasource', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('creates provider for logs query', () => {
|
it('creates provider for logs query', () => {
|
||||||
const options = getQueryOptions<LokiQuery>({
|
const options: DataQueryRequest<LokiQuery> = {
|
||||||
|
...baseRequestOptions,
|
||||||
targets: [{ expr: '{label="value"}', refId: 'A', queryType: LokiQueryType.Range }],
|
targets: [{ expr: '{label="value"}', refId: 'A', queryType: LokiQueryType.Range }],
|
||||||
});
|
};
|
||||||
|
|
||||||
expect(ds.getDataProvider(SupplementaryQueryType.LogsVolume, options)).toBeDefined();
|
expect(ds.getDataProvider(SupplementaryQueryType.LogsVolume, options)).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not create provider for metrics query', () => {
|
it('does not create provider for metrics query', () => {
|
||||||
const options = getQueryOptions<LokiQuery>({
|
const options: DataQueryRequest<LokiQuery> = {
|
||||||
|
...baseRequestOptions,
|
||||||
targets: [{ expr: 'rate({label="value"}[1m])', refId: 'A' }],
|
targets: [{ expr: 'rate({label="value"}[1m])', refId: 'A' }],
|
||||||
});
|
};
|
||||||
|
|
||||||
expect(ds.getDataProvider(SupplementaryQueryType.LogsVolume, options)).not.toBeDefined();
|
expect(ds.getDataProvider(SupplementaryQueryType.LogsVolume, options)).not.toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('creates provider if at least one query is a logs query', () => {
|
it('creates provider if at least one query is a logs query', () => {
|
||||||
const options = getQueryOptions<LokiQuery>({
|
const options: DataQueryRequest<LokiQuery> = {
|
||||||
|
...baseRequestOptions,
|
||||||
targets: [
|
targets: [
|
||||||
{ expr: 'rate({label="value"}[1m])', queryType: LokiQueryType.Range, refId: 'A' },
|
{ expr: 'rate({label="value"}[1m])', queryType: LokiQueryType.Range, refId: 'A' },
|
||||||
{ expr: '{label="value"}', queryType: LokiQueryType.Range, refId: 'B' },
|
{ expr: '{label="value"}', queryType: LokiQueryType.Range, refId: 'B' },
|
||||||
],
|
],
|
||||||
});
|
};
|
||||||
|
|
||||||
expect(ds.getDataProvider(SupplementaryQueryType.LogsVolume, options)).toBeDefined();
|
expect(ds.getDataProvider(SupplementaryQueryType.LogsVolume, options)).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not create provider if there is only an instant logs query', () => {
|
it('does not create provider if there is only an instant logs query', () => {
|
||||||
const options = getQueryOptions<LokiQuery>({
|
const options: DataQueryRequest<LokiQuery> = {
|
||||||
|
...baseRequestOptions,
|
||||||
targets: [{ expr: '{label="value"', refId: 'A', queryType: LokiQueryType.Instant }],
|
targets: [{ expr: '{label="value"', refId: 'A', queryType: LokiQueryType.Instant }],
|
||||||
});
|
};
|
||||||
|
|
||||||
expect(ds.getDataProvider(SupplementaryQueryType.LogsVolume, options)).not.toBeDefined();
|
expect(ds.getDataProvider(SupplementaryQueryType.LogsVolume, options)).not.toBeDefined();
|
||||||
});
|
});
|
||||||
@ -1281,28 +1297,31 @@ describe('LokiDatasource', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('creates provider for metrics query', () => {
|
it('creates provider for metrics query', () => {
|
||||||
const options = getQueryOptions<LokiQuery>({
|
const options: DataQueryRequest<LokiQuery> = {
|
||||||
|
...baseRequestOptions,
|
||||||
targets: [{ expr: 'rate({label="value"}[5m])', refId: 'A' }],
|
targets: [{ expr: 'rate({label="value"}[5m])', refId: 'A' }],
|
||||||
});
|
};
|
||||||
|
|
||||||
expect(ds.getDataProvider(SupplementaryQueryType.LogsSample, options)).toBeDefined();
|
expect(ds.getDataProvider(SupplementaryQueryType.LogsSample, options)).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not create provider for log query', () => {
|
it('does not create provider for log query', () => {
|
||||||
const options = getQueryOptions<LokiQuery>({
|
const options: DataQueryRequest<LokiQuery> = {
|
||||||
|
...baseRequestOptions,
|
||||||
targets: [{ expr: '{label="value"}', refId: 'A' }],
|
targets: [{ expr: '{label="value"}', refId: 'A' }],
|
||||||
});
|
};
|
||||||
|
|
||||||
expect(ds.getDataProvider(SupplementaryQueryType.LogsSample, options)).not.toBeDefined();
|
expect(ds.getDataProvider(SupplementaryQueryType.LogsSample, options)).not.toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('creates provider if at least one query is a metric query', () => {
|
it('creates provider if at least one query is a metric query', () => {
|
||||||
const options = getQueryOptions<LokiQuery>({
|
const options: DataQueryRequest<LokiQuery> = {
|
||||||
|
...baseRequestOptions,
|
||||||
targets: [
|
targets: [
|
||||||
{ expr: 'rate({label="value"}[1m])', refId: 'A' },
|
{ expr: 'rate({label="value"}[1m])', refId: 'A' },
|
||||||
{ expr: '{label="value"}', refId: 'B' },
|
{ expr: '{label="value"}', refId: 'B' },
|
||||||
],
|
],
|
||||||
});
|
};
|
||||||
|
|
||||||
expect(ds.getDataProvider(SupplementaryQueryType.LogsSample, options)).toBeDefined();
|
expect(ds.getDataProvider(SupplementaryQueryType.LogsSample, options)).toBeDefined();
|
||||||
});
|
});
|
||||||
@ -1551,10 +1570,11 @@ describe('LokiDatasource', () => {
|
|||||||
],
|
],
|
||||||
])('supports query splitting when the requirements are met', async (targets: LokiQuery[]) => {
|
])('supports query splitting when the requirements are met', async (targets: LokiQuery[]) => {
|
||||||
const ds = createLokiDatasource(templateSrvStub);
|
const ds = createLokiDatasource(templateSrvStub);
|
||||||
const query = getQueryOptions<LokiQuery>({
|
const query: DataQueryRequest<LokiQuery> = {
|
||||||
|
...baseRequestOptions,
|
||||||
targets,
|
targets,
|
||||||
app: CoreApp.Dashboard,
|
app: CoreApp.Dashboard,
|
||||||
});
|
};
|
||||||
|
|
||||||
await expect(ds.query(query)).toEmitValuesWith(() => {
|
await expect(ds.query(query)).toEmitValuesWith(() => {
|
||||||
expect(runSplitQuery).toHaveBeenCalled();
|
expect(runSplitQuery).toHaveBeenCalled();
|
||||||
|
@ -3,7 +3,6 @@ import { createDataFrame } from '@grafana/data';
|
|||||||
import { getDerivedFields } from './getDerivedFields';
|
import { getDerivedFields } from './getDerivedFields';
|
||||||
|
|
||||||
jest.mock('@grafana/runtime', () => ({
|
jest.mock('@grafana/runtime', () => ({
|
||||||
// @ts-ignore
|
|
||||||
...jest.requireActual('@grafana/runtime'),
|
...jest.requireActual('@grafana/runtime'),
|
||||||
getDataSourceSrv: () => {
|
getDataSourceSrv: () => {
|
||||||
return {
|
return {
|
||||||
|
Loading…
Reference in New Issue
Block a user