CloudWatch: List all metrics properly in SQL autocomplete (#45898)

* make sure right value is passed for metric

* add unit test
This commit is contained in:
Erik Sundell 2022-03-02 10:46:17 +01:00 committed by GitHub
parent 647c5208d7
commit 8e08128f83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View File

@ -249,6 +249,26 @@ describe('datasource', () => {
});
});
});
describe('resource requests', () => {
it('should map resource response to metric response', async () => {
const datasource = setupMockedDataSource().datasource;
datasource.doMetricResourceRequest = jest.fn().mockResolvedValue([
{
text: 'AWS/EC2',
value: 'CPUUtilization',
},
{
text: 'AWS/Redshift',
value: 'CPUPercentage',
},
]);
const allMetrics = await datasource.getAllMetrics('us-east-2');
expect(allMetrics[0].metricName).toEqual('CPUUtilization');
expect(allMetrics[0].namespace).toEqual('AWS/EC2');
expect(allMetrics[1].metricName).toEqual('CPUPercentage');
expect(allMetrics[1].namespace).toEqual('AWS/Redshift');
});
});
describe('performTimeSeriesQuery', () => {
it('should return the same length of data as result', async () => {

View File

@ -670,7 +670,7 @@ export class CloudWatchDatasource
region: this.templateSrv.replace(this.getActualRegion(region)),
});
return values.map((v) => ({ metricName: v.label, namespace: v.text }));
return values.map((v) => ({ metricName: v.value, namespace: v.text }));
}
async getDimensionKeys(