From bda809f06210811d82cacbe9ad3dcb9973a16ad8 Mon Sep 17 00:00:00 2001 From: Andreas Christou Date: Wed, 6 Aug 2025 19:19:07 +0200 Subject: [PATCH] Azure: Switch to `AdvancedHttpSettings` component (#109194) * Type updates * Switch to AdvancedHttpSettings component * Fix locale * Betterer * i18n-extract --- .betterer.results | 3 -- .../x/AzureMonitorDataQuery_types.gen.ts | 2 + .../kinds/dataquery/types_dataquery_gen.go | 7 +-- .../ConfigEditor/ConfigEditor.test.tsx | 31 ++++++++++++ .../components/ConfigEditor/ConfigEditor.tsx | 48 ++++--------------- .../datasource/azuremonitor/dataquery.cue | 2 + .../datasource/azuremonitor/dataquery.gen.ts | 2 + .../grafana-azure-monitor-datasource.json | 6 +-- .../datasource/azuremonitor/types/types.ts | 1 + 9 files changed, 54 insertions(+), 48 deletions(-) diff --git a/.betterer.results b/.betterer.results index 324e75b58f1..f8eaec8ae3f 100644 --- a/.betterer.results +++ b/.betterer.results @@ -3057,9 +3057,6 @@ exports[`better eslint`] = { "public/app/plugins/datasource/azuremonitor/components/ConfigEditor/BasicLogsToggle.tsx:5381": [ [0, 0, 0, "Add noMargin prop to Field components to remove built-in margins. Use layout components like Stack or Grid with the gap prop instead for consistent spacing.", "0"] ], - "public/app/plugins/datasource/azuremonitor/components/ConfigEditor/ConfigEditor.tsx:5381": [ - [0, 0, 0, "Add noMargin prop to Field components to remove built-in margins. Use layout components like Stack or Grid with the gap prop instead for consistent spacing.", "0"] - ], "public/app/plugins/datasource/azuremonitor/components/ConfigEditor/CurrentUserFallbackCredentials.tsx:5381": [ [0, 0, 0, "Add noMargin prop to Field components to remove built-in margins. Use layout components like Stack or Grid with the gap prop instead for consistent spacing.", "0"], [0, 0, 0, "Add noMargin prop to Field components to remove built-in margins. Use layout components like Stack or Grid with the gap prop instead for consistent spacing.", "1"] diff --git a/packages/grafana-schema/src/raw/composable/azuremonitor/dataquery/x/AzureMonitorDataQuery_types.gen.ts b/packages/grafana-schema/src/raw/composable/azuremonitor/dataquery/x/AzureMonitorDataQuery_types.gen.ts index 612f0f3a1bf..55ad5313063 100644 --- a/packages/grafana-schema/src/raw/composable/azuremonitor/dataquery/x/AzureMonitorDataQuery_types.gen.ts +++ b/packages/grafana-schema/src/raw/composable/azuremonitor/dataquery/x/AzureMonitorDataQuery_types.gen.ts @@ -37,6 +37,7 @@ export interface AzureMonitorQuery extends common.DataQuery { * @deprecated Legacy template variable support. */ grafanaTemplateVariableFn?: GrafanaTemplateVariableQuery; + keepCookies?: Array; /** * Namespace used in template variable queries */ @@ -73,6 +74,7 @@ export interface AzureMonitorQuery extends common.DataQuery { } export const defaultAzureMonitorQuery: Partial = { + keepCookies: [], subscriptions: [], }; diff --git a/pkg/tsdb/azuremonitor/kinds/dataquery/types_dataquery_gen.go b/pkg/tsdb/azuremonitor/kinds/dataquery/types_dataquery_gen.go index 598accb4794..010225654aa 100644 --- a/pkg/tsdb/azuremonitor/kinds/dataquery/types_dataquery_gen.go +++ b/pkg/tsdb/azuremonitor/kinds/dataquery/types_dataquery_gen.go @@ -53,13 +53,14 @@ type AzureMonitorQuery struct { CustomNamespace *string `json:"customNamespace,omitempty"` // Used only for exemplar queries from Prometheus Query *string `json:"query,omitempty"` + // Used to configure the HTTP request timeout + Timeout *float64 `json:"timeout,omitempty"` // For mixed data sources the selected datasource is on the query level. // For non mixed scenarios this is undefined. // TODO find a better way to do this ^ that's friendly to schema // TODO this shouldn't be unknown but DataSourceRef | null - Datasource any `json:"datasource,omitempty"` - // Used to configure the HTTP request timeout - Timeout *float64 `json:"timeout,omitempty"` + Datasource any `json:"datasource,omitempty"` + KeepCookies []string `json:"keepCookies,omitempty"` } // NewAzureMonitorQuery creates a new AzureMonitorQuery object. diff --git a/public/app/plugins/datasource/azuremonitor/components/ConfigEditor/ConfigEditor.test.tsx b/public/app/plugins/datasource/azuremonitor/components/ConfigEditor/ConfigEditor.test.tsx index 5f9f7f79235..0a1c5357236 100644 --- a/public/app/plugins/datasource/azuremonitor/components/ConfigEditor/ConfigEditor.test.tsx +++ b/public/app/plugins/datasource/azuremonitor/components/ConfigEditor/ConfigEditor.test.tsx @@ -42,4 +42,35 @@ describe('AppInsights ConfigEditor', () => { expect(screen.queryByText('Azure Application Insights')).not.toBeInTheDocument(); }); + + it('should render timeout correctly', () => { + const options = { + ...baseOptions, + jsonData, + }; + render( + + ); + + expect(screen.getByLabelText('Timeout')).toBeInTheDocument(); + }); + + it('should render cookies correctly', () => { + const options = { + ...baseOptions, + jsonData, + }; + render( + + ); + + expect(screen.getByText('cookie1')).toBeInTheDocument(); + expect(screen.getByText('cookie2')).toBeInTheDocument(); + }); }); diff --git a/public/app/plugins/datasource/azuremonitor/components/ConfigEditor/ConfigEditor.tsx b/public/app/plugins/datasource/azuremonitor/components/ConfigEditor/ConfigEditor.tsx index 6fc1c94ce81..09e51514832 100644 --- a/public/app/plugins/datasource/azuremonitor/components/ConfigEditor/ConfigEditor.tsx +++ b/public/app/plugins/datasource/azuremonitor/components/ConfigEditor/ConfigEditor.tsx @@ -1,10 +1,10 @@ -import { ChangeEvent, PureComponent } from 'react'; +import { PureComponent } from 'react'; import { DataSourcePluginOptionsEditorProps, SelectableValue, updateDatasourcePluginOption } from '@grafana/data'; import { t } from '@grafana/i18n'; -import { ConfigSection, DataSourceDescription } from '@grafana/plugin-ui'; +import { AdvancedHttpSettings, ConfigSection, DataSourceDescription } from '@grafana/plugin-ui'; import { getBackendSrv, getTemplateSrv, isFetchError, TemplateSrv, config } from '@grafana/runtime'; -import { Alert, Divider, Field, Input, SecureSocksProxySettings } from '@grafana/ui'; +import { Alert, Divider, SecureSocksProxySettings } from '@grafana/ui'; import ResponseParser from '../../azure_monitor/response_parser'; import { @@ -100,23 +100,6 @@ export class ConfigEditor extends PureComponent { const { options, onOptionsChange } = this.props; const { error } = this.state; - const onTimeoutChange = (e: ChangeEvent) => { - if (e.currentTarget.value?.trim() === '') { - this.updateOptions((options) => ({ - ...options, - jsonData: { ...options.jsonData, timeout: undefined }, - })); - } else { - const newVal = Number(e.currentTarget.value); - if (!Number.isNaN(newVal)) { - this.updateOptions((options) => ({ - ...options, - jsonData: { ...options.jsonData, timeout: newVal }, - })); - } - } - }; - return ( <> { title={t('components.config-editor.title-additional-settings', 'Additional settings')} description={t( 'components.config-editor.description-additional-settings', - 'Additional settings are optional settings that can be configured for more control over your data source. This includes Secure Socks Proxy.' + 'Additional settings are optional settings that can be configured for more control over your data source. This includes Secure Socks Proxy, request timeout, and forwarded cookies.' )} isCollapsible={true} - isInitiallyOpen={options.jsonData.enableSecureSocksProxy !== undefined} + isInitiallyOpen={ + options.jsonData.enableSecureSocksProxy !== undefined || + options.jsonData.timeout !== undefined || + options.jsonData.keepCookies !== undefined + } > - - - + {config.secureSocksDSProxyEnabled && ( )} diff --git a/public/app/plugins/datasource/azuremonitor/dataquery.cue b/public/app/plugins/datasource/azuremonitor/dataquery.cue index c4401ed2c79..4fd52d5f297 100644 --- a/public/app/plugins/datasource/azuremonitor/dataquery.cue +++ b/public/app/plugins/datasource/azuremonitor/dataquery.cue @@ -62,6 +62,8 @@ composableKinds: DataQuery: { // Used to configure the HTTP request timeout timeout?: number + + keepCookies?: [...string] } @cuetsy(kind="interface") @grafana(TSVeneer="type") // Defines the supported queryTypes. GrafanaTemplateVariableFn is deprecated diff --git a/public/app/plugins/datasource/azuremonitor/dataquery.gen.ts b/public/app/plugins/datasource/azuremonitor/dataquery.gen.ts index 0a8a9c6e166..c4b986970ca 100644 --- a/public/app/plugins/datasource/azuremonitor/dataquery.gen.ts +++ b/public/app/plugins/datasource/azuremonitor/dataquery.gen.ts @@ -35,6 +35,7 @@ export interface AzureMonitorQuery extends common.DataQuery { * @deprecated Legacy template variable support. */ grafanaTemplateVariableFn?: GrafanaTemplateVariableQuery; + keepCookies?: Array; /** * Namespace used in template variable queries */ @@ -71,6 +72,7 @@ export interface AzureMonitorQuery extends common.DataQuery { } export const defaultAzureMonitorQuery: Partial = { + keepCookies: [], subscriptions: [], }; diff --git a/public/app/plugins/datasource/azuremonitor/locales/en-US/grafana-azure-monitor-datasource.json b/public/app/plugins/datasource/azuremonitor/locales/en-US/grafana-azure-monitor-datasource.json index 441551be648..fade7a48d67 100644 --- a/public/app/plugins/datasource/azuremonitor/locales/en-US/grafana-azure-monitor-datasource.json +++ b/public/app/plugins/datasource/azuremonitor/locales/en-US/grafana-azure-monitor-datasource.json @@ -72,10 +72,8 @@ "label-enable-basic-logs": "Enable Basic Logs" }, "config-editor": { - "description-additional-settings": "Additional settings are optional settings that can be configured for more control over your data source. This includes Secure Socks Proxy.", - "description-request-timeout": "Set the request timeout in seconds. Default is 30 seconds.", - "title-additional-settings": "Additional settings", - "title-request-timeout": "Request Timeout" + "description-additional-settings": "Additional settings are optional settings that can be configured for more control over your data source. This includes Secure Socks Proxy, request timeout, and forwarded cookies.", + "title-additional-settings": "Additional settings" }, "current-user-fallback-credentials": { "alert-fallback-credentials-disabled": "Fallback credentials have been disabled. As user-based authentication only inherently supports requests with a user in scope, features such as alerting, recorded queries, or reporting will not function as expected. Please review the <2>documentation for more details.", diff --git a/public/app/plugins/datasource/azuremonitor/types/types.ts b/public/app/plugins/datasource/azuremonitor/types/types.ts index 34b5d6a88cd..103c59a5535 100644 --- a/public/app/plugins/datasource/azuremonitor/types/types.ts +++ b/public/app/plugins/datasource/azuremonitor/types/types.ts @@ -42,6 +42,7 @@ export interface AzureMonitorDataSourceJsonData extends AzureDataSourceJsonData enableSecureSocksProxy?: boolean; timeout?: number; + keepCookies?: string[]; } export interface AzureMonitorDataSourceSecureJsonData extends AzureDataSourceSecureJsonData {