diff --git a/public/app/plugins/datasource/tempo/QueryEditor/QueryField.tsx b/public/app/plugins/datasource/tempo/QueryEditor/QueryField.tsx index e4ce99fa7f1..e55dd42fb75 100644 --- a/public/app/plugins/datasource/tempo/QueryEditor/QueryField.tsx +++ b/public/app/plugins/datasource/tempo/QueryEditor/QueryField.tsx @@ -86,6 +86,16 @@ class TempoQueryFieldComponent extends React.PureComponent { this.props.onRunQuery(); }; + onClearResults = () => { + // Run clear query to clear results + const { onChange, query, onRunQuery } = this.props; + onChange({ + ...query, + queryType: 'clear', + }); + onRunQuery(); + }; + render() { const { query, onChange, datasource } = this.props; // Find query field from linked datasource @@ -123,12 +133,14 @@ class TempoQueryFieldComponent extends React.PureComponent { options={queryTypeOptions} value={query.queryType} - onChange={(v) => + onChange={(v) => { + this.onClearResults(); + onChange({ ...query, queryType: v, - }) - } + }); + }} size="md" /> diff --git a/public/app/plugins/datasource/tempo/datasource.ts b/public/app/plugins/datasource/tempo/datasource.ts index ad26adfd777..f0c36737a8d 100644 --- a/public/app/plugins/datasource/tempo/datasource.ts +++ b/public/app/plugins/datasource/tempo/datasource.ts @@ -28,7 +28,7 @@ import { import { NodeGraphOptions } from 'app/core/components/NodeGraphSettings'; // search = Loki search, nativeSearch = Tempo search for backwards compatibility -export type TempoQueryType = 'search' | 'traceId' | 'serviceMap' | 'upload' | 'nativeSearch'; +export type TempoQueryType = 'search' | 'traceId' | 'serviceMap' | 'upload' | 'nativeSearch' | 'clear'; export interface TempoJsonData extends DataSourceJsonData { tracesToLogs?: TraceToLogsOptions; @@ -90,6 +90,10 @@ export class TempoDatasource extends DataSourceWithBackend !target.hide); const targets: { [type: string]: TempoQuery[] } = groupBy(filteredTargets, (t) => t.queryType || 'traceId'); + if (targets.clear) { + return of({ data: [], state: LoadingState.Done }); + } + // Run search queries on linked datasource if (this.tracesToLogs?.datasourceUid && targets.search?.length > 0) { const dsSrv = getDatasourceSrv();