mirror of
https://github.com/grafana/grafana.git
synced 2024-11-29 20:24:18 -06:00
CloudWatch: Interpolate region in log context query (#94930)
CloudWatch: interpolate region in log context query
This commit is contained in:
parent
053a806ab1
commit
fd5f351a6f
@ -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');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -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,
|
||||
};
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user