mirror of
https://github.com/grafana/grafana.git
synced 2024-11-28 11:44:26 -06:00
CloudWatch: Return with error message for empty logs query string (#59584)
This commit is contained in:
parent
8152b0e1ef
commit
ada0c771ef
@ -6,8 +6,8 @@ import { dateTime, Field } from '@grafana/data';
|
||||
import {
|
||||
fieldsVariable,
|
||||
logGroupNamesVariable,
|
||||
setupMockedDataSource,
|
||||
regionVariable,
|
||||
setupMockedDataSource,
|
||||
} from './__mocks__/CloudWatchDataSource';
|
||||
import { setupForLogs } from './__mocks__/logsTestContext';
|
||||
import { validLogsQuery, validMetricSearchBuilderQuery } from './__mocks__/queries';
|
||||
@ -165,6 +165,7 @@ describe('datasource', () => {
|
||||
region: '',
|
||||
queryMode: 'Logs',
|
||||
logGroupNames: ['test'],
|
||||
expression: 'some query',
|
||||
refId: 'a',
|
||||
},
|
||||
],
|
||||
@ -195,7 +196,7 @@ describe('datasource', () => {
|
||||
expect(emits[0].data[0].fields.find((f: Field) => f.name === '@message').config.links).toMatchObject([
|
||||
{
|
||||
title: 'View in CloudWatch console',
|
||||
url: "https://us-west-1.console.aws.amazon.com/cloudwatch/home?region=us-west-1#logs-insights:queryDetail=~(end~'2020-12-31T19*3a00*3a00.000Z~start~'2020-12-31T19*3a00*3a00.000Z~timeType~'ABSOLUTE~tz~'UTC~editorString~'~isLiveTail~false~source~(~'test))",
|
||||
url: "https://us-west-1.console.aws.amazon.com/cloudwatch/home?region=us-west-1#logs-insights:queryDetail=~(end~'2020-12-31T19*3a00*3a00.000Z~start~'2020-12-31T19*3a00*3a00.000Z~timeType~'ABSOLUTE~tz~'UTC~editorString~'some*20query~isLiveTail~false~source~(~'test))",
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
@ -1,10 +1,18 @@
|
||||
import { interval, lastValueFrom, of } from 'rxjs';
|
||||
|
||||
import { LogRowModel, MutableDataFrame, FieldType, LogLevel, dataFrameToJSON, DataQueryErrorType } from '@grafana/data';
|
||||
import {
|
||||
dataFrameToJSON,
|
||||
DataQueryErrorType,
|
||||
DataQueryRequest,
|
||||
FieldType,
|
||||
LogLevel,
|
||||
LogRowModel,
|
||||
MutableDataFrame,
|
||||
} from '@grafana/data';
|
||||
|
||||
import { genMockFrames, setupMockedLogsQueryRunner } from '../__mocks__/LogsQueryRunner';
|
||||
import { validLogsQuery } from '../__mocks__/queries';
|
||||
import { LogAction } from '../types';
|
||||
import { CloudWatchQuery, LogAction } from '../types';
|
||||
import * as rxjsUtils from '../utils/rxjs/increasingInterval';
|
||||
|
||||
import { LOG_IDENTIFIER_INTERNAL, LOGSTREAM_IDENTIFIER_INTERNAL } from './CloudWatchLogsQueryRunner';
|
||||
@ -213,4 +221,32 @@ describe('CloudWatchLogsQueryRunner', () => {
|
||||
expect(i).toBe(3);
|
||||
});
|
||||
});
|
||||
|
||||
describe('handleLogQueries', () => {
|
||||
it('should return error message when missing query string', async () => {
|
||||
const { runner } = setupMockedLogsQueryRunner();
|
||||
const response = await lastValueFrom(
|
||||
runner.handleLogQueries(
|
||||
[
|
||||
{
|
||||
datasource: { type: 'cloudwatch', uid: 'Zne6OZIVk' },
|
||||
id: '',
|
||||
logGroups: [{ label: '', text: '', value: '' }],
|
||||
queryMode: 'Logs',
|
||||
refId: 'A',
|
||||
region: 'default',
|
||||
},
|
||||
],
|
||||
{ scopedVars: {} } as DataQueryRequest<CloudWatchQuery>
|
||||
)
|
||||
);
|
||||
|
||||
expect(response).toEqual({
|
||||
data: [],
|
||||
error: {
|
||||
message: 'Query is required',
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -1,20 +1,20 @@
|
||||
import { set } from 'lodash';
|
||||
import {
|
||||
Observable,
|
||||
of,
|
||||
mergeMap,
|
||||
map,
|
||||
from,
|
||||
catchError,
|
||||
concatMap,
|
||||
finalize,
|
||||
from,
|
||||
lastValueFrom,
|
||||
map,
|
||||
mergeMap,
|
||||
Observable,
|
||||
of,
|
||||
repeat,
|
||||
scan,
|
||||
share,
|
||||
takeWhile,
|
||||
tap,
|
||||
zip,
|
||||
catchError,
|
||||
lastValueFrom,
|
||||
} from 'rxjs';
|
||||
|
||||
import {
|
||||
@ -108,6 +108,14 @@ export class CloudWatchLogsQueryRunner extends CloudWatchRequest {
|
||||
return of({ data: [], error: { message: 'Log group is required' } });
|
||||
}
|
||||
|
||||
const hasQueryWithMissingQueryString = queryParams.some((qp) => {
|
||||
return qp.queryString.length === 0;
|
||||
});
|
||||
|
||||
if (hasQueryWithMissingQueryString) {
|
||||
return of({ data: [], error: { message: 'Query is required' } });
|
||||
}
|
||||
|
||||
const startTime = new Date();
|
||||
const timeoutFunc = () => {
|
||||
return Date.now() >= startTime.valueOf() + rangeUtil.intervalToMs(this.logsTimeout);
|
||||
|
Loading…
Reference in New Issue
Block a user