Azure: Switch to AdvancedHttpSettings component (#109194)

* Type updates

* Switch to AdvancedHttpSettings component

* Fix locale

* Betterer

* i18n-extract
This commit is contained in:
Andreas Christou
2025-08-06 18:19:07 +01:00
committed by GitHub
parent ce2697bb07
commit bda809f062
9 changed files with 54 additions and 48 deletions
-3
View File
@@ -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"]
@@ -37,6 +37,7 @@ export interface AzureMonitorQuery extends common.DataQuery {
* @deprecated Legacy template variable support.
*/
grafanaTemplateVariableFn?: GrafanaTemplateVariableQuery;
keepCookies?: Array<string>;
/**
* Namespace used in template variable queries
*/
@@ -73,6 +74,7 @@ export interface AzureMonitorQuery extends common.DataQuery {
}
export const defaultAzureMonitorQuery: Partial<AzureMonitorQuery> = {
keepCookies: [],
subscriptions: [],
};
@@ -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.
@@ -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(
<ConfigEditor
options={{ ...options, jsonData: { ...options.jsonData, timeout: 10 } }}
onOptionsChange={onOptionsChange}
/>
);
expect(screen.getByLabelText('Timeout')).toBeInTheDocument();
});
it('should render cookies correctly', () => {
const options = {
...baseOptions,
jsonData,
};
render(
<ConfigEditor
options={{ ...options, jsonData: { ...options.jsonData, keepCookies: ['cookie1', 'cookie2'] } }}
onOptionsChange={onOptionsChange}
/>
);
expect(screen.getByText('cookie1')).toBeInTheDocument();
expect(screen.getByText('cookie2')).toBeInTheDocument();
});
});
@@ -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<Props, State> {
const { options, onOptionsChange } = this.props;
const { error } = this.state;
const onTimeoutChange = (e: ChangeEvent<HTMLInputElement>) => {
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 (
<>
<DataSourceDescription
@@ -138,27 +121,16 @@ export class ConfigEditor extends PureComponent<Props, State> {
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
}
>
<Field
label={t('components.config-editor.title-request-timeout', 'Request Timeout')}
description={t(
'components.config-editor.description-request-timeout',
'Set the request timeout in seconds. Default is 30 seconds.'
)}
>
<Input
value={options.jsonData.timeout}
type="number"
className="width-15"
// eslint-disable-next-line @grafana/i18n/no-untranslated-strings
placeholder="30"
onChange={onTimeoutChange}
/>
</Field>
<AdvancedHttpSettings config={options} onChange={onOptionsChange} />
{config.secureSocksDSProxyEnabled && (
<SecureSocksProxySettings options={options} onOptionsChange={onOptionsChange} />
)}
@@ -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
@@ -35,6 +35,7 @@ export interface AzureMonitorQuery extends common.DataQuery {
* @deprecated Legacy template variable support.
*/
grafanaTemplateVariableFn?: GrafanaTemplateVariableQuery;
keepCookies?: Array<string>;
/**
* Namespace used in template variable queries
*/
@@ -71,6 +72,7 @@ export interface AzureMonitorQuery extends common.DataQuery {
}
export const defaultAzureMonitorQuery: Partial<AzureMonitorQuery> = {
keepCookies: [],
subscriptions: [],
};
@@ -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</2> for more details.",
@@ -42,6 +42,7 @@ export interface AzureMonitorDataSourceJsonData extends AzureDataSourceJsonData
enableSecureSocksProxy?: boolean;
timeout?: number;
keepCookies?: string[];
}
export interface AzureMonitorDataSourceSecureJsonData extends AzureDataSourceSecureJsonData {