Chore: Type improvements (#87634)

* improve typings in opentsdb datasource

* couple of influx improvements

* couple more

* more

* more more more

* 3 more

* changes to variables/inspect/utils

* some graphite improvements
This commit is contained in:
Ashley Harrison
2024-05-10 17:28:44 +01:00
committed by GitHub
parent 49e6bf26b3
commit 396e75dadf
16 changed files with 206 additions and 253 deletions
+36 -117
View File
@@ -472,10 +472,7 @@ 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, "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.", "5"]
],
"packages/grafana-prometheus/src/gcopypaste/app/features/live/data/amendTimeSeries.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
@@ -1780,20 +1777,17 @@ exports[`better eslint`] = {
[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, "Do not use any type assertions.", "17"],
[0, 0, 0, "Unexpected any. Specify a different type.", "18"],
[0, 0, 0, "Unexpected any. Specify a different type.", "19"],
[0, 0, 0, "Do not use any type assertions.", "20"],
[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, "Do not use any type assertions.", "23"],
[0, 0, 0, "Do not use any type assertions.", "24"],
[0, 0, 0, "Unexpected any. Specify a different type.", "25"],
[0, 0, 0, "Do not use any type assertions.", "26"],
[0, 0, 0, "Do not use any type assertions.", "27"],
[0, 0, 0, "Unexpected any. Specify a different type.", "28"],
[0, 0, 0, "Unexpected any. Specify a different type.", "29"],
[0, 0, 0, "Do not use any type assertions.", "30"]
[0, 0, 0, "Unexpected any. Specify a different type.", "26"],
[0, 0, 0, "Do not use any type assertions.", "27"]
],
"public/app/features/dashboard/state/DashboardModel.repeat.test.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
@@ -1842,23 +1836,20 @@ exports[`better eslint`] = {
[0, 0, 0, "Unexpected any. Specify a different type.", "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, "Do not use any type assertions.", "9"],
[0, 0, 0, "Do not use any type assertions.", "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, "Unexpected any. Specify a different type.", "12"],
[0, 0, 0, "Do not use any type assertions.", "13"],
[0, 0, 0, "Unexpected any. Specify a different type.", "14"],
[0, 0, 0, "Do not use any type assertions.", "15"],
[0, 0, 0, "Do not use any type assertions.", "12"],
[0, 0, 0, "Unexpected any. Specify a different type.", "13"],
[0, 0, 0, "Do not use any type assertions.", "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, "Do not use any type assertions.", "17"],
[0, 0, 0, "Unexpected any. Specify a different type.", "18"],
[0, 0, 0, "Do not use any type assertions.", "19"],
[0, 0, 0, "Unexpected any. Specify a different type.", "20"],
[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.", "21"]
],
"public/app/features/dashboard/state/TimeModel.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
@@ -3030,9 +3021,7 @@ exports[`better eslint`] = {
[0, 0, 0, "Unexpected any. Specify a different type.", "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"],
[0, 0, 0, "Unexpected any. Specify a different type.", "10"]
[0, 0, 0, "Unexpected any. Specify a different type.", "8"]
],
"public/app/features/search/page/components/ActionRow.tsx:5381": [
[0, 0, 0, "Styles should be written using objects.", "0"],
@@ -3172,10 +3161,9 @@ exports[`better eslint`] = {
[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"],
[0, 0, 0, "Do not use any type assertions.", "9"],
[0, 0, 0, "Do not use any type assertions.", "10"],
[0, 0, 0, "Do not use any type assertions.", "11"],
[0, 0, 0, "Do not use any type assertions.", "12"]
[0, 0, 0, "Do not use any type assertions.", "11"]
],
"public/app/features/trails/ActionTabs/utils.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
@@ -3198,9 +3186,7 @@ exports[`better eslint`] = {
[0, 0, 0, "Unexpected any. Specify a different type.", "2"]
],
"public/app/features/transformers/FilterByValueTransformer/ValueMatchers/utils.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, "Unexpected any. Specify a different type.", "2"]
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
],
"public/app/features/transformers/FilterByValueTransformer/ValueMatchers/valueMatchersUI.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
@@ -3416,11 +3402,9 @@ 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.", "5"],
[0, 0, 0, "Do not use any type assertions.", "6"],
[0, 0, 0, "Do not use any type assertions.", "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.", "7"]
],
"public/app/features/variables/pickers/OptionsPicker/actions.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
@@ -4034,17 +4018,17 @@ exports[`better eslint`] = {
],
"public/app/plugins/datasource/graphite/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, "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"],
[0, 0, 0, "Do not use any type assertions.", "2"],
[0, 0, 0, "Unexpected any. Specify a different type.", "3"],
[0, 0, 0, "Do not use any type assertions.", "4"],
[0, 0, 0, "Unexpected any. Specify a different type.", "5"],
[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"],
[0, 0, 0, "Do not use any type assertions.", "10"],
[0, 0, 0, "Do not use any type assertions.", "11"],
[0, 0, 0, "Unexpected any. Specify a different type.", "10"],
[0, 0, 0, "Unexpected any. Specify a different type.", "11"],
[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"],
@@ -4063,42 +4047,15 @@ exports[`better eslint`] = {
[0, 0, 0, "Unexpected any. Specify a different type.", "27"],
[0, 0, 0, "Unexpected any. Specify a different type.", "28"],
[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.", "34"],
[0, 0, 0, "Unexpected any. Specify a different type.", "35"],
[0, 0, 0, "Unexpected any. Specify a different type.", "36"],
[0, 0, 0, "Unexpected any. Specify a different type.", "37"],
[0, 0, 0, "Unexpected any. Specify a different type.", "38"],
[0, 0, 0, "Unexpected any. Specify a different type.", "39"],
[0, 0, 0, "Unexpected any. Specify a different type.", "40"],
[0, 0, 0, "Unexpected any. Specify a different type.", "41"],
[0, 0, 0, "Unexpected any. Specify a different type.", "42"],
[0, 0, 0, "Unexpected any. Specify a different type.", "43"],
[0, 0, 0, "Unexpected any. Specify a different type.", "44"],
[0, 0, 0, "Unexpected any. Specify a different type.", "45"],
[0, 0, 0, "Unexpected any. Specify a different type.", "46"],
[0, 0, 0, "Unexpected any. Specify a different type.", "47"],
[0, 0, 0, "Unexpected any. Specify a different type.", "48"],
[0, 0, 0, "Unexpected any. Specify a different type.", "49"],
[0, 0, 0, "Unexpected any. Specify a different type.", "50"],
[0, 0, 0, "Unexpected any. Specify a different type.", "51"],
[0, 0, 0, "Unexpected any. Specify a different type.", "52"]
[0, 0, 0, "Unexpected any. Specify a different type.", "30"]
],
"public/app/plugins/datasource/graphite/gfunc.ts: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"],
[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, "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"],
[0, 0, 0, "Unexpected any. Specify a different type.", "10"]
[0, 0, 0, "Unexpected any. Specify a different type.", "5"]
],
"public/app/plugins/datasource/graphite/graphite_query.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
@@ -4195,14 +4152,7 @@ exports[`better eslint`] = {
[0, 0, 0, "Unexpected any. Specify a different type.", "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, "Unexpected any. Specify a different type.", "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"],
[0, 0, 0, "Unexpected any. Specify a different type.", "10"],
[0, 0, 0, "Unexpected any. Specify a different type.", "11"]
[0, 0, 0, "Unexpected any. Specify a different type.", "4"]
],
"public/app/plugins/datasource/influxdb/influx_series.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
@@ -4246,8 +4196,7 @@ exports[`better eslint`] = {
[0, 0, 0, "Unexpected any. Specify a different type.", "14"]
],
"public/app/plugins/datasource/influxdb/response_parser.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, "Unexpected any. Specify a different type.", "0"]
],
"public/app/plugins/datasource/jaeger/CheatSheet.tsx:5381": [
[0, 0, 0, "Styles should be written using objects.", "0"],
@@ -4336,8 +4285,7 @@ exports[`better eslint`] = {
],
"public/app/plugins/datasource/loki/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, "Unexpected any. Specify a different type.", "2"]
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
],
"public/app/plugins/datasource/loki/querybuilder/components/LabelBrowserModal.tsx:5381": [
[0, 0, 0, "Styles should be written using objects.", "0"]
@@ -4397,34 +4345,7 @@ exports[`better eslint`] = {
[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, "Unexpected any. Specify a different type.", "28"],
[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.", "34"],
[0, 0, 0, "Unexpected any. Specify a different type.", "35"],
[0, 0, 0, "Unexpected any. Specify a different type.", "36"],
[0, 0, 0, "Unexpected any. Specify a different type.", "37"],
[0, 0, 0, "Unexpected any. Specify a different type.", "38"],
[0, 0, 0, "Unexpected any. Specify a different type.", "39"],
[0, 0, 0, "Unexpected any. Specify a different type.", "40"],
[0, 0, 0, "Do not use any type assertions.", "41"],
[0, 0, 0, "Unexpected any. Specify a different type.", "42"],
[0, 0, 0, "Unexpected any. Specify a different type.", "43"],
[0, 0, 0, "Unexpected any. Specify a different type.", "44"]
[0, 0, 0, "Unexpected any. Specify a different type.", "17"]
],
"public/app/plugins/datasource/opentsdb/migrations.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
@@ -4492,9 +4413,7 @@ exports[`better eslint`] = {
"public/app/plugins/datasource/tempo/datasource.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[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, "Unexpected any. Specify a different type.", "2"]
],
"public/app/plugins/datasource/tempo/language_provider.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
@@ -10,6 +10,7 @@ import {
AnnotationEvent,
AnnotationQueryRequest,
CoreApp,
CustomVariableModel,
DataFrame,
DataQueryRequest,
DataQueryResponse,
@@ -23,6 +24,7 @@ import {
LegacyMetricFindQueryOptions,
MetricFindValue,
QueryFixAction,
QueryVariableModel,
rangeUtil,
renderLegendFormat,
ScopedVars,
@@ -85,14 +87,14 @@ export class PrometheusDatasource
id: number;
access: 'direct' | 'proxy';
basicAuth: any;
withCredentials: any;
withCredentials: boolean;
interval: string;
queryTimeout: string | undefined;
httpMethod: string;
languageProvider: PrometheusLanguageProvider;
exemplarTraceIdDestinations: ExemplarTraceIdDestination[] | undefined;
lookupsDisabled: boolean;
customQueryParameters: any;
customQueryParameters: URLSearchParams;
datasourceConfigurationPrometheusFlavor?: PromApplication;
datasourceConfigurationPrometheusVersion?: string;
disableRecordingRules: boolean;
@@ -114,7 +116,7 @@ export class PrometheusDatasource
this.url = instanceSettings.url!;
this.access = instanceSettings.access;
this.basicAuth = instanceSettings.basicAuth;
this.withCredentials = instanceSettings.withCredentials;
this.withCredentials = Boolean(instanceSettings.withCredentials);
this.interval = instanceSettings.jsonData.timeInterval || '15s';
this.queryTimeout = instanceSettings.jsonData.queryTimeout;
this.httpMethod = instanceSettings.jsonData.httpMethod || 'GET';
@@ -322,7 +324,7 @@ export class PrometheusDatasource
); // toPromise until we change getTagValues, getLabelNames to Observable
}
interpolateQueryExpr(value: string | string[] = [], variable: any) {
interpolateQueryExpr(value: string | string[] = [], variable: QueryVariableModel | CustomVariableModel) {
// if no multi or include all do not regexEscape
if (!variable.multi && !variable.includeAll) {
return prometheusRegularEscape(value);
@@ -159,7 +159,7 @@ export class DashboardMigrator {
if (oldVersion < 3) {
// ensure panel IDs
let maxId = this.dashboard.getNextPanelId();
panelUpgrades.push((panel: any) => {
panelUpgrades.push((panel: PanelModel) => {
if (!panel.id) {
panel.id = maxId;
maxId += 1;
@@ -280,7 +280,7 @@ export class DashboardMigrator {
// schema version 9 changes
if (oldVersion < 9) {
// move aliasYAxis changes
panelUpgrades.push((panel: any) => {
panelUpgrades.push((panel: PanelModel) => {
if (panel.type !== 'singlestat' && panel.thresholds !== '') {
return panel;
}
@@ -631,7 +631,7 @@ export class DashboardMigrator {
}
if (oldVersion < 26) {
panelUpgrades.push((panel: any) => {
panelUpgrades.push((panel: PanelModel) => {
const wasReactText = panel.type === 'text2';
if (!wasReactText) {
return panel;
@@ -180,7 +180,7 @@ export class PanelModel implements DataConfigSource, IPanelModel {
snapshotData?: DataFrameDTO[];
timeFrom?: any;
timeShift?: any;
hideTimeOverride?: any;
hideTimeOverride?: boolean;
declare options: {
[key: string]: any;
};
@@ -515,7 +515,7 @@ export class PanelModel implements DataConfigSource, IPanelModel {
changePlugin(newPlugin: PanelPlugin) {
const pluginId = newPlugin.meta.id;
const oldOptions: any = this.getOptionsToRemember();
const oldOptions = this.getOptionsToRemember();
const prevFieldConfig = this.fieldConfig;
const oldPluginId = this.type;
const wasAngular = this.isAngularPlugin() || Boolean(autoMigrateAngular[oldPluginId]);
@@ -720,7 +720,7 @@ interface PanelOptionsCache {
// For cases where we immediately want to stringify the panel model without cloning each property
export function stringifyPanelModel(panel: PanelModel) {
const model: any = {};
const model: Record<string, unknown> = {};
Object.entries(panel)
.filter(
@@ -1,10 +1,6 @@
import {
DataQuery,
DataSourceApi,
DataSourceWithQueryExportSupport,
DataSourceWithQueryImportSupport,
} from '@grafana/data';
import { DataSourceApi, DataSourceWithQueryExportSupport, DataSourceWithQueryImportSupport } from '@grafana/data';
import { ExpressionDatasourceRef } from '@grafana/runtime/src/utils/DataSourceWithBackend';
import { DataQuery } from '@grafana/schema';
import { TestQuery } from 'app/core/utils/query.test';
import { TemplateSrv } from 'app/features/templating/template_srv';
@@ -380,7 +376,7 @@ describe('updateQueries with import', () => {
const importedQueries = queries.map((q) => ({ ...q, imported: true }));
return Promise.resolve(importedQueries);
},
} as DataSourceWithQueryImportSupport<any>;
} as DataSourceWithQueryImportSupport<DataQuery>;
const oldUidDSWithAbstract = {
uid: 'old-uid',
@@ -456,7 +452,7 @@ describe('updateQueries with import', () => {
importFromAbstractQueries: () => {
return Promise.resolve([]);
},
} as DataSourceWithQueryImportSupport<any>;
} as DataSourceWithQueryImportSupport<DataQuery>;
const oldUidDSWithAbstract = {
uid: 'old-uid',
@@ -124,7 +124,7 @@ export class TemplateSrv implements BaseTemplateSrv {
* interpolateVariablesInQueries or applyTemplateVariables it is passed as a new argument
**/
getAdhocFilters(datasourceName: string, skipDeprecationWarning?: boolean): AdHocVariableFilter[] {
let filters: any = [];
let filters: AdHocVariableFilter[] = [];
let ds = getDataSourceSrv().getInstanceSettings(datasourceName);
if (!ds) {
@@ -2,7 +2,7 @@ import { isString, isUndefined } from 'lodash';
import { Field, FieldType } from '@grafana/data';
export function convertToType(value: any, field: Field): any {
export function convertToType(value: any, field: Field) {
switch (field.type) {
case FieldType.boolean:
if (isUndefined(value)) {
@@ -27,7 +27,7 @@ export function convertToType(value: any, field: Field): any {
}
}
const convertToBool = (value: any): boolean => {
const convertToBool = (value: unknown): boolean => {
if (isString(value)) {
return !(value[0] === 'F' || value[0] === 'f' || value[0] === '0');
}
@@ -69,7 +69,7 @@ export function getVariableName(expression: string) {
return variableName;
}
export const getUnknownVariableStrings = (variables: VariableModel[], model: any) => {
export const getUnknownVariableStrings = (variables: VariableModel[], model: DashboardModel) => {
variableRegex.lastIndex = 0;
const unknownVariableNames: string[] = [];
const modelAsString = safeStringifyValue(model, 2);
@@ -342,7 +342,7 @@ export const transformUsagesToNetwork = (usages: VariableUsageTree[]): UsagesToN
};
const countLeaves = (object: object): number => {
const total = Object.values(object).reduce((count: number, value: any) => {
const total = Object.values(object).reduce<number>((count, value) => {
if (typeof value === 'object') {
return count + countLeaves(value);
}
@@ -209,12 +209,12 @@ describe('graphiteDatasource', () => {
fromAnnotations: true,
tags: ['tag1'],
queryType: 'tags',
},
} as GraphiteQuery,
],
range: {
from: '2022-06-06T07:03:03.109Z',
to: '2022-06-07T07:03:03.109Z',
from: dateTime('2022-06-06T07:03:03.109Z'),
to: dateTime('2022-06-07T07:03:03.109Z'),
raw: {
from: '2022-06-06T07:03:03.109Z',
to: '2022-06-07T07:03:03.109Z',
@@ -748,6 +748,7 @@ function accessScenario(name: string, url: string, fn: ({ headers }: { headers:
const httpOptions = {
headers: {},
url,
};
describe('when using proxy mode', () => {
@@ -21,7 +21,7 @@ import {
toDataFrame,
getSearchFilterScopedVar,
} from '@grafana/data';
import { getBackendSrv } from '@grafana/runtime';
import { BackendSrvRequest, getBackendSrv } from '@grafana/runtime';
import { isVersionGtOrEq, SemVersion } from 'app/core/utils/version';
import { getTemplateSrv, TemplateSrv } from 'app/features/templating/template_srv';
import { getRollupNotice, getRuntimeConsolidationNotice } from 'app/plugins/datasource/graphite/meta';
@@ -71,11 +71,11 @@ export class GraphiteDatasource
basicAuth: string;
url: string;
name: string;
graphiteVersion: any;
graphiteVersion: string;
supportsTags: boolean;
isMetricTank: boolean;
rollupIndicatorEnabled: boolean;
cacheTimeout: any;
cacheTimeout: number;
withCredentials: boolean;
funcDefs: FuncDefs | null = null;
funcDefsPromise: Promise<FuncDefs> | null = null;
@@ -228,7 +228,7 @@ export class GraphiteDatasource
params.push('meta=true');
}
const httpOptions: any = {
const httpOptions: BackendSrvRequest = {
method: 'POST',
url: '/render',
data: params.join('&'),
@@ -247,10 +247,13 @@ export class GraphiteDatasource
}
addTracingHeaders(
httpOptions: { headers: any },
httpOptions: BackendSrvRequest,
options: { dashboardId?: number; panelId?: number; panelPluginId?: string }
) {
const proxyMode = !this.url.match(/^http/);
if (!httpOptions.headers) {
httpOptions.headers = {};
}
if (proxyMode) {
if (options.dashboardId) {
httpOptions.headers['X-Dashboard-Id'] = options.dashboardId;
@@ -364,7 +367,7 @@ export class GraphiteDatasource
return expandedQueries;
}
annotationEvents(range: any, target: any) {
annotationEvents(range: TimeRange, target: GraphiteQuery) {
if (target.target) {
// Graphite query as target as annotation
const targetAnnotation = this.templateSrv.replace(target.target, {}, 'glob');
@@ -434,7 +437,7 @@ export class GraphiteDatasource
}
}
events(options: { range: TimeRange; tags: any; timezone?: TimeZone }) {
events(options: { range: TimeRange; tags: string; timezone?: TimeZone }) {
try {
let tags = '';
if (options.tags) {
@@ -624,10 +627,17 @@ export class GraphiteDatasource
requestId: string,
range?: { from: any; until: any }
): Promise<MetricFindValue[]> {
const httpOptions: any = {
const params: BackendSrvRequest['params'] = {};
if (range) {
params.from = range.from;
params.until = range.until;
}
const httpOptions: BackendSrvRequest = {
method: 'POST',
url: '/metrics/find',
params: {},
params,
data: `query=${query}`,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
@@ -636,11 +646,6 @@ export class GraphiteDatasource
requestId: requestId,
};
if (range) {
httpOptions.params.from = range.from;
httpOptions.params.until = range.until;
}
return lastValueFrom(
this.doGraphiteRequest(httpOptions).pipe(
map((results: any) => {
@@ -665,10 +670,16 @@ export class GraphiteDatasource
requestId: string,
range?: { from: any; until: any }
): Promise<MetricFindValue[]> {
const httpOptions: any = {
const params: BackendSrvRequest['params'] = { query };
if (range) {
params.from = range.from;
params.until = range.until;
}
const httpOptions: BackendSrvRequest = {
method: 'GET',
url: '/metrics/expand',
params: { query },
params,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
@@ -676,11 +687,6 @@ export class GraphiteDatasource
requestId,
};
if (range) {
httpOptions.params.from = range.from;
httpOptions.params.until = range.until;
}
return lastValueFrom(
this.doGraphiteRequest(httpOptions).pipe(
map((results: any) => {
@@ -697,19 +703,21 @@ export class GraphiteDatasource
getTags(optionalOptions: any) {
const options = optionalOptions || {};
const params: BackendSrvRequest['params'] = {};
const httpOptions: any = {
if (options.range) {
params.from = this.translateTime(options.range.from, false, options.timezone);
params.until = this.translateTime(options.range.to, true, options.timezone);
}
const httpOptions: BackendSrvRequest = {
method: 'GET',
url: '/tags',
// for cancellations
requestId: options.requestId,
params,
};
if (options.range) {
httpOptions.params.from = this.translateTime(options.range.from, false, options.timezone);
httpOptions.params.until = this.translateTime(options.range.to, true, options.timezone);
}
return lastValueFrom(
this.doGraphiteRequest(httpOptions).pipe(
map((results: any) => {
@@ -725,18 +733,21 @@ export class GraphiteDatasource
}
getTagValues(options: any = {}) {
const httpOptions: any = {
const params: BackendSrvRequest['params'] = {};
if (options.range) {
params.from = this.translateTime(options.range.from, false, options.timezone);
params.until = this.translateTime(options.range.to, true, options.timezone);
}
const httpOptions: BackendSrvRequest = {
method: 'GET',
url: '/tags/' + this.templateSrv.replace(options.key),
// for cancellations
requestId: options.requestId,
params,
};
if (options.range) {
httpOptions.params.from = this.translateTime(options.range.from, false, options.timezone);
httpOptions.params.until = this.translateTime(options.range.to, true, options.timezone);
}
return lastValueFrom(
this.doGraphiteRequest(httpOptions).pipe(
map((results: any) => {
@@ -755,56 +766,59 @@ export class GraphiteDatasource
);
}
getTagsAutoComplete(expressions: any[], tagPrefix: any, optionalOptions?: any) {
getTagsAutoComplete(expressions: string[], tagPrefix?: string, optionalOptions?: any) {
const options = optionalOptions || {};
const httpOptions: any = {
method: 'GET',
url: '/tags/autoComplete/tags',
params: {
expr: _map(expressions, (expression) => this.templateSrv.replace((expression || '').trim())),
},
// for cancellations
requestId: options.requestId,
const params: BackendSrvRequest['params'] = {
expr: _map(expressions, (expression) => this.templateSrv.replace((expression || '').trim())),
};
if (tagPrefix) {
httpOptions.params.tagPrefix = tagPrefix;
params.tagPrefix = tagPrefix;
}
if (options.limit) {
httpOptions.params.limit = options.limit;
params.limit = options.limit;
}
if (options.range) {
httpOptions.params.from = this.translateTime(options.range.from, false, options.timezone);
httpOptions.params.until = this.translateTime(options.range.to, true, options.timezone);
params.from = this.translateTime(options.range.from, false, options.timezone);
params.until = this.translateTime(options.range.to, true, options.timezone);
}
return lastValueFrom(this.doGraphiteRequest(httpOptions).pipe(mapToTags()));
}
getTagValuesAutoComplete(expressions: any[], tag: any, valuePrefix: any, optionalOptions: any) {
const options = optionalOptions || {};
const httpOptions: any = {
const httpOptions: BackendSrvRequest = {
method: 'GET',
url: '/tags/autoComplete/values',
params: {
expr: _map(expressions, (expression) => this.templateSrv.replace((expression || '').trim())),
tag: this.templateSrv.replace((tag || '').trim()),
},
url: '/tags/autoComplete/tags',
params,
// for cancellations
requestId: options.requestId,
};
return lastValueFrom(this.doGraphiteRequest(httpOptions).pipe(mapToTags()));
}
getTagValuesAutoComplete(expressions: string[], tag: string, valuePrefix?: string, optionalOptions?: any) {
const options = optionalOptions || {};
const params: BackendSrvRequest['params'] = {
expr: _map(expressions, (expression) => this.templateSrv.replace((expression || '').trim())),
tag: this.templateSrv.replace((tag || '').trim()),
};
if (valuePrefix) {
httpOptions.params.valuePrefix = valuePrefix;
params.valuePrefix = valuePrefix;
}
if (options.limit) {
httpOptions.params.limit = options.limit;
params.limit = options.limit;
}
if (options.range) {
httpOptions.params.from = this.translateTime(options.range.from, false, options.timezone);
httpOptions.params.until = this.translateTime(options.range.to, true, options.timezone);
params.from = this.translateTime(options.range.from, false, options.timezone);
params.until = this.translateTime(options.range.to, true, options.timezone);
}
const httpOptions: BackendSrvRequest = {
method: 'GET',
url: '/tags/autoComplete/values',
params,
// for cancellations
requestId: options.requestId,
};
return lastValueFrom(this.doGraphiteRequest(httpOptions).pipe(mapToTags()));
}
@@ -861,7 +875,7 @@ export class GraphiteDatasource
url: '/functions',
// add responseType because if this is not defined,
// backend_srv defaults to json
responseType: 'text',
responseType: 'text' as const,
};
return lastValueFrom(
@@ -908,14 +922,11 @@ export class GraphiteDatasource
return lastValueFrom(this.query(query)).then(() => ({ status: 'success', message: 'Data source is working' }));
}
doGraphiteRequest(options: {
method?: string;
url: any;
requestId?: any;
withCredentials?: any;
headers?: any;
inspect?: any;
}) {
doGraphiteRequest(
options: BackendSrvRequest & {
inspect?: any;
}
) {
if (this.basicAuth || this.withCredentials) {
options.withCredentials = true;
}
@@ -17,7 +17,7 @@ export interface FuncDef {
params: ParamDef[];
defaultParams: Array<string | number>;
category?: string;
shortName?: any;
shortName?: string;
fake?: boolean;
version?: string;
description?: string;
@@ -990,7 +990,7 @@ function isVersionRelatedFunction(obj: { version?: string }, graphiteVersion: st
export class FuncInstance {
def: FuncDef;
params: Array<string | number>;
text: any;
text = '';
/**
* True if this function was just added and not edited yet. It's used to focus on first
* function param to edit it straight away after adding a function.
@@ -1004,7 +1004,7 @@ export class FuncInstance {
*/
hidden?: boolean;
constructor(funcDef: FuncDef, options?: { withDefaultParams: any }) {
constructor(funcDef: FuncDef, options?: { withDefaultParams: boolean }) {
this.def = funcDef;
this.params = [];
@@ -1109,7 +1109,11 @@ export class FuncInstance {
}
}
function createFuncInstance(funcDef: FuncDef | string, options?: { withDefaultParams: any }, idx?: any): FuncInstance {
function createFuncInstance(
funcDef: FuncDef | string,
options?: { withDefaultParams: boolean },
idx?: any
): FuncInstance {
if (isString(funcDef)) {
funcDef = getFuncDef(funcDef, idx);
}
@@ -1181,7 +1185,7 @@ function parseFuncDefs(rawDefs: any): FuncDefs {
}
forEach(funcDef.params, (rawParam) => {
const param: any = {
const param: ParamDef = {
name: rawParam.name,
type: 'string',
optional: !rawParam.required,
@@ -2,6 +2,7 @@ import { filter, find, indexOf, map } from 'lodash';
import { AdHocVariableFilter, escapeRegex, ScopedVars } from '@grafana/data';
import { TemplateSrv } from '@grafana/runtime';
import { QueryPart } from 'app/features/alerting/state/query_part';
import { removeRegexWrapper } from './queryUtils';
import queryPart from './query_part';
@@ -9,11 +10,11 @@ import { DEFAULT_POLICY, InfluxQuery, InfluxQueryTag } from './types';
export default class InfluxQueryModel {
target: InfluxQuery;
selectModels: any[] = [];
selectModels: QueryPart[][] = [];
queryBuilder: any;
groupByParts: any;
groupByParts: QueryPart[] = [];
templateSrv: any;
scopedVars: any;
scopedVars: ScopedVars | undefined;
refId?: string;
constructor(target: InfluxQuery, templateSrv?: TemplateSrv, scopedVars?: ScopedVars) {
@@ -244,7 +245,7 @@ export default class InfluxQueryModel {
return policy + measurement;
}
interpolateQueryStr(value: any[], variable: { multi: any; includeAll: any }, defaultFormatFn: any) {
interpolateQueryStr(value: string | string[], variable: { multi: boolean; includeAll: boolean }) {
// if no multi or include all do not regexEscape
if (!variable.multi && !variable.includeAll) {
return value;
@@ -100,7 +100,7 @@ export default class ResponseParser {
}
const table = this.getTable(rsp.data, target, {});
const list: any[] = [];
const list: AnnotationEvent[] = [];
let titleColIndex = 0;
let timeColIndex = 0;
let timeEndColIndex = 0;
@@ -40,6 +40,8 @@ import {
DataSourceWithQueryModificationSupport,
LogsVolumeOption,
LogsSampleOptions,
QueryVariableModel,
CustomVariableModel,
} from '@grafana/data';
import { Duration } from '@grafana/lezer-logql';
import { BackendSrvRequest, config, DataSourceWithBackend, getTemplateSrv, TemplateSrv } from '@grafana/runtime';
@@ -759,7 +761,7 @@ export class LokiDatasource
* Handles escaping of special characters based on variable type and value.
* @returns The interpolated value with appropriate character escaping.
*/
interpolateQueryExpr(value: any, variable: any) {
interpolateQueryExpr(value: any, variable: QueryVariableModel | CustomVariableModel) {
// if no multi or include all do not regexEscape
if (!variable.multi && !variable.includeAll) {
return lokiRegularEscape(value);
@@ -22,6 +22,7 @@ import {
DataQueryResponse,
DataSourceApi,
dateMath,
DateTime,
ScopedVars,
toDataFrame,
} from '@grafana/data';
@@ -33,18 +34,18 @@ import { prepareAnnotation } from './migrations';
import { OpenTsdbFilter, OpenTsdbOptions, OpenTsdbQuery } from './types';
export default class OpenTsDatasource extends DataSourceApi<OpenTsdbQuery, OpenTsdbOptions> {
type: any;
url: any;
name: any;
withCredentials: any;
type: 'opentsdb';
url: string;
name: string;
withCredentials: boolean;
basicAuth: any;
tsdbVersion: any;
tsdbResolution: any;
lookupLimit: any;
tagKeys: any;
tsdbVersion: number;
tsdbResolution: number;
lookupLimit: number;
tagKeys: Record<string | number, string[]>;
aggregatorsPromise: any;
filterTypesPromise: any;
aggregatorsPromise: Promise<string[]> | null;
filterTypesPromise: Promise<string[]> | null;
constructor(
instanceSettings: any,
@@ -163,7 +164,7 @@ export default class OpenTsDatasource extends DataSourceApi<OpenTsdbQuery, OpenT
const start = this.convertToTSDBTime(options.range.raw.from, false, options.timezone);
const end = this.convertToTSDBTime(options.range.raw.to, true, options.timezone);
const qs = [];
const eventList: any[] = [];
const eventList: AnnotationEvent[] = [];
qs.push({ aggregator: 'sum', metric: annotation.target });
@@ -215,7 +216,7 @@ export default class OpenTsDatasource extends DataSourceApi<OpenTsdbQuery, OpenT
return false;
}
performTimeSeriesQuery(queries: any[], start: any, end: any): Observable<FetchResponse> {
performTimeSeriesQuery(queries: any[], start: number | null, end: number | null): Observable<FetchResponse> {
let msResolution = false;
if (this.tsdbResolution === 2) {
msResolution = true;
@@ -267,12 +268,12 @@ export default class OpenTsDatasource extends DataSourceApi<OpenTsdbQuery, OpenT
);
}
_performMetricKeyValueLookup(metric: string, keys: any) {
_performMetricKeyValueLookup(metric: string, keys: string) {
if (!metric || !keys) {
return of([]);
}
const keysArray = keys.split(',').map((key: any) => {
const keysArray = keys.split(',').map((key) => {
return key.trim();
});
const key = keysArray[0];
@@ -298,7 +299,7 @@ export default class OpenTsDatasource extends DataSourceApi<OpenTsdbQuery, OpenT
);
}
_performMetricKeyLookup(metric: any) {
_performMetricKeyLookup(metric: string) {
if (!metric) {
return of([]);
}
@@ -321,7 +322,7 @@ export default class OpenTsDatasource extends DataSourceApi<OpenTsdbQuery, OpenT
_get(
relativeUrl: string,
params?: { type?: string; q?: string; max?: number; m?: any; limit?: number }
params?: { type?: string; q?: string; max?: number; m?: string; limit?: number }
): Observable<FetchResponse> {
const options = {
method: 'GET',
@@ -334,7 +335,7 @@ export default class OpenTsDatasource extends DataSourceApi<OpenTsdbQuery, OpenT
return getBackendSrv().fetch(options);
}
_addCredentialOptions(options: any) {
_addCredentialOptions(options: Record<string, unknown>) {
if (this.basicAuth || this.withCredentials) {
options.withCredentials = true;
}
@@ -443,7 +444,13 @@ export default class OpenTsDatasource extends DataSourceApi<OpenTsdbQuery, OpenT
return this.filterTypesPromise;
}
transformMetricData(md: { dps: any }, groupByTags: any, target: any, options: any, tsdbResolution: number) {
transformMetricData(
md: { dps: any },
groupByTags: Record<string, boolean>,
target: OpenTsdbQuery,
options: DataQueryRequest<OpenTsdbQuery>,
tsdbResolution: number
) {
const metricLabel = this.createMetricLabel(md, target, groupByTags, options);
const dps: any[] = [];
@@ -462,9 +469,9 @@ export default class OpenTsDatasource extends DataSourceApi<OpenTsdbQuery, OpenT
createMetricLabel(
md: { dps?: any; tags?: any; metric?: any },
target: { alias: string },
groupByTags: any,
options: { scopedVars: any }
target: OpenTsdbQuery,
groupByTags: Record<string, boolean>,
options: DataQueryRequest<OpenTsdbQuery>
) {
if (target.alias) {
const scopedVars = clone(options.scopedVars || {});
@@ -554,13 +561,13 @@ export default class OpenTsDatasource extends DataSourceApi<OpenTsdbQuery, OpenT
return this.templateSrv.getVariables().map((v) => `$${v.name}`);
}
mapMetricsToTargets(metrics: any, options: any, tsdbVersion: number) {
mapMetricsToTargets(metrics: any, options: DataQueryRequest<OpenTsdbQuery>, tsdbVersion: number) {
let interpolatedTagValue, arrTagV;
return _map(metrics, (metricData) => {
if (tsdbVersion === 3) {
return metricData.query.index;
} else {
return findIndex(options.targets as any[], (target) => {
return findIndex(options.targets, (target) => {
if (target.filters && target.filters.length > 0) {
return target.metric === metricData.metric;
} else {
@@ -609,12 +616,12 @@ export default class OpenTsDatasource extends DataSourceApi<OpenTsdbQuery, OpenT
return query;
}
convertToTSDBTime(date: any, roundUp: boolean, timezone: string) {
convertToTSDBTime(date: string | DateTime, roundUp: boolean, timezone: string) {
if (date === 'now') {
return null;
}
date = dateMath.parse(date, roundUp, timezone);
return date.valueOf();
const dateTime = dateMath.parse(date, roundUp, timezone);
return dateTime?.valueOf() ?? null;
}
}
@@ -1154,7 +1154,12 @@ function getServiceGraphView(
if (errorRate.length > 0 && errorRate[0].fields?.length > 2) {
const errorRateNames = errorRate[0].fields[1]?.values ?? [];
const errorRateValues = errorRate[0].fields[2]?.values ?? [];
let errorRateObj: any = {};
let errorRateObj: Record<
string,
{
value: string;
}
> = {};
errorRateNames.map((name: string, index: number) => {
errorRateObj[name] = { value: errorRateValues[index] };
});
@@ -1199,7 +1204,12 @@ function getServiceGraphView(
}
if (duration.length > 0) {
let durationObj: any = {};
let durationObj: Record<
string,
{
value: string;
}
> = {};
duration.forEach((d) => {
if (d.fields.length > 1) {
const delimiter = d.refId?.includes('span_name=~"') ? 'span_name=~"' : 'span_name="';