|
|
|
@ -1,6 +1,15 @@ |
|
|
|
|
import { interval, lastValueFrom, of } from 'rxjs'; |
|
|
|
|
|
|
|
|
|
import { DataQueryErrorType, FieldType, LogLevel, LogRowModel, MutableDataFrame } from '@grafana/data'; |
|
|
|
|
import { |
|
|
|
|
DataQueryErrorType, |
|
|
|
|
FieldType, |
|
|
|
|
LogLevel, |
|
|
|
|
LogRowModel, |
|
|
|
|
MutableDataFrame, |
|
|
|
|
dateTime, |
|
|
|
|
DataQueryRequest, |
|
|
|
|
} from '@grafana/data'; |
|
|
|
|
import { getTimeSrv } from 'app/features/dashboard/services/TimeSrv'; |
|
|
|
|
|
|
|
|
|
import { |
|
|
|
|
CloudWatchSettings, |
|
|
|
@ -8,7 +17,7 @@ import { |
|
|
|
|
logGroupNamesVariable, |
|
|
|
|
regionVariable, |
|
|
|
|
} from '../__mocks__/CloudWatchDataSource'; |
|
|
|
|
import { genMockFrames, setupMockedLogsQueryRunner } from '../__mocks__/LogsQueryRunner'; |
|
|
|
|
import { genMockFrames, genMockCloudWatchLogsRequest, setupMockedLogsQueryRunner } from '../__mocks__/LogsQueryRunner'; |
|
|
|
|
import { LogsRequestMock } from '../__mocks__/Request'; |
|
|
|
|
import { validLogsQuery } from '../__mocks__/queries'; |
|
|
|
|
import { CloudWatchLogsQuery, LogAction, StartQueryRequest } from '../types'; |
|
|
|
@ -272,7 +281,39 @@ describe('CloudWatchLogsQueryRunner', () => { |
|
|
|
|
region: regionVariable.current.value as string, |
|
|
|
|
}, |
|
|
|
|
]; |
|
|
|
|
expect(spy).toHaveBeenNthCalledWith(1, 'StartQuery', startQueryRequests); |
|
|
|
|
expect(spy).toHaveBeenNthCalledWith(1, 'StartQuery', startQueryRequests, LogsRequestMock); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
describe('makeLogActionRequest', () => { |
|
|
|
|
it('should use the time range from the options if it is available', async () => { |
|
|
|
|
const { runner } = setupMockedLogsQueryRunner(); |
|
|
|
|
const spy = jest.spyOn(runner, 'awsRequest'); |
|
|
|
|
const from = dateTime(0); |
|
|
|
|
const to = dateTime(1000); |
|
|
|
|
const options: DataQueryRequest<CloudWatchLogsQuery> = { |
|
|
|
|
...LogsRequestMock, |
|
|
|
|
range: { from, to, raw: { from, to } }, |
|
|
|
|
}; |
|
|
|
|
await lastValueFrom(runner.makeLogActionRequest('StartQuery', [genMockCloudWatchLogsRequest()], options)); |
|
|
|
|
expect(spy).toHaveBeenNthCalledWith(1, '/api/ds/query', expect.objectContaining({ from: '0', to: '1000' }), { |
|
|
|
|
'X-Cache-Skip': 'true', |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('should use the time range from the timeSrv if the time range in the options is not available', async () => { |
|
|
|
|
const timeSrv = getTimeSrv(); |
|
|
|
|
timeSrv.timeRange = jest.fn().mockReturnValue({ |
|
|
|
|
from: dateTime(1111), |
|
|
|
|
to: dateTime(2222), |
|
|
|
|
raw: { from: dateTime(1111), to: dateTime(2222) }, |
|
|
|
|
}); |
|
|
|
|
const { runner } = setupMockedLogsQueryRunner({ timeSrv }); |
|
|
|
|
const spy = jest.spyOn(runner, 'awsRequest'); |
|
|
|
|
await lastValueFrom(runner.makeLogActionRequest('StartQuery', [genMockCloudWatchLogsRequest()])); |
|
|
|
|
expect(spy).toHaveBeenNthCalledWith(1, '/api/ds/query', expect.objectContaining({ from: '1111', to: '2222' }), { |
|
|
|
|
'X-Cache-Skip': 'true', |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|