From 306cea73509f815d8c879152c752995d7258b528 Mon Sep 17 00:00:00 2001 From: Joey <90795735+joey-grafana@users.noreply.github.com> Date: Thu, 18 Apr 2024 08:52:51 +0100 Subject: [PATCH] Tempo: Group by template vars (#86022) * Add template variables to group by field * Add test for interpolation * Add test to allow selecting template vars * Show custom value --- .../SearchTraceQLEditor/GroupByField.test.tsx | 20 +++++++++++++++++ .../SearchTraceQLEditor/GroupByField.tsx | 14 ++++++++---- .../tempo/SearchTraceQLEditor/SearchField.tsx | 22 +++++++++---------- .../datasource/tempo/datasource.test.ts | 14 ++++++++++++ .../plugins/datasource/tempo/datasource.ts | 11 ++++++++++ 5 files changed, 66 insertions(+), 15 deletions(-) diff --git a/public/app/plugins/datasource/tempo/SearchTraceQLEditor/GroupByField.test.tsx b/public/app/plugins/datasource/tempo/SearchTraceQLEditor/GroupByField.test.tsx index 95ebbb01afc..303bf88837a 100644 --- a/public/app/plugins/datasource/tempo/SearchTraceQLEditor/GroupByField.test.tsx +++ b/public/app/plugins/datasource/tempo/SearchTraceQLEditor/GroupByField.test.tsx @@ -5,6 +5,7 @@ import React, { useState } from 'react'; import { TraceqlSearchScope } from '../dataquery.gen'; import { TempoDatasource } from '../datasource'; import TempoLanguageProvider from '../language_provider'; +import { initTemplateSrv } from '../test_utils'; import { TempoQuery } from '../types'; import { GroupByField } from './GroupByField'; @@ -40,6 +41,8 @@ describe('GroupByField', () => { // Need to use delay: null here to work with fakeTimers // see https://github.com/testing-library/user-event/issues/833 user = userEvent.setup({ delay: null }); + + initTemplateSrv([{ name: 'templateVariable1' }, { name: 'templateVariable2' }], {}); }); afterEach(() => { @@ -132,4 +135,21 @@ describe('GroupByField', () => { expect(groupByFilter?.tag).toBe('http.method'); } }); + + it('should allow selecting template variables', async () => { + const { container } = render( + + ); + + const tagSelect = container.querySelector(`input[aria-label="Select tag for filter 1"]`); + expect(tagSelect).not.toBeNull(); + expect(tagSelect).toBeInTheDocument(); + + if (tagSelect) { + await user.click(tagSelect); + jest.advanceTimersByTime(1000); + expect(await screen.findByText('$templateVariable1')).toBeInTheDocument(); + expect(await screen.findByText('$templateVariable2')).toBeInTheDocument(); + } + }); }); diff --git a/public/app/plugins/datasource/tempo/SearchTraceQLEditor/GroupByField.tsx b/public/app/plugins/datasource/tempo/SearchTraceQLEditor/GroupByField.tsx index e88ab32a21c..bcf53682d7e 100644 --- a/public/app/plugins/datasource/tempo/SearchTraceQLEditor/GroupByField.tsx +++ b/public/app/plugins/datasource/tempo/SearchTraceQLEditor/GroupByField.tsx @@ -11,6 +11,7 @@ import { TempoDatasource } from '../datasource'; import { TempoQuery } from '../types'; import InlineSearchField from './InlineSearchField'; +import { withTemplateVariableOptions } from './SearchField'; import { replaceAt } from './utils'; interface Props { @@ -89,15 +90,20 @@ export const GroupByField = (props: Props) => {