mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Loki: Remove imports from core in various files (#79990)
* Remove imports from core in tracking.ts * Remove imports from core in tracking.test.ts * Remove imports from core in querySplitting.test.ts
This commit is contained in:
parent
6fbd6e3d31
commit
df8624c8cd
@ -1,7 +1,6 @@
|
|||||||
import { of } from 'rxjs';
|
import { of } from 'rxjs';
|
||||||
import { getQueryOptions } from 'test/helpers/getQueryOptions';
|
|
||||||
|
|
||||||
import { dateTime, LoadingState } from '@grafana/data';
|
import { DataQueryRequest, dateTime, LoadingState } from '@grafana/data';
|
||||||
|
|
||||||
import { createLokiDatasource } from './__mocks__/datasource';
|
import { createLokiDatasource } from './__mocks__/datasource';
|
||||||
import { getMockFrames } from './__mocks__/frames';
|
import { getMockFrames } from './__mocks__/frames';
|
||||||
@ -27,10 +26,19 @@ describe('runSplitQuery()', () => {
|
|||||||
to: dateTime('2023-02-10T06:00:00.000Z'),
|
to: dateTime('2023-02-10T06:00:00.000Z'),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const request = getQueryOptions<LokiQuery>({
|
|
||||||
targets: [{ expr: 'count_over_time({a="b"}[1m])', refId: 'A' }],
|
const createRequest = (targets: LokiQuery[], overrides?: Partial<DataQueryRequest<LokiQuery>>) => {
|
||||||
range,
|
const request = {
|
||||||
});
|
range,
|
||||||
|
targets,
|
||||||
|
intervalMs: 60000,
|
||||||
|
requestId: 'TEST',
|
||||||
|
} as DataQueryRequest<LokiQuery>;
|
||||||
|
|
||||||
|
Object.assign(request, overrides);
|
||||||
|
return request;
|
||||||
|
};
|
||||||
|
const request = createRequest([{ expr: 'count_over_time({a="b"}[1m])', refId: 'A' }]);
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
datasource = createLokiDatasource();
|
datasource = createLokiDatasource();
|
||||||
jest.spyOn(datasource, 'runQuery').mockReturnValue(of({ data: [] }));
|
jest.spyOn(datasource, 'runQuery').mockReturnValue(of({ data: [] }));
|
||||||
@ -44,10 +52,7 @@ describe('runSplitQuery()', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Metric queries with maxLines of 0 will execute', async () => {
|
test('Metric queries with maxLines of 0 will execute', async () => {
|
||||||
const request = getQueryOptions<LokiQuery>({
|
const request = createRequest([{ expr: 'count_over_time({a="b"}[1m])', refId: 'A', maxLines: 0 }]);
|
||||||
targets: [{ expr: 'count_over_time({a="b"}[1m])', refId: 'A', maxLines: 0 }],
|
|
||||||
range,
|
|
||||||
});
|
|
||||||
await expect(runSplitQuery(datasource, request)).toEmitValuesWith(() => {
|
await expect(runSplitQuery(datasource, request)).toEmitValuesWith(() => {
|
||||||
// 3 days, 3 chunks, 3 requests.
|
// 3 days, 3 chunks, 3 requests.
|
||||||
expect(datasource.runQuery).toHaveBeenCalledTimes(3);
|
expect(datasource.runQuery).toHaveBeenCalledTimes(3);
|
||||||
@ -55,10 +60,7 @@ describe('runSplitQuery()', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Log queries with maxLines of 0 will NOT execute', async () => {
|
test('Log queries with maxLines of 0 will NOT execute', async () => {
|
||||||
const request = getQueryOptions<LokiQuery>({
|
const request = createRequest([{ expr: '{a="b"}', refId: 'A', maxLines: 0 }]);
|
||||||
targets: [{ expr: '{a="b"}', refId: 'A', maxLines: 0 }],
|
|
||||||
range,
|
|
||||||
});
|
|
||||||
await expect(runSplitQuery(datasource, request)).toEmitValuesWith(() => {
|
await expect(runSplitQuery(datasource, request)).toEmitValuesWith(() => {
|
||||||
// Will not request a log query with maxLines of 0
|
// Will not request a log query with maxLines of 0
|
||||||
expect(datasource.runQuery).toHaveBeenCalledTimes(0);
|
expect(datasource.runQuery).toHaveBeenCalledTimes(0);
|
||||||
@ -220,13 +222,10 @@ describe('runSplitQuery()', () => {
|
|||||||
jest.useRealTimers();
|
jest.useRealTimers();
|
||||||
});
|
});
|
||||||
test('Ignores hidden queries', async () => {
|
test('Ignores hidden queries', async () => {
|
||||||
const request = getQueryOptions<LokiQuery>({
|
const request = createRequest([
|
||||||
targets: [
|
{ expr: 'count_over_time({a="b"}[1m])', refId: 'A', hide: true },
|
||||||
{ expr: 'count_over_time({a="b"}[1m])', refId: 'A', hide: true },
|
{ expr: '{a="b"}', refId: 'B' },
|
||||||
{ expr: '{a="b"}', refId: 'B' },
|
]);
|
||||||
],
|
|
||||||
range,
|
|
||||||
});
|
|
||||||
await expect(runSplitQuery(datasource, request)).toEmitValuesWith(() => {
|
await expect(runSplitQuery(datasource, request)).toEmitValuesWith(() => {
|
||||||
expect(logsTimeSplit.splitTimeRange).toHaveBeenCalled();
|
expect(logsTimeSplit.splitTimeRange).toHaveBeenCalled();
|
||||||
expect(metricTimeSplit.splitTimeRange).not.toHaveBeenCalled();
|
expect(metricTimeSplit.splitTimeRange).not.toHaveBeenCalled();
|
||||||
@ -253,13 +252,10 @@ describe('runSplitQuery()', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
test('Ignores empty queries', async () => {
|
test('Ignores empty queries', async () => {
|
||||||
const request = getQueryOptions<LokiQuery>({
|
const request = createRequest([
|
||||||
targets: [
|
{ expr: 'count_over_time({a="b"}[1m])', refId: 'A' },
|
||||||
{ expr: 'count_over_time({a="b"}[1m])', refId: 'A' },
|
{ expr: '', refId: 'B' },
|
||||||
{ expr: '', refId: 'B' },
|
]);
|
||||||
],
|
|
||||||
range,
|
|
||||||
});
|
|
||||||
await expect(runSplitQuery(datasource, request)).toEmitValuesWith(() => {
|
await expect(runSplitQuery(datasource, request)).toEmitValuesWith(() => {
|
||||||
expect(logsTimeSplit.splitTimeRange).not.toHaveBeenCalled();
|
expect(logsTimeSplit.splitTimeRange).not.toHaveBeenCalled();
|
||||||
expect(metricTimeSplit.splitTimeRange).toHaveBeenCalled();
|
expect(metricTimeSplit.splitTimeRange).toHaveBeenCalled();
|
||||||
@ -288,10 +284,7 @@ describe('runSplitQuery()', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Dynamic maxLines for logs requests', () => {
|
describe('Dynamic maxLines for logs requests', () => {
|
||||||
const request = getQueryOptions<LokiQuery>({
|
const request = createRequest([{ expr: '{a="b"}', refId: 'A', maxLines: 4 }]);
|
||||||
targets: [{ expr: '{a="b"}', refId: 'A', maxLines: 4 }],
|
|
||||||
range,
|
|
||||||
});
|
|
||||||
const { logFrameA } = getMockFrames();
|
const { logFrameA } = getMockFrames();
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.spyOn(datasource, 'runQuery').mockReturnValue(of({ data: [logFrameA], refId: 'A' }));
|
jest.spyOn(datasource, 'runQuery').mockReturnValue(of({ data: [logFrameA], refId: 'A' }));
|
||||||
@ -324,52 +317,40 @@ describe('runSplitQuery()', () => {
|
|||||||
jest.spyOn(datasource, 'runQuery').mockReturnValue(of({ data: [], refId: 'A' }));
|
jest.spyOn(datasource, 'runQuery').mockReturnValue(of({ data: [], refId: 'A' }));
|
||||||
});
|
});
|
||||||
test('Sends logs and metric queries individually', async () => {
|
test('Sends logs and metric queries individually', async () => {
|
||||||
const request = getQueryOptions<LokiQuery>({
|
const request = createRequest([
|
||||||
targets: [
|
{ expr: '{a="b"}', refId: 'A' },
|
||||||
{ expr: '{a="b"}', refId: 'A' },
|
{ expr: 'count_over_time({a="b"}[1m])', refId: 'B' },
|
||||||
{ expr: 'count_over_time({a="b"}[1m])', refId: 'B' },
|
]);
|
||||||
],
|
|
||||||
range,
|
|
||||||
});
|
|
||||||
await expect(runSplitQuery(datasource, request)).toEmitValuesWith(() => {
|
await expect(runSplitQuery(datasource, request)).toEmitValuesWith(() => {
|
||||||
// 3 days, 3 chunks, 1x Metric + 1x Log, 6 requests.
|
// 3 days, 3 chunks, 1x Metric + 1x Log, 6 requests.
|
||||||
expect(datasource.runQuery).toHaveBeenCalledTimes(6);
|
expect(datasource.runQuery).toHaveBeenCalledTimes(6);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
test('Groups metric queries', async () => {
|
test('Groups metric queries', async () => {
|
||||||
const request = getQueryOptions<LokiQuery>({
|
const request = createRequest([
|
||||||
targets: [
|
{ expr: 'count_over_time({a="b"}[1m])', refId: 'A' },
|
||||||
{ expr: 'count_over_time({a="b"}[1m])', refId: 'A' },
|
{ expr: 'count_over_time({c="d"}[1m])', refId: 'B' },
|
||||||
{ expr: 'count_over_time({c="d"}[1m])', refId: 'B' },
|
]);
|
||||||
],
|
|
||||||
range,
|
|
||||||
});
|
|
||||||
await expect(runSplitQuery(datasource, request)).toEmitValuesWith(() => {
|
await expect(runSplitQuery(datasource, request)).toEmitValuesWith(() => {
|
||||||
// 3 days, 3 chunks, 1x2 Metric, 3 requests.
|
// 3 days, 3 chunks, 1x2 Metric, 3 requests.
|
||||||
expect(datasource.runQuery).toHaveBeenCalledTimes(3);
|
expect(datasource.runQuery).toHaveBeenCalledTimes(3);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
test('Groups logs queries', async () => {
|
test('Groups logs queries', async () => {
|
||||||
const request = getQueryOptions<LokiQuery>({
|
const request = createRequest([
|
||||||
targets: [
|
{ expr: '{a="b"}', refId: 'A' },
|
||||||
{ expr: '{a="b"}', refId: 'A' },
|
{ expr: '{c="d"}', refId: 'B' },
|
||||||
{ expr: '{c="d"}', refId: 'B' },
|
]);
|
||||||
],
|
|
||||||
range,
|
|
||||||
});
|
|
||||||
await expect(runSplitQuery(datasource, request)).toEmitValuesWith(() => {
|
await expect(runSplitQuery(datasource, request)).toEmitValuesWith(() => {
|
||||||
// 3 days, 3 chunks, 1x2 Logs, 3 requests.
|
// 3 days, 3 chunks, 1x2 Logs, 3 requests.
|
||||||
expect(datasource.runQuery).toHaveBeenCalledTimes(3);
|
expect(datasource.runQuery).toHaveBeenCalledTimes(3);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
test('Groups instant queries', async () => {
|
test('Groups instant queries', async () => {
|
||||||
const request = getQueryOptions<LokiQuery>({
|
const request = createRequest([
|
||||||
targets: [
|
{ expr: 'count_over_time({a="b"}[1m])', refId: 'A', queryType: LokiQueryType.Instant },
|
||||||
{ expr: 'count_over_time({a="b"}[1m])', refId: 'A', queryType: LokiQueryType.Instant },
|
{ expr: 'count_over_time({c="d"}[1m])', refId: 'B', queryType: LokiQueryType.Instant },
|
||||||
{ expr: 'count_over_time({c="d"}[1m])', refId: 'B', queryType: LokiQueryType.Instant },
|
]);
|
||||||
],
|
|
||||||
range,
|
|
||||||
});
|
|
||||||
await expect(runSplitQuery(datasource, request)).toEmitValuesWith(() => {
|
await expect(runSplitQuery(datasource, request)).toEmitValuesWith(() => {
|
||||||
// Instant queries are omitted from splitting
|
// Instant queries are omitted from splitting
|
||||||
expect(datasource.runQuery).toHaveBeenCalledTimes(1);
|
expect(datasource.runQuery).toHaveBeenCalledTimes(1);
|
||||||
@ -377,13 +358,10 @@ describe('runSplitQuery()', () => {
|
|||||||
});
|
});
|
||||||
test('Respects maxLines of logs queries', async () => {
|
test('Respects maxLines of logs queries', async () => {
|
||||||
const { logFrameA } = getMockFrames();
|
const { logFrameA } = getMockFrames();
|
||||||
const request = getQueryOptions<LokiQuery>({
|
const request = createRequest([
|
||||||
targets: [
|
{ expr: '{a="b"}', refId: 'A', maxLines: logFrameA.fields[0].values.length },
|
||||||
{ expr: '{a="b"}', refId: 'A', maxLines: logFrameA.fields[0].values.length },
|
{ expr: 'count_over_time({a="b"}[1m])', refId: 'B' },
|
||||||
{ expr: 'count_over_time({a="b"}[1m])', refId: 'B' },
|
]);
|
||||||
],
|
|
||||||
range,
|
|
||||||
});
|
|
||||||
jest.spyOn(datasource, 'runQuery').mockReturnValue(of({ data: [], refId: 'B' }));
|
jest.spyOn(datasource, 'runQuery').mockReturnValue(of({ data: [], refId: 'B' }));
|
||||||
jest.spyOn(datasource, 'runQuery').mockReturnValueOnce(of({ data: [logFrameA], refId: 'A' }));
|
jest.spyOn(datasource, 'runQuery').mockReturnValueOnce(of({ data: [logFrameA], refId: 'A' }));
|
||||||
|
|
||||||
@ -393,14 +371,11 @@ describe('runSplitQuery()', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
test('Groups multiple queries into logs, queries, instant', async () => {
|
test('Groups multiple queries into logs, queries, instant', async () => {
|
||||||
const request = getQueryOptions<LokiQuery>({
|
const request = createRequest([
|
||||||
targets: [
|
{ expr: 'count_over_time({a="b"}[1m])', refId: 'A', queryType: LokiQueryType.Instant },
|
||||||
{ expr: 'count_over_time({a="b"}[1m])', refId: 'A', queryType: LokiQueryType.Instant },
|
{ expr: '{c="d"}', refId: 'B' },
|
||||||
{ expr: '{c="d"}', refId: 'B' },
|
{ expr: 'count_over_time({c="d"}[1m])', refId: 'C' },
|
||||||
{ expr: 'count_over_time({c="d"}[1m])', refId: 'C' },
|
]);
|
||||||
],
|
|
||||||
range,
|
|
||||||
});
|
|
||||||
await expect(runSplitQuery(datasource, request)).toEmitValuesWith(() => {
|
await expect(runSplitQuery(datasource, request)).toEmitValuesWith(() => {
|
||||||
// 3 days, 3 chunks, 3x Logs + 3x Metric + (1x Instant), 7 requests.
|
// 3 days, 3 chunks, 3x Logs + 3x Metric + (1x Instant), 7 requests.
|
||||||
expect(datasource.runQuery).toHaveBeenCalledTimes(7);
|
expect(datasource.runQuery).toHaveBeenCalledTimes(7);
|
||||||
@ -421,70 +396,70 @@ describe('runSplitQuery()', () => {
|
|||||||
jest.spyOn(datasource, 'runQuery').mockReturnValue(of({ data: [], refId: 'A' }));
|
jest.spyOn(datasource, 'runQuery').mockReturnValue(of({ data: [], refId: 'A' }));
|
||||||
});
|
});
|
||||||
test('with 30m splitDuration runs 2 queries', async () => {
|
test('with 30m splitDuration runs 2 queries', async () => {
|
||||||
const request = getQueryOptions<LokiQuery>({
|
const request = {
|
||||||
targets: [{ expr: '{a="b"}', refId: 'A', splitDuration: '30m' }],
|
targets: [{ expr: '{a="b"}', refId: 'A', splitDuration: '30m' }],
|
||||||
range: range1h,
|
range: range1h,
|
||||||
});
|
} as DataQueryRequest<LokiQuery>;
|
||||||
await expect(runSplitQuery(datasource, request)).toEmitValuesWith(() => {
|
await expect(runSplitQuery(datasource, request)).toEmitValuesWith(() => {
|
||||||
expect(datasource.runQuery).toHaveBeenCalledTimes(2);
|
expect(datasource.runQuery).toHaveBeenCalledTimes(2);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
test('with 1h splitDuration runs 1 queries', async () => {
|
test('with 1h splitDuration runs 1 queries', async () => {
|
||||||
const request = getQueryOptions<LokiQuery>({
|
const request = {
|
||||||
targets: [{ expr: '{a="b"}', refId: 'A', splitDuration: '1h' }],
|
targets: [{ expr: '{a="b"}', refId: 'A', splitDuration: '1h' }],
|
||||||
range: range1h,
|
range: range1h,
|
||||||
});
|
} as DataQueryRequest<LokiQuery>;
|
||||||
await expect(runSplitQuery(datasource, request)).toEmitValuesWith(() => {
|
await expect(runSplitQuery(datasource, request)).toEmitValuesWith(() => {
|
||||||
expect(datasource.runQuery).toHaveBeenCalledTimes(1);
|
expect(datasource.runQuery).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
test('with 1h splitDuration and 2 targets runs 1 queries', async () => {
|
test('with 1h splitDuration and 2 targets runs 1 queries', async () => {
|
||||||
const request = getQueryOptions<LokiQuery>({
|
const request = {
|
||||||
targets: [
|
targets: [
|
||||||
{ expr: '{a="b"}', refId: 'A', splitDuration: '1h' },
|
{ expr: '{a="b"}', refId: 'A', splitDuration: '1h' },
|
||||||
{ expr: '{a="b"}', refId: 'B', splitDuration: '1h' },
|
{ expr: '{a="b"}', refId: 'B', splitDuration: '1h' },
|
||||||
],
|
],
|
||||||
range: range1h,
|
range: range1h,
|
||||||
});
|
} as DataQueryRequest<LokiQuery>;
|
||||||
await expect(runSplitQuery(datasource, request)).toEmitValuesWith(() => {
|
await expect(runSplitQuery(datasource, request)).toEmitValuesWith(() => {
|
||||||
expect(datasource.runQuery).toHaveBeenCalledTimes(1);
|
expect(datasource.runQuery).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
test('with 1h/30m splitDuration and 2 targets runs 3 queries', async () => {
|
test('with 1h/30m splitDuration and 2 targets runs 3 queries', async () => {
|
||||||
const request = getQueryOptions<LokiQuery>({
|
const request = {
|
||||||
targets: [
|
targets: [
|
||||||
{ expr: '{a="b"}', refId: 'A', splitDuration: '1h' },
|
{ expr: '{a="b"}', refId: 'A', splitDuration: '1h' },
|
||||||
{ expr: '{a="b"}', refId: 'B', splitDuration: '30m' },
|
{ expr: '{a="b"}', refId: 'B', splitDuration: '30m' },
|
||||||
],
|
],
|
||||||
range: range1h,
|
range: range1h,
|
||||||
});
|
} as DataQueryRequest<LokiQuery>;
|
||||||
await expect(runSplitQuery(datasource, request)).toEmitValuesWith(() => {
|
await expect(runSplitQuery(datasource, request)).toEmitValuesWith(() => {
|
||||||
// 2 x 30m + 1 x 1h
|
// 2 x 30m + 1 x 1h
|
||||||
expect(datasource.runQuery).toHaveBeenCalledTimes(3);
|
expect(datasource.runQuery).toHaveBeenCalledTimes(3);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
test('with mixed splitDuration runs the expected amount of queries', async () => {
|
test('with mixed splitDuration runs the expected amount of queries', async () => {
|
||||||
const request = getQueryOptions<LokiQuery>({
|
const request = createRequest(
|
||||||
targets: [
|
[
|
||||||
{ expr: 'count_over_time({c="d"}[1m])', refId: 'A', splitDuration: '15m' },
|
{ expr: 'count_over_time({c="d"}[1m])', refId: 'A', splitDuration: '15m' },
|
||||||
{ expr: '{a="b"}', refId: 'B', splitDuration: '15m' },
|
{ expr: '{a="b"}', refId: 'B', splitDuration: '15m' },
|
||||||
{ expr: '{a="b"}', refId: 'C', splitDuration: '1h' },
|
{ expr: '{a="b"}', refId: 'C', splitDuration: '1h' },
|
||||||
],
|
],
|
||||||
range: range1h,
|
{ range: range1h }
|
||||||
});
|
);
|
||||||
await expect(runSplitQuery(datasource, request)).toEmitValuesWith(() => {
|
await expect(runSplitQuery(datasource, request)).toEmitValuesWith(() => {
|
||||||
// 4 * 15m + 4 * 15m + 1 * 1h
|
// 4 * 15m + 4 * 15m + 1 * 1h
|
||||||
expect(datasource.runQuery).toHaveBeenCalledTimes(9);
|
expect(datasource.runQuery).toHaveBeenCalledTimes(9);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
test('with 1h/30m splitDuration and 1 log and 2 metric target runs 3 queries', async () => {
|
test('with 1h/30m splitDuration and 1 log and 2 metric target runs 3 queries', async () => {
|
||||||
const request = getQueryOptions<LokiQuery>({
|
const request = createRequest(
|
||||||
targets: [
|
[
|
||||||
{ expr: '{a="b"}', refId: 'A', splitDuration: '1h' },
|
{ expr: '{a="b"}', refId: 'A', splitDuration: '1h' },
|
||||||
{ expr: 'count_over_time({c="d"}[1m])', refId: 'C', splitDuration: '30m' },
|
{ expr: 'count_over_time({c="d"}[1m])', refId: 'C', splitDuration: '30m' },
|
||||||
],
|
],
|
||||||
range: range1h,
|
{ range: range1h }
|
||||||
});
|
);
|
||||||
await expect(runSplitQuery(datasource, request)).toEmitValuesWith(() => {
|
await expect(runSplitQuery(datasource, request)).toEmitValuesWith(() => {
|
||||||
// 2 x 30m + 1 x 1h
|
// 2 x 30m + 1 x 1h
|
||||||
expect(datasource.runQuery).toHaveBeenCalledTimes(3);
|
expect(datasource.runQuery).toHaveBeenCalledTimes(3);
|
||||||
@ -502,26 +477,26 @@ describe('runSplitQuery()', () => {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
test('Groups logs queries by resolution', async () => {
|
test('Groups logs queries by resolution', async () => {
|
||||||
const request = getQueryOptions<LokiQuery>({
|
const request = createRequest(
|
||||||
targets: [
|
[
|
||||||
{ expr: '{a="b"}', refId: 'A', resolution: 3 },
|
{ expr: '{a="b"}', refId: 'A', resolution: 3 },
|
||||||
{ expr: '{a="b"}', refId: 'B', resolution: 5 },
|
{ expr: '{a="b"}', refId: 'B', resolution: 5 },
|
||||||
],
|
],
|
||||||
range: range1d,
|
{ range: range1d }
|
||||||
});
|
);
|
||||||
await expect(runSplitQuery(datasource, request)).toEmitValuesWith(() => {
|
await expect(runSplitQuery(datasource, request)).toEmitValuesWith(() => {
|
||||||
// A, B
|
// A, B
|
||||||
expect(datasource.runQuery).toHaveBeenCalledTimes(2);
|
expect(datasource.runQuery).toHaveBeenCalledTimes(2);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
test('Groups metric queries with no step by calculated stepMs', async () => {
|
test('Groups metric queries with no step by calculated stepMs', async () => {
|
||||||
const request = getQueryOptions<LokiQuery>({
|
const request = createRequest(
|
||||||
targets: [
|
[
|
||||||
{ expr: 'count_over_time({a="b"}[1m])', refId: 'A', resolution: 3 },
|
{ expr: 'count_over_time({a="b"}[1m])', refId: 'A', resolution: 3 },
|
||||||
{ expr: 'count_over_time{a="b"}[1m])', refId: 'B', resolution: 5 },
|
{ expr: 'count_over_time{a="b"}[1m])', refId: 'B', resolution: 5 },
|
||||||
],
|
],
|
||||||
range: range1d,
|
{ range: range1d }
|
||||||
});
|
);
|
||||||
await expect(runSplitQuery(datasource, request)).toEmitValuesWith(() => {
|
await expect(runSplitQuery(datasource, request)).toEmitValuesWith(() => {
|
||||||
// A, B
|
// A, B
|
||||||
expect(datasource.runQuery).toHaveBeenCalledTimes(2);
|
expect(datasource.runQuery).toHaveBeenCalledTimes(2);
|
||||||
@ -529,21 +504,21 @@ describe('runSplitQuery()', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Groups metric queries with step by stepMs', async () => {
|
test('Groups metric queries with step by stepMs', async () => {
|
||||||
const request = getQueryOptions<LokiQuery>({
|
const request = createRequest(
|
||||||
targets: [
|
[
|
||||||
{ expr: 'count_over_time({a="b"}[1m])', refId: 'A', resolution: 1, step: '10' },
|
{ expr: 'count_over_time({a="b"}[1m])', refId: 'A', resolution: 1, step: '10' },
|
||||||
{ expr: 'count_over_time{a="b"}[1m])', refId: 'B', resolution: 1, step: '5ms' },
|
{ expr: 'count_over_time{a="b"}[1m])', refId: 'B', resolution: 1, step: '5ms' },
|
||||||
],
|
],
|
||||||
range: range1d,
|
{ range: range1d }
|
||||||
});
|
);
|
||||||
await expect(runSplitQuery(datasource, request)).toEmitValuesWith(() => {
|
await expect(runSplitQuery(datasource, request)).toEmitValuesWith(() => {
|
||||||
// A, B
|
// A, B
|
||||||
expect(datasource.runQuery).toHaveBeenCalledTimes(2);
|
expect(datasource.runQuery).toHaveBeenCalledTimes(2);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
test('Groups mixed queries by stepMs', async () => {
|
test('Groups mixed queries by stepMs', async () => {
|
||||||
const request = getQueryOptions<LokiQuery>({
|
const request = createRequest(
|
||||||
targets: [
|
[
|
||||||
{ expr: '{a="b"}', refId: 'A', resolution: 3 },
|
{ expr: '{a="b"}', refId: 'A', resolution: 3 },
|
||||||
{ expr: '{a="b"}', refId: 'B', resolution: 5 },
|
{ expr: '{a="b"}', refId: 'B', resolution: 5 },
|
||||||
{ expr: 'count_over_time({a="b"}[1m])', refId: 'C', resolution: 3 },
|
{ expr: 'count_over_time({a="b"}[1m])', refId: 'C', resolution: 3 },
|
||||||
@ -552,26 +527,23 @@ describe('runSplitQuery()', () => {
|
|||||||
{ expr: 'rate({a="b"}[5m])', refId: 'F', resolution: 5, step: '10' },
|
{ expr: 'rate({a="b"}[5m])', refId: 'F', resolution: 5, step: '10' },
|
||||||
{ expr: 'rate({a="b"} | logfmt[5m])', refId: 'G', resolution: 5, step: '10s' },
|
{ expr: 'rate({a="b"} | logfmt[5m])', refId: 'G', resolution: 5, step: '10s' },
|
||||||
],
|
],
|
||||||
range: range1d,
|
{ range: range1d }
|
||||||
});
|
);
|
||||||
await expect(runSplitQuery(datasource, request)).toEmitValuesWith(() => {
|
await expect(runSplitQuery(datasource, request)).toEmitValuesWith(() => {
|
||||||
// A, B, C, D, E, F+G
|
// A, B, C, D, E, F+G
|
||||||
expect(datasource.runQuery).toHaveBeenCalledTimes(6);
|
expect(datasource.runQuery).toHaveBeenCalledTimes(6);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
test('Chunked groups mixed queries by stepMs', async () => {
|
test('Chunked groups mixed queries by stepMs', async () => {
|
||||||
const request = getQueryOptions<LokiQuery>({
|
const request = createRequest([
|
||||||
targets: [
|
{ expr: '{a="b"}', refId: 'A', resolution: 3 },
|
||||||
{ expr: '{a="b"}', refId: 'A', resolution: 3 },
|
{ expr: '{a="b"}', refId: 'B', resolution: 5 },
|
||||||
{ expr: '{a="b"}', refId: 'B', resolution: 5 },
|
{ expr: 'count_over_time({a="b"}[1m])', refId: 'C', resolution: 3 },
|
||||||
{ expr: 'count_over_time({a="b"}[1m])', refId: 'C', resolution: 3 },
|
{ expr: 'count_over_time{a="b"}[1m])', refId: 'D', resolution: 5 },
|
||||||
{ expr: 'count_over_time{a="b"}[1m])', refId: 'D', resolution: 5 },
|
{ expr: '{a="b"}', refId: 'E', resolution: 5, queryType: LokiQueryType.Instant },
|
||||||
{ expr: '{a="b"}', refId: 'E', resolution: 5, queryType: LokiQueryType.Instant },
|
{ expr: 'rate({a="b"}[5m])', refId: 'F', resolution: 5, step: '10' },
|
||||||
{ expr: 'rate({a="b"}[5m])', refId: 'F', resolution: 5, step: '10' },
|
{ expr: 'rate({a="b"} | logfmt[5m])', refId: 'G', resolution: 5, step: '10s' },
|
||||||
{ expr: 'rate({a="b"} | logfmt[5m])', refId: 'G', resolution: 5, step: '10s' },
|
]);
|
||||||
],
|
|
||||||
range, // 3 days
|
|
||||||
});
|
|
||||||
await expect(runSplitQuery(datasource, request)).toEmitValuesWith(() => {
|
await expect(runSplitQuery(datasource, request)).toEmitValuesWith(() => {
|
||||||
// 3 * A, 3 * B, 3 * C, 3 * D, 1 * E, 3 * F+G
|
// 3 * A, 3 * B, 3 * C, 3 * D, 1 * E, 3 * F+G
|
||||||
expect(datasource.runQuery).toHaveBeenCalledTimes(16);
|
expect(datasource.runQuery).toHaveBeenCalledTimes(16);
|
||||||
|
@ -28,7 +28,7 @@ export function makeError(expr: string, node: SyntaxNode) {
|
|||||||
* \[\[([\s\S]+?)(?::(\w+))?\]\] [[var2]] or [[var2:fmt2]]
|
* \[\[([\s\S]+?)(?::(\w+))?\]\] [[var2]] or [[var2:fmt2]]
|
||||||
* \${(\w+)(?::(\w+))?} ${var3} or ${var3:fmt3}
|
* \${(\w+)(?::(\w+))?} ${var3} or ${var3:fmt3}
|
||||||
*/
|
*/
|
||||||
const variableRegex = /\$(\w+)|\[\[([\s\S]+?)(?::(\w+))?\]\]|\${(\w+)(?:\.([^:^\}]+))?(?::([^\}]+))?}/g;
|
export const variableRegex = /\$(\w+)|\[\[([\s\S]+?)(?::(\w+))?\]\]|\${(\w+)(?:\.([^:^\}]+))?(?::([^\}]+))?}/g;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* As variables with $ are creating parsing errors, we first replace them with magic string that is parsable and at
|
* As variables with $ are creating parsing errors, we first replace them with magic string that is parsable and at
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
import { getQueryOptions } from 'test/helpers/getQueryOptions';
|
import { DashboardLoadedEvent, DataQueryRequest, dateTime } from '@grafana/data';
|
||||||
|
|
||||||
import { DashboardLoadedEvent, dateTime } from '@grafana/data';
|
|
||||||
import { reportInteraction } from '@grafana/runtime';
|
import { reportInteraction } from '@grafana/runtime';
|
||||||
|
|
||||||
import { QueryEditorMode } from '../prometheus/querybuilder/shared/types';
|
import { QueryEditorMode } from '../prometheus/querybuilder/shared/types';
|
||||||
@ -27,7 +25,7 @@ const range = {
|
|||||||
to: dateTime('2023-02-10T06:00:00.000Z'),
|
to: dateTime('2023-02-10T06:00:00.000Z'),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const originalRequest = getQueryOptions<LokiQuery>({
|
const originalRequest = {
|
||||||
targets: [
|
targets: [
|
||||||
{ expr: 'count_over_time({a="b"}[1m])', refId: 'A', ...baseTarget },
|
{ expr: 'count_over_time({a="b"}[1m])', refId: 'A', ...baseTarget },
|
||||||
{ expr: '{a="b"}', refId: 'B', maxLines: 10, ...baseTarget },
|
{ expr: '{a="b"}', refId: 'B', maxLines: 10, ...baseTarget },
|
||||||
@ -35,26 +33,23 @@ const originalRequest = getQueryOptions<LokiQuery>({
|
|||||||
],
|
],
|
||||||
range,
|
range,
|
||||||
app: 'explore',
|
app: 'explore',
|
||||||
});
|
} as DataQueryRequest<LokiQuery>;
|
||||||
|
|
||||||
const requests: LokiGroupedRequest[] = [
|
const requests: LokiGroupedRequest[] = [
|
||||||
{
|
{
|
||||||
request: {
|
request: {
|
||||||
...getQueryOptions<LokiQuery>({
|
targets: [{ expr: 'count_over_time({a="b"}[1m])', refId: 'A', ...baseTarget }],
|
||||||
targets: [{ expr: 'count_over_time({a="b"}[1m])', refId: 'A', ...baseTarget }],
|
range,
|
||||||
range,
|
|
||||||
}),
|
|
||||||
app: 'explore',
|
app: 'explore',
|
||||||
},
|
} as DataQueryRequest<LokiQuery>,
|
||||||
partition: partitionTimeRange(true, range, 60000, 24 * 60 * 60 * 1000),
|
partition: partitionTimeRange(true, range, 60000, 24 * 60 * 60 * 1000),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
request: {
|
request: {
|
||||||
...getQueryOptions<LokiQuery>({
|
targets: [{ expr: '{a="b"}', refId: 'B', maxLines: 10, ...baseTarget }],
|
||||||
targets: [{ expr: '{a="b"}', refId: 'B', maxLines: 10, ...baseTarget }],
|
range,
|
||||||
range,
|
|
||||||
}),
|
|
||||||
app: 'explore',
|
app: 'explore',
|
||||||
},
|
} as DataQueryRequest<LokiQuery>,
|
||||||
partition: partitionTimeRange(false, range, 60000, 24 * 60 * 60 * 1000),
|
partition: partitionTimeRange(false, range, 60000, 24 * 60 * 60 * 1000),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import { CoreApp, DashboardLoadedEvent, DataQueryRequest, DataQueryResponse } from '@grafana/data';
|
import { CoreApp, DashboardLoadedEvent, DataQueryRequest, DataQueryResponse } from '@grafana/data';
|
||||||
import { reportInteraction, config } from '@grafana/runtime';
|
import { reportInteraction, config } from '@grafana/runtime';
|
||||||
import { variableRegex } from 'app/features/variables/utils';
|
|
||||||
|
|
||||||
import { QueryEditorMode } from '../prometheus/querybuilder/shared/types';
|
import { QueryEditorMode } from '../prometheus/querybuilder/shared/types';
|
||||||
|
|
||||||
@ -12,6 +11,7 @@ import {
|
|||||||
} from './datasource';
|
} from './datasource';
|
||||||
import pluginJson from './plugin.json';
|
import pluginJson from './plugin.json';
|
||||||
import { getNormalizedLokiQuery, isLogsQuery, obfuscate, parseToNodeNamesArray } from './queryUtils';
|
import { getNormalizedLokiQuery, isLogsQuery, obfuscate, parseToNodeNamesArray } from './queryUtils';
|
||||||
|
import { variableRegex } from './querybuilder/parsingUtils';
|
||||||
import { LokiGroupedRequest, LokiQuery, LokiQueryType } from './types';
|
import { LokiGroupedRequest, LokiQuery, LokiQueryType } from './types';
|
||||||
|
|
||||||
type LokiOnDashboardLoadedTrackingEvent = {
|
type LokiOnDashboardLoadedTrackingEvent = {
|
||||||
|
Loading…
Reference in New Issue
Block a user