CloudWatch: Correctly quote metric names with special characters (#78958)

pull/78976/head
Isabella Siu 1 year ago committed by GitHub
parent af05fdc806
commit d894f4cc79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      public/app/plugins/datasource/cloudwatch/language/cloudwatch-sql/SQLGenerator.test.ts
  2. 5
      public/app/plugins/datasource/cloudwatch/language/cloudwatch-sql/SQLGenerator.ts

@ -62,6 +62,13 @@ describe('SQLGenerator', () => {
`SELECT COUNT("Bytes-Per-Second") FROM SCHEMA("AWS/EC2")`
);
});
it('should wrap in double quotes if metric name starts with a number ', () => {
const select = createFunctionWithParameter('COUNT', ['4xxErrorRate']);
expect(new SQLGenerator().expressionToSqlQuery({ ...baseQuery, select })).toEqual(
`SELECT COUNT("4xxErrorRate") FROM SCHEMA("AWS/EC2")`
);
});
});
describe('from', () => {

@ -146,10 +146,11 @@ export default class SQLGenerator {
}
private formatValue(label: string): string {
const specialCharacters = /[/\s\.-]/; // slash, space, dot or dash
const specialCharacters = /[/\s\.%-]/; // slash, space, dot, percent, or dash
const startsWithNumber = /^\d/;
const interpolated = this.templateSrv.replace(label, {}, 'raw');
if (specialCharacters.test(interpolated)) {
if (specialCharacters.test(interpolated) || startsWithNumber.test(interpolated)) {
return `"${label}"`;
}

Loading…
Cancel
Save