diff --git a/.betterer.results b/.betterer.results index eb7876d964e..b19bf8a9210 100644 --- a/.betterer.results +++ b/.betterer.results @@ -4045,40 +4045,30 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "1"] ], "public/app/plugins/datasource/influxdb/components/editor/config/ConfigEditor.tsx:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"], + [0, 0, 0, "Do not use any type assertions.", "0"], [0, 0, 0, "Do not use any type assertions.", "1"], [0, 0, 0, "Do not use any type assertions.", "2"] ], "public/app/plugins/datasource/influxdb/datasource.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], - [0, 0, 0, "Unexpected any. Specify a different type.", "1"], + [0, 0, 0, "Do not use any type assertions.", "1"], [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, "Do not use any type assertions.", "5"], + [0, 0, 0, "Unexpected any. Specify a different type.", "5"], [0, 0, 0, "Unexpected any. Specify a different type.", "6"], - [0, 0, 0, "Do not use any type assertions.", "7"], + [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"], [0, 0, 0, "Unexpected any. Specify a different type.", "10"], [0, 0, 0, "Unexpected any. Specify a different type.", "11"], - [0, 0, 0, "Do not use any type assertions.", "12"], + [0, 0, 0, "Unexpected any. Specify a different type.", "12"], [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, "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, "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"], - [0, 0, 0, "Unexpected any. Specify a different type.", "26"], - [0, 0, 0, "Unexpected any. Specify a different type.", "27"], - [0, 0, 0, "Do not use any type assertions.", "28"] + [0, 0, 0, "Do not use any type assertions.", "18"] ], "public/app/plugins/datasource/influxdb/influx_query_model.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], @@ -4143,8 +4133,7 @@ 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, "Unexpected any. Specify a different type.", "17"] + [0, 0, 0, "Unexpected any. Specify a different type.", "16"] ], "public/app/plugins/datasource/influxdb/response_parser.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], @@ -4171,9 +4160,7 @@ exports[`better eslint`] = { ], "public/app/plugins/datasource/influxdb/specs/mocks.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"], - [0, 0, 0, "Do not use any type assertions.", "1"], - [0, 0, 0, "Unexpected any. Specify a different type.", "2"], - [0, 0, 0, "Do not use any type assertions.", "3"] + [0, 0, 0, "Do not use any type assertions.", "1"] ], "public/app/plugins/datasource/jaeger/datasource.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], diff --git a/public/app/plugins/datasource/influxdb/components/editor/config/ConfigEditor.tsx b/public/app/plugins/datasource/influxdb/components/editor/config/ConfigEditor.tsx index 58c2af9e846..65550937838 100644 --- a/public/app/plugins/datasource/influxdb/components/editor/config/ConfigEditor.tsx +++ b/public/app/plugins/datasource/influxdb/components/editor/config/ConfigEditor.tsx @@ -3,6 +3,7 @@ import React, { PureComponent } from 'react'; import { DataSourcePluginOptionsEditorProps, + DataSourceSettings, onUpdateDatasourceJsonDataOption, onUpdateDatasourceJsonDataOptionSelect, onUpdateDatasourceOption, @@ -23,7 +24,7 @@ import { import { config } from 'app/core/config'; import { BROWSER_MODE_DISABLED_MESSAGE } from '../../../constants'; -import { InfluxOptions, InfluxSecureJsonData, InfluxVersion } from '../../../types'; +import { InfluxOptions, InfluxOptionsV1, InfluxSecureJsonData, InfluxVersion } from '../../../types'; const { Input, SecretFormField } = LegacyForms; @@ -76,7 +77,7 @@ export class ConfigEditor extends PureComponent { onVersionChanged = (selected: SelectableValue) => { const { options, onOptionsChange } = this.props; - const copy: any = { + const copy: DataSourceSettings = { ...options, jsonData: { ...options.jsonData, @@ -89,11 +90,12 @@ export class ConfigEditor extends PureComponent { copy.jsonData.httpMode = 'POST'; // Remove old 1x configs - delete copy.user; - delete copy.database; - } + const { user, database, ...rest } = copy; - onOptionsChange(copy); + onOptionsChange(rest as DataSourceSettings); + } else { + onOptionsChange(copy); + } }; renderInflux2x() { diff --git a/public/app/plugins/datasource/influxdb/components/editor/query/influxql/hooks/useRetentionPolicies.test.ts b/public/app/plugins/datasource/influxdb/components/editor/query/influxql/hooks/useRetentionPolicies.test.ts index e4648e2f1e7..f52d2beebf4 100644 --- a/public/app/plugins/datasource/influxdb/components/editor/query/influxql/hooks/useRetentionPolicies.test.ts +++ b/public/app/plugins/datasource/influxdb/components/editor/query/influxql/hooks/useRetentionPolicies.test.ts @@ -1,5 +1,6 @@ import { renderHook } from '@testing-library/react-hooks'; +import { FetchResponse } from '@grafana/runtime/src'; import config from 'app/core/config'; import { getMockDS, getMockDSInstanceSettings, mockBackendService } from '../../../../../specs/mocks'; @@ -24,7 +25,17 @@ describe('useRetentionPolicies', () => { }); }); -const response = { +const response: FetchResponse = { + config: { + url: 'mock-response-url', + }, + headers: new Headers(), + ok: false, + redirected: false, + status: 0, + statusText: '', + type: 'basic', + url: '', data: { results: { metadataQuery: { diff --git a/public/app/plugins/datasource/influxdb/datasource.ts b/public/app/plugins/datasource/influxdb/datasource.ts index 8f6f78aef1e..3cf26de346c 100644 --- a/public/app/plugins/datasource/influxdb/datasource.ts +++ b/public/app/plugins/datasource/influxdb/datasource.ts @@ -10,9 +10,11 @@ import { DataQueryResponse, DataSourceInstanceSettings, dateMath, + DateTime, FieldType, MetricFindValue, QueryResultMeta, + RawTimeRange, ScopedVars, TIME_SERIES_TIME_FIELD_NAME, TIME_SERIES_VALUE_FIELD_NAME, @@ -235,7 +237,7 @@ export default class InfluxDatasource extends DataSourceWithBackend { + applyTemplateVariables(query: InfluxQuery, scopedVars: ScopedVars): InfluxQuery { // We want to interpolate these variables on backend const { __interval, __interval_ms, ...rest } = scopedVars || {}; @@ -253,7 +255,7 @@ export default class InfluxDatasource extends DataSourceWithBackend { - return selects.map((select: any) => { + return selects.map((select) => { return { ...select, - params: select.params?.map((param: any) => { + params: select.params?.map((param) => { return this.templateSrv.replace(param.toString(), undefined, 'regex'); }), }; @@ -355,7 +357,7 @@ export default class InfluxDatasource extends DataSourceWithBackend { if (rsp.data?.length) { return frameToMetricFindValue(rsp.data[0]); @@ -381,29 +383,32 @@ export default class InfluxDatasource extends DataSourceWithBackend { + (memo: string[], value, key) => { if (value === null || value === undefined) { return memo; } memo.push(encodeURIComponent(key) + '=' + encodeURIComponent(value)); return memo; }, - [] as string[] + [] ).join('&'); } + /** + * @deprecated + */ _influxRequest(method: string, url: string, data: any, options?: any) { const currentUrl = this.urls.shift()!; this.urls.push(currentUrl); @@ -520,6 +531,9 @@ export default class InfluxDatasource extends DataSourceWithBackend= ' + from + ' and time <= ' + until; } - getInfluxTime(date: any, roundUp: any, timezone: any) { + getInfluxTime(date: DateTime | string, roundUp: any, timezone: any) { + let outPutDate; if (isString(date)) { if (date === 'now') { return 'now()'; @@ -564,7 +579,11 @@ export default class InfluxDatasource extends DataSourceWithBackend { let timeFilter = this.getTimeFilter(options); diff --git a/public/app/plugins/datasource/influxdb/query_part.ts b/public/app/plugins/datasource/influxdb/query_part.ts index cf8ab68a852..d37adbafa7f 100644 --- a/public/app/plugins/datasource/influxdb/query_part.ts +++ b/public/app/plugins/datasource/influxdb/query_part.ts @@ -1,6 +1,6 @@ -import { map, clone } from 'lodash'; +import { clone, map } from 'lodash'; -import { QueryPartDef, QueryPart, functionRenderer, suffixRenderer } from 'app/features/alerting/state/query_part'; +import { functionRenderer, QueryPart, QueryPartDef, suffixRenderer } from 'app/features/alerting/state/query_part'; const index: any[] = []; const categories: any = { @@ -33,7 +33,7 @@ function aliasRenderer(part: { params: string[] }, innerExpr: string) { return innerExpr + ' AS ' + '"' + part.params[0] + '"'; } -function fieldRenderer(part: { params: string[] }, innerExpr: any) { +function fieldRenderer(part: { params: string[] }) { const param = part.params[0]; if (param === '*') { diff --git a/public/app/plugins/datasource/influxdb/specs/datasource.test.ts b/public/app/plugins/datasource/influxdb/specs/datasource.test.ts index 894d1ad7589..c8ce4744b32 100644 --- a/public/app/plugins/datasource/influxdb/specs/datasource.test.ts +++ b/public/app/plugins/datasource/influxdb/specs/datasource.test.ts @@ -354,6 +354,9 @@ describe('InfluxDataSource', () => { interpolationVar: { text: text, value: text }, interpolationVar2: { text: 'interpolationText2', value: 'interpolationText2' }, }); + if (!query.tags?.length) { + throw new Error('Tags are not defined'); + } const value = query.tags[0].value; const scopedVars = 'interpolationText|interpolationText2'; expect(value).toBe(scopedVars); diff --git a/public/app/plugins/datasource/influxdb/specs/mocks.ts b/public/app/plugins/datasource/influxdb/specs/mocks.ts index 72c01d4453a..2b737ec8e84 100644 --- a/public/app/plugins/datasource/influxdb/specs/mocks.ts +++ b/public/app/plugins/datasource/influxdb/specs/mocks.ts @@ -15,8 +15,8 @@ export const templateSrvStub = { replace: replaceMock, } as unknown as TemplateSrv; -export function mockBackendService(response: any) { - const fetchMock = jest.fn().mockReturnValue(of(response as FetchResponse)); +export function mockBackendService(response: FetchResponse) { + const fetchMock = jest.fn().mockReturnValue(of(response)); const origBackendSrv = getBackendSrv(); setBackendSrv({ ...origBackendSrv, diff --git a/public/app/plugins/datasource/influxdb/types.ts b/public/app/plugins/datasource/influxdb/types.ts index 9de94c0c8a0..44f3e761604 100644 --- a/public/app/plugins/datasource/influxdb/types.ts +++ b/public/app/plugins/datasource/influxdb/types.ts @@ -19,6 +19,14 @@ export interface InfluxOptions extends DataSourceJsonData { maxSeries?: number; } +/** + * @deprecated + */ +export interface InfluxOptionsV1 extends InfluxOptions { + user?: string; + database?: string; +} + export interface InfluxSecureJsonData { // For Flux token?: string;