From 6ed07873769d95b1f3ed0fe336b9be7e02648085 Mon Sep 17 00:00:00 2001 From: Galen Kistler <109082771+gtk-grafana@users.noreply.github.com> Date: Fri, 26 Aug 2022 08:26:44 -0500 Subject: [PATCH] InfluxQL: Quoting tag values in the query editor (#54187) * Quote numeric values in query editor --- public/app/plugins/datasource/influxdb/query_builder.ts | 5 +++-- .../plugins/datasource/influxdb/specs/query_builder.test.ts | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/public/app/plugins/datasource/influxdb/query_builder.ts b/public/app/plugins/datasource/influxdb/query_builder.ts index ba044d436b6..2f148799a99 100644 --- a/public/app/plugins/datasource/influxdb/query_builder.ts +++ b/public/app/plugins/datasource/influxdb/query_builder.ts @@ -19,8 +19,9 @@ function renderTagCondition(tag: { operator: any; value: string; condition: any; } } - // quote value unless regex or number, or if empty-string - if (value === '' || (operator !== '=~' && operator !== '!~' && isNaN(+value))) { + // quote value unless regex or empty-string + // Influx versions before 0.13 had inconsistent requirements on if (numeric) tags are quoted or not. + if (value === '' || (operator !== '=~' && operator !== '!~')) { value = "'" + value.replace(/\\/g, '\\\\').replace(/\'/g, "\\'") + "'"; } diff --git a/public/app/plugins/datasource/influxdb/specs/query_builder.test.ts b/public/app/plugins/datasource/influxdb/specs/query_builder.test.ts index 9c989f671b6..07be475e028 100644 --- a/public/app/plugins/datasource/influxdb/specs/query_builder.test.ts +++ b/public/app/plugins/datasource/influxdb/specs/query_builder.test.ts @@ -166,7 +166,7 @@ describe('InfluxQueryBuilder', () => { undefined ); const query = builder.buildExploreQuery('MEASUREMENTS'); - expect(query).toBe(`SHOW MEASUREMENTS WHERE "app" == 42 LIMIT 100`); + expect(query).toBe(`SHOW MEASUREMENTS WHERE "app" == '42' LIMIT 100`); }); it('should handle tag-value=number-ish getting tag-keys', () => { @@ -175,7 +175,7 @@ describe('InfluxQueryBuilder', () => { undefined ); const query = builder.buildExploreQuery('TAG_KEYS'); - expect(query).toBe(`SHOW TAG KEYS WHERE "app" == 42`); + expect(query).toBe(`SHOW TAG KEYS WHERE "app" == '42'`); }); it('should handle tag-value-contains-backslash-character getting tag-keys', () => {