Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CloudWatch: Region template query fix #20661

Merged
merged 2 commits into from
Nov 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions public/app/plugins/datasource/cloudwatch/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,8 @@ export default class CloudWatchDatasource extends DataSourceApi<CloudWatchQuery,
return this.doMetricQueryRequest('namespaces', null);
}

async getMetrics(namespace: string, region: string) {
if (!namespace || !region) {
async getMetrics(namespace: string, region?: string) {
if (!namespace) {
return [];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,39 @@ describe('CloudWatchDatasource', () => {
});
});
});

describe('when regions query is used', () => {
beforeEach(() => {
ctx.backendSrv.datasourceRequest = jest.fn(() => {
return Promise.resolve({});
});
ctx.ds = new CloudWatchDatasource(instanceSettings, {} as any, backendSrv, templateSrv, timeSrv);
ctx.ds.doMetricQueryRequest = jest.fn(() => []);
});
describe('and region param is left out', () => {
it('should use the default region', done => {
ctx.ds.metricFindQuery('metrics(testNamespace)').then(() => {
expect(ctx.ds.doMetricQueryRequest).toHaveBeenCalledWith('metrics', {
namespace: 'testNamespace',
region: instanceSettings.jsonData.defaultRegion,
});
done();
});
});
});

describe('and region param is defined by user', () => {
it('should use the user defined region', done => {
ctx.ds.metricFindQuery('metrics(testNamespace2, custom-region)').then(() => {
expect(ctx.ds.doMetricQueryRequest).toHaveBeenCalledWith('metrics', {
namespace: 'testNamespace2',
region: 'custom-region',
});
done();
});
});
});
});
});

describe('When query region is "default"', () => {
Expand Down