From 757fa06b85f8e1e9d416134e383fc15d7d521fa7 Mon Sep 17 00:00:00 2001 From: ismail simsek Date: Wed, 28 Feb 2024 15:59:06 +0100 Subject: [PATCH] InfluxDB: Fix interpolation of multi value template variables by adding parenthesis around them (#83577) Put parenthesis around multi value template variable --- public/app/plugins/datasource/influxdb/datasource.test.ts | 6 +++--- public/app/plugins/datasource/influxdb/datasource.ts | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/public/app/plugins/datasource/influxdb/datasource.test.ts b/public/app/plugins/datasource/influxdb/datasource.test.ts index 5e20d38370a..01f1ab2f7e6 100644 --- a/public/app/plugins/datasource/influxdb/datasource.test.ts +++ b/public/app/plugins/datasource/influxdb/datasource.test.ts @@ -452,7 +452,7 @@ describe('InfluxDataSource Frontend Mode', () => { .withIncludeAll(true) .build(); const result = ds.interpolateQueryExpr(value, variableMock, 'select from /^($tempVar)$/'); - const expectation = `env|env2|env3`; + const expectation = `(env|env2|env3)`; expect(result).toBe(expectation); }); @@ -476,7 +476,7 @@ describe('InfluxDataSource Frontend Mode', () => { const value = [`/special/path`, `/some/other/path`]; const variableMock = queryBuilder().withId('tempVar').withName('tempVar').withMulti().build(); const result = ds.interpolateQueryExpr(value, variableMock, `select that where path = '$tempVar'`); - const expectation = `\\/special\\/path|\\/some\\/other\\/path`; + const expectation = `(\\/special\\/path|\\/some\\/other\\/path)`; expect(result).toBe(expectation); }); @@ -505,7 +505,7 @@ describe('InfluxDataSource Frontend Mode', () => { .build(); const value = [`/special/path`, `/some/other/path`]; const result = ds.interpolateQueryExpr(value, variableMock, `select that where path = /$tempVar/`); - const expectation = `\\/special\\/path|\\/some\\/other\\/path`; + const expectation = `(\\/special\\/path|\\/some\\/other\\/path)`; expect(result).toBe(expectation); }); }); diff --git a/public/app/plugins/datasource/influxdb/datasource.ts b/public/app/plugins/datasource/influxdb/datasource.ts index b3837a09871..d5be06528aa 100644 --- a/public/app/plugins/datasource/influxdb/datasource.ts +++ b/public/app/plugins/datasource/influxdb/datasource.ts @@ -309,7 +309,8 @@ export default class InfluxDatasource extends DataSourceWithBackend escapeRegex(v)).join('|'); + // then put inside parenthesis. + return `(${value.map((v) => escapeRegex(v)).join('|')})`; } // If the variable is not a multi-value variable @@ -324,7 +325,8 @@ export default class InfluxDatasource extends DataSourceWithBackend escapeRegex(v)).join('|'); + // then put inside parenthesis. + return `(${value.map((v) => escapeRegex(v)).join('|')})`; } return value;