diff --git a/.betterer.results b/.betterer.results index aff231860f1..a9418f5dcc4 100644 --- a/.betterer.results +++ b/.betterer.results @@ -5856,8 +5856,8 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "2"], [0, 0, 0, "Unexpected any. Specify a different type.", "3"], [0, 0, 0, "Unexpected any. Specify a different type.", "4"], - [0, 0, 0, "Unexpected any. Specify a different type.", "5"], - [0, 0, 0, "Do not use any type assertions.", "6"], + [0, 0, 0, "Do not use any type assertions.", "5"], + [0, 0, 0, "Unexpected any. Specify a different type.", "6"], [0, 0, 0, "Unexpected any. Specify a different type.", "7"], [0, 0, 0, "Unexpected any. Specify a different type.", "8"], [0, 0, 0, "Unexpected any. Specify a different type.", "9"], @@ -5867,13 +5867,13 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "13"], [0, 0, 0, "Unexpected any. Specify a different type.", "14"], [0, 0, 0, "Unexpected any. Specify a different type.", "15"], - [0, 0, 0, "Unexpected any. Specify a different type.", "16"], - [0, 0, 0, "Do not use any type assertions.", "17"], + [0, 0, 0, "Do not use any type assertions.", "16"], + [0, 0, 0, "Unexpected any. Specify a different type.", "17"], [0, 0, 0, "Unexpected any. Specify a different type.", "18"], [0, 0, 0, "Unexpected any. Specify a different type.", "19"], [0, 0, 0, "Unexpected any. Specify a different type.", "20"], - [0, 0, 0, "Unexpected any. Specify a different type.", "21"], - [0, 0, 0, "Do not use any type assertions.", "22"], + [0, 0, 0, "Do not use any type assertions.", "21"], + [0, 0, 0, "Unexpected any. Specify a different type.", "22"], [0, 0, 0, "Unexpected any. Specify a different type.", "23"], [0, 0, 0, "Unexpected any. Specify a different type.", "24"], [0, 0, 0, "Unexpected any. Specify a different type.", "25"], @@ -5883,8 +5883,7 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "29"], [0, 0, 0, "Unexpected any. Specify a different type.", "30"], [0, 0, 0, "Unexpected any. Specify a different type.", "31"], - [0, 0, 0, "Unexpected any. Specify a different type.", "32"], - [0, 0, 0, "Unexpected any. Specify a different type.", "33"] + [0, 0, 0, "Unexpected any. Specify a different type.", "32"] ], "public/app/plugins/datasource/influxdb/influx_query_model.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], @@ -5906,8 +5905,7 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "16"], [0, 0, 0, "Unexpected any. Specify a different type.", "17"], [0, 0, 0, "Unexpected any. Specify a different type.", "18"], - [0, 0, 0, "Unexpected any. Specify a different type.", "19"], - [0, 0, 0, "Unexpected any. Specify a different type.", "20"] + [0, 0, 0, "Unexpected any. Specify a different type.", "19"] ], "public/app/plugins/datasource/influxdb/influx_series.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], diff --git a/public/app/plugins/datasource/influxdb/components/VisualInfluxQLEditor/Editor.tags.test.tsx b/public/app/plugins/datasource/influxdb/components/VisualInfluxQLEditor/Editor.tags.test.tsx index a2f4b6a043f..f03086099b0 100644 --- a/public/app/plugins/datasource/influxdb/components/VisualInfluxQLEditor/Editor.tags.test.tsx +++ b/public/app/plugins/datasource/influxdb/components/VisualInfluxQLEditor/Editor.tags.test.tsx @@ -10,6 +10,12 @@ import { Editor } from './Editor'; jest.mock('../../influxQLMetadataQuery', () => { return { + __esModule: true, + getAllPolicies: jest.fn().mockReturnValueOnce(Promise.resolve(['default', 'autogen'])), + getFieldKeysForMeasurement: jest + .fn() + .mockReturnValueOnce(Promise.resolve(['free', 'total'])) + .mockReturnValueOnce(Promise.resolve([])), getTagKeysForMeasurementAndTags: jest .fn() // first time we are called when the widget mounts, diff --git a/public/app/plugins/datasource/influxdb/components/VisualInfluxQLEditor/Editor.test.tsx b/public/app/plugins/datasource/influxdb/components/VisualInfluxQLEditor/Editor.test.tsx index a45d8d0f462..58a033a41ab 100644 --- a/public/app/plugins/datasource/influxdb/components/VisualInfluxQLEditor/Editor.test.tsx +++ b/public/app/plugins/datasource/influxdb/components/VisualInfluxQLEditor/Editor.test.tsx @@ -1,4 +1,4 @@ -import { render } from '@testing-library/react'; +import { act, render } from '@testing-library/react'; import React from 'react'; import InfluxDatasource from '../../datasource'; @@ -35,24 +35,27 @@ jest.mock('./Seg', () => { }; }); -function assertEditor(query: InfluxQuery, textContent: string) { +async function assertEditor(query: InfluxQuery, textContent: string) { const onChange = jest.fn(); const onRunQuery = jest.fn(); const datasource: InfluxDatasource = { metricFindQuery: () => Promise.resolve([]), } as unknown as InfluxDatasource; - const { container } = render( - - ); - expect(container.textContent).toBe(textContent); + await act(async () => { + const { container } = await render( + + ); + expect(container.textContent).toBe(textContent); + }); } describe('InfluxDB InfluxQL Visual Editor', () => { - it('should handle minimal query', () => { + it('should handle minimal query', async () => { const query: InfluxQuery = { refId: 'A', + policy: 'default', }; - assertEditor( + await assertEditor( query, 'FROM[default][select measurement]WHERE[+]' + 'SELECT[field]([value])[mean]()[+]' + @@ -62,13 +65,14 @@ describe('InfluxDB InfluxQL Visual Editor', () => { 'FORMAT AS[time_series]ALIAS[Naming pattern]' ); }); - it('should have the alias-field hidden when format-as-table', () => { + it('should have the alias-field hidden when format-as-table', async () => { const query: InfluxQuery = { refId: 'A', alias: 'test-alias', resultFormat: 'table', + policy: 'default', }; - assertEditor( + await assertEditor( query, 'FROM[default][select measurement]WHERE[+]' + 'SELECT[field]([value])[mean]()[+]' + @@ -78,7 +82,7 @@ describe('InfluxDB InfluxQL Visual Editor', () => { 'FORMAT AS[table]' ); }); - it('should handle complex query', () => { + it('should handle complex query', async () => { const query: InfluxQuery = { refId: 'A', policy: 'default', @@ -147,7 +151,7 @@ describe('InfluxDB InfluxQL Visual Editor', () => { tz: 'UTC', alias: 'all i as', }; - assertEditor( + await assertEditor( query, 'FROM[default][cpu]WHERE[cpu][=][cpu1][AND][cpu][<][cpu3][+]' + 'SELECT[field]([usage_idle])[mean]()[+]' + diff --git a/public/app/plugins/datasource/influxdb/components/VisualInfluxQLEditor/Editor.tsx b/public/app/plugins/datasource/influxdb/components/VisualInfluxQLEditor/Editor.tsx index 7935f6819c0..2bac3d7c305 100644 --- a/public/app/plugins/datasource/influxdb/components/VisualInfluxQLEditor/Editor.tsx +++ b/public/app/plugins/datasource/influxdb/components/VisualInfluxQLEditor/Editor.tsx @@ -1,5 +1,6 @@ import { css } from '@emotion/css'; import React, { useMemo } from 'react'; +import { useAsync } from 'react-use'; import { GrafanaTheme2 } from '@grafana/data'; import { getTemplateSrv } from '@grafana/runtime'; @@ -76,6 +77,9 @@ export const Editor = (props: Props): JSX.Element => { const { datasource } = props; const { measurement, policy } = query; + const policyData = useAsync(() => getAllPolicies(datasource), [datasource]); + const retentionPolicies = !!policyData.error ? [] : policyData.value ?? []; + const allTagKeys = useMemo(() => { return getTagKeysForMeasurementAndTags(measurement, policy, [], datasource).then((tags) => { return new Set(tags); @@ -135,7 +139,7 @@ export const Editor = (props: Props): JSX.Element => {
getAllPolicies(datasource)} getMeasurementOptions={(filter) => diff --git a/public/app/plugins/datasource/influxdb/components/VisualInfluxQLEditor/FromSection.tsx b/public/app/plugins/datasource/influxdb/components/VisualInfluxQLEditor/FromSection.tsx index d3b4c7920ac..7bb322297b1 100644 --- a/public/app/plugins/datasource/influxdb/components/VisualInfluxQLEditor/FromSection.tsx +++ b/public/app/plugins/datasource/influxdb/components/VisualInfluxQLEditor/FromSection.tsx @@ -3,8 +3,6 @@ import React from 'react'; import { Seg } from './Seg'; import { toSelectableValue } from './toSelectableValue'; -const DEFAULT_POLICY = 'default'; - // we use the value "default" as a magic-value, it means // we use the default retention-policy. // unfortunately, IF the user has a retention-policy named "default", @@ -33,12 +31,7 @@ export const FromSection = ({ }: Props): JSX.Element => { const handlePolicyLoadOptions = async () => { const allPolicies = await getPolicyOptions(); - // if `default` does not exist in the list of policies, we add it - const allPoliciesWithDefault = allPolicies.some((p) => p === 'default') - ? allPolicies - : [DEFAULT_POLICY, ...allPolicies]; - - return allPoliciesWithDefault.map(toSelectableValue); + return allPolicies.map(toSelectableValue); }; const handleMeasurementLoadOptions = async (filter: string) => { @@ -50,7 +43,7 @@ export const FromSection = ({ <> { onChange(v.value, measurement); diff --git a/public/app/plugins/datasource/influxdb/datasource.ts b/public/app/plugins/datasource/influxdb/datasource.ts index 6c7319e19a1..b8667fa9c9a 100644 --- a/public/app/plugins/datasource/influxdb/datasource.ts +++ b/public/app/plugins/datasource/influxdb/datasource.ts @@ -123,7 +123,7 @@ export default class InfluxDatasource extends DataSourceWithBackend> => { const builder = new InfluxQueryBuilder(target, datasource.database); const q = builder.buildExploreQuery(type, withKey, withMeasurementFilter); - return datasource.metricFindQuery(q); + const options = { policy: target.policy }; + return datasource.metricFindQuery(q, options); }; export async function getAllPolicies(datasource: InfluxDatasource): Promise { diff --git a/public/app/plugins/datasource/influxdb/influx_query_model.ts b/public/app/plugins/datasource/influxdb/influx_query_model.ts index 2aa00ee797f..e029a2c4cd8 100644 --- a/public/app/plugins/datasource/influxdb/influx_query_model.ts +++ b/public/app/plugins/datasource/influxdb/influx_query_model.ts @@ -1,4 +1,4 @@ -import { map, find, filter, indexOf } from 'lodash'; +import { filter, find, indexOf, map } from 'lodash'; import { escapeRegex, ScopedVars } from '@grafana/data'; import { TemplateSrv } from '@grafana/runtime'; @@ -20,7 +20,6 @@ export default class InfluxQueryModel { this.templateSrv = templateSrv; this.scopedVars = scopedVars; - target.policy = target.policy || 'default'; target.resultFormat = target.resultFormat || 'time_series'; target.orderByTime = target.orderByTime || 'ASC'; target.tags = target.tags || []; @@ -173,7 +172,7 @@ export default class InfluxQueryModel { return str + '"' + tag.key + '" ' + operator + ' ' + value; } - getMeasurementAndPolicy(interpolate: any) { + getMeasurementAndPolicy(interpolate?: boolean) { let policy = this.target.policy; let measurement = this.target.measurement || 'measurement'; @@ -183,13 +182,7 @@ export default class InfluxQueryModel { measurement = this.templateSrv.replace(measurement, this.scopedVars, 'regex'); } - if (policy !== 'default') { - policy = '"' + this.target.policy + '".'; - } else { - policy = ''; - } - - return policy + measurement; + return `"${policy}".${measurement}`; } interpolateQueryStr(value: any[], variable: { multi: any; includeAll: any }, defaultFormatFn: any) { diff --git a/public/app/plugins/datasource/influxdb/queryUtils.test.ts b/public/app/plugins/datasource/influxdb/queryUtils.test.ts index 531c5446705..1620ae99732 100644 --- a/public/app/plugins/datasource/influxdb/queryUtils.test.ts +++ b/public/app/plugins/datasource/influxdb/queryUtils.test.ts @@ -1,6 +1,6 @@ import { cloneDeep } from 'lodash'; -import { buildRawQuery, normalizeQuery, changeSelectPart, changeGroupByPart } from './queryUtils'; +import { buildRawQuery, changeGroupByPart, changeSelectPart, normalizeQuery } from './queryUtils'; import { InfluxQuery } from './types'; describe('InfluxDB query utils', () => { @@ -37,12 +37,15 @@ describe('InfluxDB query utils', () => { ], ], }) - ).toBe('SELECT mean("value") FROM "measurement" WHERE $timeFilter GROUP BY time($__interval) fill(null)'); + ).toBe( + 'SELECT mean("value") FROM "default"."measurement" WHERE $timeFilter GROUP BY time($__interval)' + ' fill(null)' + ); }); it('should handle small query', () => { expect( buildRawQuery({ refId: 'A', + policy: 'autogen', select: [ [ { @@ -53,12 +56,13 @@ describe('InfluxDB query utils', () => { ], groupBy: [], }) - ).toBe('SELECT "value" FROM "measurement" WHERE $timeFilter'); + ).toBe('SELECT "value" FROM "autogen"."measurement" WHERE $timeFilter'); }); it('should handle string limit/slimit', () => { expect( buildRawQuery({ refId: 'A', + policy: 'autogen', select: [ [ { @@ -71,12 +75,13 @@ describe('InfluxDB query utils', () => { limit: '12', slimit: '23', }) - ).toBe('SELECT "value" FROM "measurement" WHERE $timeFilter LIMIT 12 SLIMIT 23'); + ).toBe('SELECT "value" FROM "autogen"."measurement" WHERE $timeFilter LIMIT 12 SLIMIT 23'); }); it('should handle number limit/slimit', () => { expect( buildRawQuery({ refId: 'A', + policy: 'autogen', select: [ [ { @@ -89,12 +94,13 @@ describe('InfluxDB query utils', () => { limit: 12, slimit: 23, }) - ).toBe('SELECT "value" FROM "measurement" WHERE $timeFilter LIMIT 12 SLIMIT 23'); + ).toBe('SELECT "value" FROM "autogen"."measurement" WHERE $timeFilter LIMIT 12 SLIMIT 23'); }); it('should handle all the tag-operators', () => { expect( buildRawQuery({ refId: 'A', + policy: 'autogen', select: [ [ { @@ -147,7 +153,10 @@ describe('InfluxDB query utils', () => { groupBy: [], }) ).toBe( - `SELECT "value" FROM "measurement" WHERE ("cpu" = 'cpu0' AND "cpu" != 'cpu0' AND "cpu" <> 'cpu0' AND "cpu" < cpu0 AND "cpu" > cpu0 AND "cpu" =~ /cpu0/ AND "cpu" !~ /cpu0/) AND $timeFilter` + `SELECT "value" ` + + `FROM "autogen"."measurement" ` + + `WHERE ("cpu" = 'cpu0' AND "cpu" != 'cpu0' AND "cpu" <> 'cpu0' AND "cpu" < cpu0 AND ` + + `"cpu" > cpu0 AND "cpu" =~ /cpu0/ AND "cpu" !~ /cpu0/) AND $timeFilter` ); }); it('should handle a complex query', () => { @@ -229,7 +238,12 @@ describe('InfluxDB query utils', () => { tz: 'UTC', }) ).toBe( - `SELECT holt_winters_with_fit(mean("usage_idle"), 30, 5), median("usage_guest") FROM "cpu" WHERE ("cpu" = 'cpu2' OR "cpu" = 'cpu3' AND "cpu" = 'cpu1') AND $timeFilter GROUP BY time($__interval), "cpu", "host" fill(none) ORDER BY time DESC LIMIT 12 SLIMIT 23 tz('UTC')` + `SELECT holt_winters_with_fit(mean("usage_idle"), 30, 5), median("usage_guest") ` + + `FROM "default"."cpu" ` + + `WHERE ("cpu" = 'cpu2' OR "cpu" = 'cpu3' AND "cpu" = 'cpu1') ` + + `AND $timeFilter ` + + `GROUP BY time($__interval), "cpu", "host" fill(none) ` + + `ORDER BY time DESC LIMIT 12 SLIMIT 23 tz('UTC')` ); }); }); @@ -238,13 +252,14 @@ describe('InfluxDB query utils', () => { it('should handle minimal query', () => { const query: InfluxQuery = { refId: 'A', + policy: 'autogen', }; const queryClone = cloneDeep(query); expect(normalizeQuery(query)).toStrictEqual({ refId: 'A', - policy: 'default', + policy: 'autogen', resultFormat: 'time_series', orderByTime: 'ASC', tags: [], diff --git a/public/app/plugins/datasource/influxdb/response_parser.ts b/public/app/plugins/datasource/influxdb/response_parser.ts index 9e0a1343935..e8e5c0d5946 100644 --- a/public/app/plugins/datasource/influxdb/response_parser.ts +++ b/public/app/plugins/datasource/influxdb/response_parser.ts @@ -18,8 +18,8 @@ export default class ResponseParser { } const normalizedQuery = query.toLowerCase(); - const isValueFirst = - normalizedQuery.indexOf('show field keys') >= 0 || normalizedQuery.indexOf('show retention policies') >= 0; + const isRetentionPolicyQuery = normalizedQuery.indexOf('show retention policies') >= 0; + const isValueFirst = normalizedQuery.indexOf('show field keys') >= 0 || isRetentionPolicyQuery; const res = new Set(); each(influxResults.series, (serie) => { @@ -38,14 +38,27 @@ export default class ResponseParser { // (while the newer versions—first). if (isValueFirst) { - addUnique(res, value[0]); + // We want to know whether the given retention policy is the default one or not. + // If it is default policy then we should add it to the beginning. + // The index 4 gives us if that policy is default or not. + // https://docs.influxdata.com/influxdb/v1.8/query_language/explore-schema/#show-retention-policies + // Only difference is v0.9. In that version we don't receive shardGroupDuration value. + // https://archive.docs.influxdata.com/influxdb/v0.9/query_language/schema_exploration/#show-retention-policies + // Since it is always the last value we will check that last value always. + if (isRetentionPolicyQuery && value[value.length - 1] === true) { + const newSetValues = [value[0].toString(), ...Array.from(res)]; + res.clear(); + newSetValues.forEach((sv) => res.add(sv)); + } else { + res.add(value[0].toString()); + } } else if (value[1] !== undefined) { - addUnique(res, value[1]); + res.add(value[1].toString()); } else { - addUnique(res, value[0]); + res.add(value[0].toString()); } } else { - addUnique(res, value); + res.add(value.toString()); } }); }); @@ -264,10 +277,6 @@ function incrementName(name: string, nameIncremenet: string, params: string[], i return nameIncremenet; } -function addUnique(s: Set, value: string | number) { - s.add(value.toString()); -} - function rawQuerySelectedFieldsInDataframe(query: string | undefined, dfs: DataFrame[]) { const names: Array = dfs.map((df: DataFrame) => df.name); diff --git a/public/app/plugins/datasource/influxdb/specs/influx_query_model.test.ts b/public/app/plugins/datasource/influxdb/specs/influx_query_model.test.ts index e496e2b9429..4ad9a52050e 100644 --- a/public/app/plugins/datasource/influxdb/specs/influx_query_model.test.ts +++ b/public/app/plugins/datasource/influxdb/specs/influx_query_model.test.ts @@ -9,13 +9,16 @@ describe('InfluxQuery', () => { { refId: 'A', measurement: 'cpu', + policy: 'autogen', }, templateSrv, {} ); const queryText = query.render(); - expect(queryText).toBe('SELECT mean("value") FROM "cpu" WHERE $timeFilter GROUP BY time($__interval) fill(null)'); + expect(queryText).toBe( + 'SELECT mean("value") FROM "autogen"."cpu" WHERE $timeFilter GROUP BY time($__interval)' + ' fill(null)' + ); }); }); @@ -44,6 +47,7 @@ describe('InfluxQuery', () => { { refId: 'A', measurement: 'cpu', + policy: 'autogen', select: [ [ { type: 'field', params: ['value'] }, @@ -59,7 +63,7 @@ describe('InfluxQuery', () => { const queryText = query.render(); expect(queryText).toBe( - 'SELECT mean("value") /100 AS "text" FROM "cpu" WHERE $timeFilter GROUP BY time($__interval) fill(null)' + 'SELECT mean("value") /100 AS "text" FROM "autogen"."cpu" WHERE $timeFilter GROUP BY time($__interval) fill(null)' ); }); }); @@ -70,6 +74,7 @@ describe('InfluxQuery', () => { { refId: 'A', measurement: 'cpu', + policy: 'autogen', groupBy: [{ type: 'time', params: ['auto'] }], tags: [{ key: 'hostname', value: 'server\\1' }], }, @@ -80,7 +85,7 @@ describe('InfluxQuery', () => { const queryText = query.render(); expect(queryText).toBe( - 'SELECT mean("value") FROM "cpu" WHERE ("hostname" = \'server\\\\1\') AND $timeFilter' + + 'SELECT mean("value") FROM "autogen"."cpu" WHERE ("hostname" = \'server\\\\1\') AND $timeFilter' + ' GROUP BY time($__interval)' ); }); @@ -90,6 +95,7 @@ describe('InfluxQuery', () => { { refId: 'A', measurement: 'cpu', + policy: 'autogen', groupBy: [{ type: 'time', params: ['auto'] }], tags: [{ key: 'app', value: '/e.*/' }], }, @@ -99,7 +105,7 @@ describe('InfluxQuery', () => { const queryText = query.render(); expect(queryText).toBe( - 'SELECT mean("value") FROM "cpu" WHERE ("app" =~ /e.*/) AND $timeFilter GROUP BY time($__interval)' + 'SELECT mean("value") FROM "autogen"."cpu" WHERE ("app" =~ /e.*/) AND $timeFilter GROUP BY time($__interval)' ); }); }); @@ -110,6 +116,7 @@ describe('InfluxQuery', () => { { refId: 'A', measurement: 'cpu', + policy: 'autogen', groupBy: [{ type: 'time', params: ['auto'] }], tags: [ { key: 'hostname', value: 'server1' }, @@ -122,7 +129,7 @@ describe('InfluxQuery', () => { const queryText = query.render(); expect(queryText).toBe( - 'SELECT mean("value") FROM "cpu" WHERE ("hostname" = \'server1\' AND "app" = \'email\') AND ' + + 'SELECT mean("value") FROM "autogen"."cpu" WHERE ("hostname" = \'server1\' AND "app" = \'email\') AND ' + '$timeFilter GROUP BY time($__interval)' ); }); @@ -134,6 +141,7 @@ describe('InfluxQuery', () => { { refId: 'A', measurement: 'cpu', + policy: 'autogen', groupBy: [{ type: 'time', params: ['auto'] }], tags: [ { key: 'hostname', value: 'server1' }, @@ -146,7 +154,7 @@ describe('InfluxQuery', () => { const queryText = query.render(); expect(queryText).toBe( - 'SELECT mean("value") FROM "cpu" WHERE ("hostname" = \'server1\' OR "hostname" = \'server2\') AND ' + + 'SELECT mean("value") FROM "autogen"."cpu" WHERE ("hostname" = \'server1\' OR "hostname" = \'server2\') AND ' + '$timeFilter GROUP BY time($__interval)' ); }); @@ -158,6 +166,7 @@ describe('InfluxQuery', () => { { refId: 'A', measurement: 'cpu', + policy: 'autogen', groupBy: [{ type: 'time', params: ['auto'] }], tags: [ { key: 'name', value: "Let's encrypt." }, @@ -170,7 +179,7 @@ describe('InfluxQuery', () => { const queryText = query.render(); expect(queryText).toBe( - 'SELECT mean("value") FROM "cpu" WHERE ("name" = \'Let\\\'s encrypt.\' OR "hostname" = \'server2\') AND ' + + 'SELECT mean("value") FROM "autogen"."cpu" WHERE ("name" = \'Let\\\'s encrypt.\' OR "hostname" = \'server2\') AND ' + '$timeFilter GROUP BY time($__interval)' ); }); @@ -182,6 +191,7 @@ describe('InfluxQuery', () => { { refId: 'A', measurement: 'cpu', + policy: 'autogen', groupBy: [], tags: [{ key: 'value', value: '5', operator: '>' }], }, @@ -190,7 +200,7 @@ describe('InfluxQuery', () => { ); const queryText = query.render(); - expect(queryText).toBe('SELECT mean("value") FROM "cpu" WHERE ("value" > 5) AND $timeFilter'); + expect(queryText).toBe('SELECT mean("value") FROM "autogen"."cpu" WHERE ("value" > 5) AND $timeFilter'); }); }); @@ -200,6 +210,7 @@ describe('InfluxQuery', () => { { refId: 'A', measurement: 'cpu', + policy: 'autogen', tags: [], groupBy: [ { type: 'time', interval: 'auto' }, @@ -211,7 +222,9 @@ describe('InfluxQuery', () => { ); const queryText = query.render(); - expect(queryText).toBe('SELECT mean("value") FROM "cpu" WHERE $timeFilter GROUP BY time($__interval), "host"'); + expect(queryText).toBe( + 'SELECT mean("value") FROM "autogen"."cpu" WHERE $timeFilter GROUP BY time($__interval), "host"' + ); }); }); @@ -221,6 +234,7 @@ describe('InfluxQuery', () => { { refId: 'A', measurement: 'cpu', + policy: 'autogen', select: [[{ type: 'field', params: ['value'] }]], groupBy: [], }, @@ -228,7 +242,7 @@ describe('InfluxQuery', () => { {} ); const queryText = query.render(); - expect(queryText).toBe('SELECT "value" FROM "cpu" WHERE $timeFilter'); + expect(queryText).toBe('SELECT "value" FROM "autogen"."cpu" WHERE $timeFilter'); }); }); @@ -238,6 +252,7 @@ describe('InfluxQuery', () => { { refId: 'A', measurement: 'cpu', + policy: 'autogen', select: [[{ type: 'field', params: ['value'] }]], groupBy: [{ type: 'time' }, { type: 'fill', params: ['0'] }], }, @@ -245,7 +260,9 @@ describe('InfluxQuery', () => { {} ); const queryText = query.render(); - expect(queryText).toBe('SELECT "value" FROM "cpu" WHERE $timeFilter GROUP BY time($__interval) fill(0)'); + expect(queryText).toBe( + 'SELECT "value" FROM "autogen"."cpu" WHERE $timeFilter GROUP BY time($__interval) fill(0)' + ); }); }); @@ -255,6 +272,7 @@ describe('InfluxQuery', () => { { refId: 'A', measurement: 'cpu', + policy: 'autogen', groupBy: [{ type: 'time' }, { type: 'fill' }], }, templateSrv,