From e372b54722b3f53dbe3f1ef31e7ed4f326e74130 Mon Sep 17 00:00:00 2001 From: Joey <90795735+joey-grafana@users.noreply.github.com> Date: Wed, 3 Jan 2024 10:00:22 +0000 Subject: [PATCH] Tempo: Easily filter by trace duration (#79931) * Easily filter by trace duration * Add test * Update onChange --- .../SearchTraceQLEditor/TraceQLSearch.tsx | 26 ++++++++++++++++--- .../tempo/SearchTraceQLEditor/utils.test.ts | 26 +++++++++++++++++++ .../tempo/SearchTraceQLEditor/utils.ts | 12 ++++++++- 3 files changed, 59 insertions(+), 5 deletions(-) diff --git a/public/app/plugins/datasource/tempo/SearchTraceQLEditor/TraceQLSearch.tsx b/public/app/plugins/datasource/tempo/SearchTraceQLEditor/TraceQLSearch.tsx index d65f7b28f15..1b3ed2e3f37 100644 --- a/public/app/plugins/datasource/tempo/SearchTraceQLEditor/TraceQLSearch.tsx +++ b/public/app/plugins/datasource/tempo/SearchTraceQLEditor/TraceQLSearch.tsx @@ -4,7 +4,7 @@ import React, { useCallback, useEffect, useState } from 'react'; import { GrafanaTheme2 } from '@grafana/data'; import { EditorRow } from '@grafana/experimental'; import { config, FetchError, getTemplateSrv } from '@grafana/runtime'; -import { Alert, HorizontalGroup, useStyles2 } from '@grafana/ui'; +import { Alert, HorizontalGroup, Select, useStyles2 } from '@grafana/ui'; import { createErrorNotification } from '../../../../core/copy/appNotification'; import { notifyApp } from '../../../../core/reducers/appNotification'; @@ -95,12 +95,15 @@ const TraceQLSearch = ({ datasource, query, onChange }: Props) => { // filter out tags that already exist in the static fields const staticTags = datasource.search?.filters?.map((f) => f.tag) || []; staticTags.push('duration'); + staticTags.push('traceDuration'); // Dynamic filters are all filters that don't match the ID of a filter in the datasource configuration // The duration and status fields are a special case since its selector is hard-coded const dynamicFilters = (query.filters || []).filter( (f) => - !hardCodedFilterIds.includes(f.id) && (datasource.search?.filters?.findIndex((sf) => sf.id === f.id) || 0) === -1 + !hardCodedFilterIds.includes(f.id) && + (datasource.search?.filters?.findIndex((sf) => sf.id === f.id) || 0) === -1 && + f.id !== 'duration-type' ); return ( @@ -150,10 +153,25 @@ const TraceQLSearch = ({ datasource, query, onChange }: Props) => { /> +