mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
CloudWatch: Correctly quote metric names with special characters (#78958)
This commit is contained in:
parent
af05fdc806
commit
d894f4cc79
@ -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…
Reference in New Issue
Block a user