CloudWatch: Interpolate region in log context query (#94930)

CloudWatch: interpolate region in log context query
This commit is contained in:
Isabella Siu 2024-10-18 11:31:05 -04:00 committed by GitHub
parent 053a806ab1
commit fd5f351a6f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 6 deletions

View File

@ -9,6 +9,7 @@ import {
MutableDataFrame,
} from '@grafana/data';
import { regionVariable } from '../__mocks__/CloudWatchDataSource';
import { setupMockedLogsQueryRunner } from '../__mocks__/LogsQueryRunner';
import { LogsRequestMock } from '../__mocks__/Request';
import { validLogsQuery } from '../__mocks__/queries';
@ -23,7 +24,7 @@ describe('CloudWatchLogsQueryRunner', () => {
describe('getLogRowContext', () => {
it('replaces parameters correctly in the query', async () => {
const { runner, queryMock } = setupMockedLogsQueryRunner();
const { runner, queryMock } = setupMockedLogsQueryRunner({ variables: [regionVariable] });
const row: LogRowModel = {
entryFieldIndex: 0,
rowIndex: 0,
@ -50,14 +51,15 @@ describe('CloudWatchLogsQueryRunner', () => {
};
await runner.getLogRowContext(row, undefined, queryMock);
expect(queryMock.mock.calls[0][0].targets[0].endTime).toBe(4);
expect(queryMock.mock.calls[0][0].targets[0].region).toBe('');
// sets the default region if region is empty
expect(queryMock.mock.calls[0][0].targets[0].region).toBe('us-west-1');
await runner.getLogRowContext(row, { direction: LogRowContextQueryDirection.Forward }, queryMock, {
...validLogsQuery,
region: 'eu-east',
region: '$region',
});
expect(queryMock.mock.calls[1][0].targets[0].startTime).toBe(4);
expect(queryMock.mock.calls[1][0].targets[0].region).toBe('eu-east');
expect(queryMock.mock.calls[1][0].targets[0].region).toBe('templatedRegion');
});
});

View File

@ -180,7 +180,7 @@ export class CloudWatchLogsQueryRunner extends CloudWatchRequest {
refId: query?.refId || 'A', // dummy
limit,
startFromHead: direction !== LogRowContextQueryDirection.Backward,
region: query?.region || '',
region: this.templateSrv.replace(this.getActualRegion(query?.region)),
logGroupName: parseLogGroupName(logField!.values[row.rowIndex]),
logStreamName: logStreamField!.values[row.rowIndex],
};
@ -252,7 +252,7 @@ export class CloudWatchLogsQueryRunner extends CloudWatchRequest {
this.logQueries[param.refId] = {
id: param.queryId,
region: param.region,
statsQuery: (param.statsGroups?.length ?? 0) > 0 ?? false,
statsQuery: (param.statsGroups?.length ?? 0) > 0,
};
});