mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
CloudWatch Logs: Fix interpolation of scoped variables in queryString (#64267)
This commit is contained in:
parent
ee38bbe030
commit
af9a0dbe39
@ -24,7 +24,7 @@ export const LogsRequestMock: DataQueryRequest<CloudWatchLogsQuery> = {
|
||||
requestId: '',
|
||||
interval: '',
|
||||
intervalMs: 0,
|
||||
scopedVars: {},
|
||||
scopedVars: { __interval: { value: '20s' } },
|
||||
timezone: '',
|
||||
app: '',
|
||||
startTime: 0,
|
||||
|
@ -216,6 +216,16 @@ describe('CloudWatchLogsQueryRunner', () => {
|
||||
expression: `fields @timestamp, @message | sort @timestamp desc | limit 1`,
|
||||
};
|
||||
|
||||
const logsScopedVarQuery: CloudWatchLogsQuery = {
|
||||
queryMode: 'Logs',
|
||||
logGroups: [{ arn: logGroupNamesVariable.name, name: logGroupNamesVariable.name }],
|
||||
hide: false,
|
||||
id: '',
|
||||
region: '$' + regionVariable.name,
|
||||
refId: 'A',
|
||||
expression: `stats count(*) by queryType, bin($__interval)`,
|
||||
};
|
||||
|
||||
describe('handleLogQueries', () => {
|
||||
it('should map log queries to start query requests correctly', async () => {
|
||||
const { runner } = setupMockedLogsQueryRunner({
|
||||
@ -229,7 +239,9 @@ describe('CloudWatchLogsQueryRunner', () => {
|
||||
},
|
||||
});
|
||||
const spy = jest.spyOn(runner, 'makeLogActionRequest');
|
||||
await lastValueFrom(runner.handleLogQueries([legacyLogGroupNamesQuery, logGroupNamesQuery], LogsRequestMock));
|
||||
await lastValueFrom(
|
||||
runner.handleLogQueries([legacyLogGroupNamesQuery, logGroupNamesQuery, logsScopedVarQuery], LogsRequestMock)
|
||||
);
|
||||
const startQueryRequests: StartQueryRequest[] = [
|
||||
{
|
||||
queryString: `fields @timestamp, @message | sort @timestamp desc | limit ${limitVariable.current.value}`,
|
||||
@ -251,6 +263,13 @@ describe('CloudWatchLogsQueryRunner', () => {
|
||||
refId: legacyLogGroupNamesQuery.refId,
|
||||
region: regionVariable.current.value as string,
|
||||
},
|
||||
{
|
||||
queryString: `stats count(*) by queryType, bin(20s)`,
|
||||
logGroupNames: [],
|
||||
logGroups: [...(logGroupNamesVariable.current.value as string[]).map((v) => ({ arn: v, name: v }))],
|
||||
refId: legacyLogGroupNamesQuery.refId,
|
||||
region: regionVariable.current.value as string,
|
||||
},
|
||||
];
|
||||
expect(spy).toHaveBeenNthCalledWith(1, 'StartQuery', startQueryRequests);
|
||||
});
|
||||
|
@ -103,7 +103,7 @@ export class CloudWatchLogsQueryRunner extends CloudWatchRequest {
|
||||
return {
|
||||
refId: target.refId,
|
||||
region: this.templateSrv.replace(this.getActualRegion(target.region)),
|
||||
queryString: this.templateSrv.replace(target.expression || ''),
|
||||
queryString: this.templateSrv.replace(target.expression || '', options.scopedVars),
|
||||
logGroups,
|
||||
logGroupNames,
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user