From 86b8a0af9f9fd526a315de1b99ea56d9398047ce Mon Sep 17 00:00:00 2001 From: Fabrizio <135109076+fabrizio-grafana@users.noreply.github.com> Date: Tue, 13 Feb 2024 11:48:39 +0100 Subject: [PATCH] Tempo: Improve Betterer results (#81338) --- .betterer.results | 16 +++------ .../plugins/datasource/tempo/QueryField.tsx | 3 ++ .../plugins/datasource/tempo/datasource.ts | 36 ++++++++++--------- 3 files changed, 28 insertions(+), 27 deletions(-) diff --git a/.betterer.results b/.betterer.results index e4f370926f8..21054bcc4dc 100644 --- a/.betterer.results +++ b/.betterer.results @@ -5743,17 +5743,11 @@ exports[`better eslint`] = { ], "public/app/plugins/datasource/tempo/datasource.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.", "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.", "7"], - [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.", "1"], + [0, 0, 0, "Do not use any type assertions.", "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"] ], "public/app/plugins/datasource/tempo/language_provider.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] diff --git a/public/app/plugins/datasource/tempo/QueryField.tsx b/public/app/plugins/datasource/tempo/QueryField.tsx index 2cb433f24b9..ab274359ad5 100644 --- a/public/app/plugins/datasource/tempo/QueryField.tsx +++ b/public/app/plugins/datasource/tempo/QueryField.tsx @@ -123,6 +123,9 @@ class TempoQueryFieldComponent extends React.PureComponent { { + if (typeof result !== 'string' && result !== null) { + throw Error(`Unexpected result type: ${typeof result}`); + } this.props.datasource.uploadedJson = result; onChange({ ...query, diff --git a/public/app/plugins/datasource/tempo/datasource.ts b/public/app/plugins/datasource/tempo/datasource.ts index 3a244e245bc..d87c04ab9cc 100644 --- a/public/app/plugins/datasource/tempo/datasource.ts +++ b/public/app/plugins/datasource/tempo/datasource.ts @@ -18,6 +18,7 @@ import { LoadingState, rangeUtil, ScopedVars, + SelectableValue, TestDataSourceResponse, urlUtil, } from '@grafana/data'; @@ -112,7 +113,7 @@ export class TempoDatasource extends DataSourceWithBackend option.value !== undefined).map((option) => ({ text: option.value })) as Array<{ - text: string; - }>; + return options.flatMap((option: SelectableValue) => + option.value !== undefined ? [{ text: option.value }] : [] + ); } init = async () => { @@ -271,7 +272,8 @@ export class TempoDatasource extends DataSourceWithBackend t.linkedQuery!) }; // Find trace matchers in derived fields of the linked datasource that's identical to this datasource - const settings: DataSourceInstanceSettings = (linkedDatasource as any).instanceSettings; + const settings: DataSourceInstanceSettings = (linkedDatasource as TempoDatasource) + .instanceSettings; const traceLinkMatcher: string[] = settings.jsonData.derivedFields ?.filter((field) => field.datasourceUid === this.uid && field.matcherRegex) @@ -285,7 +287,8 @@ export class TempoDatasource extends DataSourceWithBackend).pipe( + const response = linkedDatasource.query(linkedRequest); + return from(response).pipe( map((response) => response.error ? response : transformTraceList(response, this.uid, this.name, traceLinkMatcher) ) @@ -453,7 +456,7 @@ export class TempoDatasource extends DataSourceWithBackend df?.meta?.preferredVisualisationType === 'nodeGraph'); @@ -720,16 +723,17 @@ export class TempoDatasource extends DataSourceWithBackend + > = ['serviceName', 'spanName', 'search', 'minDuration', 'maxDuration', 'limit']; + return keys + .filter((key) => query[key]) + .map((key) => `${startCase(key)}: ${query[key]}`) + .join(', '); } buildSearchQuery(query: TempoQuery, timeRange?: { startTime: number; endTime?: number }): SearchQueryParams {