|
|
@ -2,11 +2,11 @@ import { of } from 'rxjs'; |
|
|
|
|
|
|
|
|
|
|
|
import { CustomVariableModel, DataFrame, DataSourceInstanceSettings } from '@grafana/data'; |
|
|
|
import { CustomVariableModel, DataFrame, DataSourceInstanceSettings } from '@grafana/data'; |
|
|
|
import { BackendDataSourceResponse, getBackendSrv, setBackendSrv } from '@grafana/runtime'; |
|
|
|
import { BackendDataSourceResponse, getBackendSrv, setBackendSrv } from '@grafana/runtime'; |
|
|
|
import { getTimeSrv } from 'app/features/dashboard/services/TimeSrv'; |
|
|
|
import { getTimeSrv, TimeSrv } from 'app/features/dashboard/services/TimeSrv'; |
|
|
|
import { TemplateSrv } from 'app/features/templating/template_srv'; |
|
|
|
import { TemplateSrv } from 'app/features/templating/template_srv'; |
|
|
|
|
|
|
|
|
|
|
|
import { CloudWatchLogsQueryRunner } from '../query-runner/CloudWatchLogsQueryRunner'; |
|
|
|
import { CloudWatchLogsQueryRunner } from '../query-runner/CloudWatchLogsQueryRunner'; |
|
|
|
import { CloudWatchJsonData, CloudWatchLogsQueryStatus } from '../types'; |
|
|
|
import { CloudWatchJsonData, CloudWatchLogsQueryStatus, CloudWatchLogsRequest } from '../types'; |
|
|
|
|
|
|
|
|
|
|
|
import { CloudWatchSettings, setupMockedTemplateService } from './CloudWatchDataSource'; |
|
|
|
import { CloudWatchSettings, setupMockedTemplateService } from './CloudWatchDataSource'; |
|
|
|
|
|
|
|
|
|
|
@ -17,11 +17,13 @@ export function setupMockedLogsQueryRunner({ |
|
|
|
variables, |
|
|
|
variables, |
|
|
|
mockGetVariableName = true, |
|
|
|
mockGetVariableName = true, |
|
|
|
settings = CloudWatchSettings, |
|
|
|
settings = CloudWatchSettings, |
|
|
|
|
|
|
|
timeSrv = getTimeSrv(), |
|
|
|
}: { |
|
|
|
}: { |
|
|
|
data?: BackendDataSourceResponse; |
|
|
|
data?: BackendDataSourceResponse; |
|
|
|
variables?: CustomVariableModel[]; |
|
|
|
variables?: CustomVariableModel[]; |
|
|
|
mockGetVariableName?: boolean; |
|
|
|
mockGetVariableName?: boolean; |
|
|
|
settings?: DataSourceInstanceSettings<CloudWatchJsonData>; |
|
|
|
settings?: DataSourceInstanceSettings<CloudWatchJsonData>; |
|
|
|
|
|
|
|
timeSrv?: TimeSrv; |
|
|
|
} = {}) { |
|
|
|
} = {}) { |
|
|
|
let templateService = new TemplateSrv(); |
|
|
|
let templateService = new TemplateSrv(); |
|
|
|
if (variables) { |
|
|
|
if (variables) { |
|
|
@ -31,7 +33,7 @@ export function setupMockedLogsQueryRunner({ |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const runner = new CloudWatchLogsQueryRunner(settings, templateService, getTimeSrv()); |
|
|
|
const runner = new CloudWatchLogsQueryRunner(settings, templateService, timeSrv); |
|
|
|
const fetchMock = jest.fn().mockReturnValue(of({ data })); |
|
|
|
const fetchMock = jest.fn().mockReturnValue(of({ data })); |
|
|
|
setBackendSrv({ |
|
|
|
setBackendSrv({ |
|
|
|
...getBackendSrv(), |
|
|
|
...getBackendSrv(), |
|
|
@ -66,3 +68,19 @@ export function genMockFrames(numResponses: number): DataFrame[] { |
|
|
|
|
|
|
|
|
|
|
|
return mockFrames; |
|
|
|
return mockFrames; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function genMockCloudWatchLogsRequest(overrides: Partial<CloudWatchLogsRequest> = {}) { |
|
|
|
|
|
|
|
const request: CloudWatchLogsRequest = { |
|
|
|
|
|
|
|
queryString: 'fields @timestamp, @message | sort @timestamp desc', |
|
|
|
|
|
|
|
logGroupNames: ['log-group-name-1', 'log-group-name-2'], |
|
|
|
|
|
|
|
logGroups: [ |
|
|
|
|
|
|
|
{ arn: 'log-group-arn-1', name: 'log-group-name-1' }, |
|
|
|
|
|
|
|
{ arn: 'log-group-arn-2', name: 'log-group-name-2' }, |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
refId: 'A', |
|
|
|
|
|
|
|
region: 'us-east-1', |
|
|
|
|
|
|
|
...overrides, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return request; |
|
|
|
|
|
|
|
} |
|
|
|