From 5195a6d72e43155a1586450b06e03fa655c9abda Mon Sep 17 00:00:00 2001 From: "grafana-delivery-bot[bot]" <132647405+grafana-delivery-bot[bot]@users.noreply.github.com> Date: Mon, 18 Aug 2025 18:25:08 +0100 Subject: [PATCH] [release-12.0.3] Azure: Fix time management field (#108481) * Azure: Fix time management field (#107993) * Fix mode setting * Update selector * Add tests * Fix condition (cherry picked from commit a421f55cd5ffd10d69ef0219dbedead3ef97c5e3) * Trigger build --------- Co-authored-by: Andreas Christou --- .../LogsQueryBuilder/LogsQueryBuilder.tsx | 2 +- .../QueryEditor/QueryEditor.test.tsx | 70 ++++++++++++++++++- .../components/QueryEditor/QueryHeader.tsx | 8 ++- .../datasource/azuremonitor/e2e/selectors.ts | 3 + 4 files changed, 80 insertions(+), 3 deletions(-) diff --git a/public/app/plugins/datasource/azuremonitor/components/LogsQueryBuilder/LogsQueryBuilder.tsx b/public/app/plugins/datasource/azuremonitor/components/LogsQueryBuilder/LogsQueryBuilder.tsx index 4662e402eb1..13b77c204e5 100644 --- a/public/app/plugins/datasource/azuremonitor/components/LogsQueryBuilder/LogsQueryBuilder.tsx +++ b/public/app/plugins/datasource/azuremonitor/components/LogsQueryBuilder/LogsQueryBuilder.tsx @@ -133,7 +133,7 @@ export const LogsQueryBuilder: React.FC = (props) => { ); return ( - + {schema && tables.length === 0 && ( diff --git a/public/app/plugins/datasource/azuremonitor/components/QueryEditor/QueryEditor.test.tsx b/public/app/plugins/datasource/azuremonitor/components/QueryEditor/QueryEditor.test.tsx index 86c9e27dc7d..8283017bec2 100644 --- a/public/app/plugins/datasource/azuremonitor/components/QueryEditor/QueryEditor.test.tsx +++ b/public/app/plugins/datasource/azuremonitor/components/QueryEditor/QueryEditor.test.tsx @@ -1,4 +1,4 @@ -import { render, screen, waitFor } from '@testing-library/react'; +import { render, screen, waitFor, cleanup } from '@testing-library/react'; import { CoreApp } from '@grafana/data'; import { config } from '@grafana/runtime'; @@ -39,6 +39,15 @@ jest.mock('@grafana/runtime', () => ({ })); describe('Azure Monitor QueryEditor', () => { + beforeEach(() => { + config.featureToggles = {}; + }); + + afterEach(() => { + cleanup(); + jest.clearAllMocks(); + }); + it('renders the Metrics query editor when the query type is Metrics', async () => { const mockDatasource = createMockDatasource(); const mockQuery = { @@ -67,6 +76,65 @@ describe('Azure Monitor QueryEditor', () => { ); }); + it('renders the Logs code editor when there is an existing query and the builder is enabled', async () => { + config.featureToggles.azureMonitorLogsBuilderEditor = true; + const mockDatasource = createMockDatasource(); + const mockQuery = { + ...createMockQuery(), + queryType: AzureQueryType.LogAnalytics, + }; + + render( {}} onRunQuery={() => {}} />); + await waitFor(() => { + expect( + screen.queryByTestId(selectors.components.queryEditor.logsQueryEditor.container.input) + ).toBeInTheDocument(); + expect( + screen.queryByTestId(selectors.components.queryEditor.logsQueryBuilder.container.input) + ).not.toBeInTheDocument(); + }); + }); + + it('renders the Logs code editor when there is no existing query and the builder is disabled', async () => { + config.featureToggles.azureMonitorLogsBuilderEditor = false; + const mockDatasource = createMockDatasource(); + const mockQuery = { + ...createMockQuery(), + queryType: AzureQueryType.LogAnalytics, + }; + delete mockQuery.azureLogAnalytics?.query; + + render( {}} onRunQuery={() => {}} />); + await waitFor(() => { + expect( + screen.queryByTestId(selectors.components.queryEditor.logsQueryEditor.container.input) + ).toBeInTheDocument(); + expect( + screen.queryByTestId(selectors.components.queryEditor.logsQueryBuilder.container.input) + ).not.toBeInTheDocument(); + }); + }); + + it('renders the Logs builder when there is no existing query and the builder is enabled', async () => { + config.featureToggles.azureMonitorLogsBuilderEditor = true; + const mockDatasource = createMockDatasource(); + const mockQuery = { + ...createMockQuery(), + queryType: AzureQueryType.LogAnalytics, + }; + delete mockQuery.azureLogAnalytics?.query; + + render( {}} onRunQuery={() => {}} />); + await waitFor(() => { + expect( + screen.queryByTestId(selectors.components.queryEditor.logsQueryEditor.container.input) + ).toBeInTheDocument(); + expect( + screen.queryByTestId(selectors.components.queryEditor.logsQueryBuilder.container.input) + ).not.toBeInTheDocument(); + }); + }); + it('renders the ARG query editor when the query type is ARG', async () => { const mockDatasource = createMockDatasource(); const mockQuery = { diff --git a/public/app/plugins/datasource/azuremonitor/components/QueryEditor/QueryHeader.tsx b/public/app/plugins/datasource/azuremonitor/components/QueryEditor/QueryHeader.tsx index b13e76acead..0bb502e76ea 100644 --- a/public/app/plugins/datasource/azuremonitor/components/QueryEditor/QueryHeader.tsx +++ b/public/app/plugins/datasource/azuremonitor/components/QueryEditor/QueryHeader.tsx @@ -63,7 +63,13 @@ export const QueryHeader = ({ ...query, azureLogAnalytics: { ...query.azureLogAnalytics, - mode: LogsEditorMode.Builder, + // Builder mode is default unless there is an existing Log Analytics query + // that was not created with the builder + mode: + (query.azureLogAnalytics?.builderQuery === undefined && query.azureLogAnalytics?.query !== undefined) || + !config.featureToggles.azureMonitorLogsBuilderEditor + ? LogsEditorMode.Raw + : LogsEditorMode.Builder, dashboardTime: true, }, }; diff --git a/public/app/plugins/datasource/azuremonitor/e2e/selectors.ts b/public/app/plugins/datasource/azuremonitor/e2e/selectors.ts index 4756af42064..5647416f601 100644 --- a/public/app/plugins/datasource/azuremonitor/e2e/selectors.ts +++ b/public/app/plugins/datasource/azuremonitor/e2e/selectors.ts @@ -80,6 +80,9 @@ export const components = { button: 'data-testid run-query', }, }, + logsQueryBuilder: { + container: { input: 'data-testid azure-monitor-logs-query-builder' }, + }, argsQueryEditor: { container: { input: 'data-testid azure-monitor-arg-query-editor',