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

This commit is contained in:
Isabella Siu 2023-12-01 14:37:09 -05:00 committed by GitHub
parent af05fdc806
commit d894f4cc79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -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', () => {

View File

@ -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}"`;
}