Cloudwatch: Fix log group variable interpolation (#62640)
This commit is contained in:
@@ -1,4 +1,9 @@
|
|||||||
import { dimensionVariable, labelsVariable, setupMockedDataSource } from './__mocks__/CloudWatchDataSource';
|
import {
|
||||||
|
dimensionVariable,
|
||||||
|
fieldsVariable,
|
||||||
|
labelsVariable,
|
||||||
|
setupMockedDataSource,
|
||||||
|
} from './__mocks__/CloudWatchDataSource';
|
||||||
import { setupMockedResourcesAPI } from './__mocks__/ResourcesAPI';
|
import { setupMockedResourcesAPI } from './__mocks__/ResourcesAPI';
|
||||||
import { VariableQuery, VariableQueryType } from './types';
|
import { VariableQuery, VariableQueryType } from './types';
|
||||||
import { CloudWatchVariableSupport } from './variables';
|
import { CloudWatchVariableSupport } from './variables';
|
||||||
@@ -15,19 +20,19 @@ const defaultQuery: VariableQuery = {
|
|||||||
refId: '',
|
refId: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
const mock = setupMockedDataSource({ variables: [labelsVariable, dimensionVariable] });
|
const mock = setupMockedDataSource({ variables: [labelsVariable, dimensionVariable, fieldsVariable] });
|
||||||
mock.datasource.resources.getRegions = jest.fn().mockResolvedValue([{ label: 'a', value: 'a' }]);
|
mock.datasource.resources.getRegions = jest.fn().mockResolvedValue([{ label: 'a', value: 'a' }]);
|
||||||
mock.datasource.resources.getNamespaces = jest.fn().mockResolvedValue([{ label: 'b', value: 'b' }]);
|
mock.datasource.resources.getNamespaces = jest.fn().mockResolvedValue([{ label: 'b', value: 'b' }]);
|
||||||
mock.datasource.resources.getMetrics = jest.fn().mockResolvedValue([{ label: 'c', value: 'c' }]);
|
mock.datasource.resources.getMetrics = jest.fn().mockResolvedValue([{ label: 'c', value: 'c' }]);
|
||||||
mock.datasource.resources.getDimensionKeys = jest.fn().mockResolvedValue([{ label: 'd', value: 'd' }]);
|
mock.datasource.resources.getDimensionKeys = jest.fn().mockResolvedValue([{ label: 'd', value: 'd' }]);
|
||||||
mock.datasource.resources.getLogGroups = jest
|
|
||||||
.fn()
|
|
||||||
.mockResolvedValue([{ value: { arn: 'a', name: 'a' } }, { value: { arn: 'b', name: 'b' } }]);
|
|
||||||
mock.datasource.resources.getAccounts = jest.fn().mockResolvedValue([]);
|
mock.datasource.resources.getAccounts = jest.fn().mockResolvedValue([]);
|
||||||
const getDimensionValues = jest.fn().mockResolvedValue([{ label: 'e', value: 'e' }]);
|
const getDimensionValues = jest.fn().mockResolvedValue([{ label: 'e', value: 'e' }]);
|
||||||
const getEbsVolumeIds = jest.fn().mockResolvedValue([{ label: 'f', value: 'f' }]);
|
const getEbsVolumeIds = jest.fn().mockResolvedValue([{ label: 'f', value: 'f' }]);
|
||||||
const getEc2InstanceAttribute = jest.fn().mockResolvedValue([{ label: 'g', value: 'g' }]);
|
const getEc2InstanceAttribute = jest.fn().mockResolvedValue([{ label: 'g', value: 'g' }]);
|
||||||
const getResourceARNs = jest.fn().mockResolvedValue([{ label: 'h', value: 'h' }]);
|
const getResourceARNs = jest.fn().mockResolvedValue([{ label: 'h', value: 'h' }]);
|
||||||
|
const getLogGroups = jest
|
||||||
|
.fn()
|
||||||
|
.mockResolvedValue([{ value: { arn: 'a', name: 'a' } }, { value: { arn: 'b', name: 'b' } }]);
|
||||||
|
|
||||||
const variables = new CloudWatchVariableSupport(mock.datasource.resources);
|
const variables = new CloudWatchVariableSupport(mock.datasource.resources);
|
||||||
|
|
||||||
@@ -196,6 +201,11 @@ describe('variables', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('log groups', () => {
|
describe('log groups', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
mock.datasource.resources.getLogGroups = getLogGroups;
|
||||||
|
getLogGroups.mockClear();
|
||||||
|
});
|
||||||
|
|
||||||
it('should call describe log groups', async () => {
|
it('should call describe log groups', async () => {
|
||||||
const result = await variables.execute({ ...defaultQuery, queryType: VariableQueryType.LogGroups });
|
const result = await variables.execute({ ...defaultQuery, queryType: VariableQueryType.LogGroups });
|
||||||
expect(result).toEqual([
|
expect(result).toEqual([
|
||||||
@@ -203,5 +213,18 @@ describe('variables', () => {
|
|||||||
{ text: 'b', value: 'b', expandable: true },
|
{ text: 'b', value: 'b', expandable: true },
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
it('should replace variables', async () => {
|
||||||
|
const query = {
|
||||||
|
...defaultQuery,
|
||||||
|
queryType: VariableQueryType.LogGroups,
|
||||||
|
logGroupPrefix: '$fields',
|
||||||
|
};
|
||||||
|
await variables.execute(query);
|
||||||
|
expect(getLogGroups).toBeCalledWith({
|
||||||
|
region: query.region,
|
||||||
|
logGroupNamePrefix: 'templatedField',
|
||||||
|
listAllLogGroups: true,
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -63,10 +63,11 @@ export class CloudWatchVariableSupport extends CustomVariableSupport<CloudWatchD
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
async handleLogGroupsQuery({ region, logGroupPrefix }: VariableQuery) {
|
async handleLogGroupsQuery({ region, logGroupPrefix }: VariableQuery) {
|
||||||
|
const interpolatedPrefix = this.resources.templateSrv.replace(logGroupPrefix);
|
||||||
return this.resources
|
return this.resources
|
||||||
.getLogGroups({
|
.getLogGroups({
|
||||||
region,
|
region,
|
||||||
logGroupNamePrefix: logGroupPrefix,
|
logGroupNamePrefix: interpolatedPrefix,
|
||||||
listAllLogGroups: true,
|
listAllLogGroups: true,
|
||||||
})
|
})
|
||||||
.then((logGroups) =>
|
.then((logGroups) =>
|
||||||
|
|||||||
Reference in New Issue
Block a user