AzureMonitor: Remove deprecated configuration parameters (#45860)

pull/46105/head
Andres Martinez Gotor 3 years ago committed by GitHub
parent 700f6863f2
commit d4b05f9421
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      .betterer.results
  2. 58
      public/app/plugins/datasource/grafana-azure-monitor-datasource/components/ConfigEditor.tsx
  3. 5
      public/app/plugins/datasource/grafana-azure-monitor-datasource/components/deprecated/components/AnalyticsConfig.test.tsx
  4. 9
      public/app/plugins/datasource/grafana-azure-monitor-datasource/components/deprecated/components/AnalyticsConfig.tsx
  5. 13
      public/app/plugins/datasource/grafana-azure-monitor-datasource/components/deprecated/components/InsightsConfig.test.tsx
  6. 47
      public/app/plugins/datasource/grafana-azure-monitor-datasource/components/deprecated/components/InsightsConfig.tsx
  7. 5
      public/app/plugins/datasource/grafana-azure-monitor-datasource/components/deprecated/components/__snapshots__/InsightsConfig.test.tsx.snap
  8. 13
      public/app/plugins/datasource/grafana-azure-monitor-datasource/components/deprecated/utils.tsx
  9. 5
      public/app/plugins/datasource/grafana-azure-monitor-datasource/credentials.ts

@ -326,7 +326,7 @@ exports[`no enzyme tests`] = {
"public/app/plugins/datasource/elasticsearch/configuration/DataLinks.test.tsx:2916632804": [ "public/app/plugins/datasource/elasticsearch/configuration/DataLinks.test.tsx:2916632804": [
[1, 17, 13, "RegExp match", "2409514259"] [1, 17, 13, "RegExp match", "2409514259"]
], ],
"public/app/plugins/datasource/grafana-azure-monitor-datasource/components/InsightsConfig.test.tsx:866257119": [ "public/app/plugins/datasource/grafana-azure-monitor-datasource/components/deprecated/components/InsightsConfig.test.tsx:1635510338": [
[1, 19, 13, "RegExp match", "2409514259"] [1, 19, 13, "RegExp match", "2409514259"]
], ],
"public/app/plugins/datasource/influxdb/components/ConfigEditor.test.tsx:767000341": [ "public/app/plugins/datasource/influxdb/components/ConfigEditor.test.tsx:767000341": [

@ -1,21 +1,15 @@
import React, { PureComponent } from 'react'; import { DataSourcePluginOptionsEditorProps, SelectableValue, updateDatasourcePluginOption } from '@grafana/data';
import {
DataSourcePluginOptionsEditorProps,
SelectableValue,
updateDatasourcePluginJsonDataOption,
updateDatasourcePluginOption,
updateDatasourcePluginResetOption,
updateDatasourcePluginSecureJsonDataOption,
} from '@grafana/data';
import { Alert } from '@grafana/ui';
import { MonitorConfig } from './MonitorConfig';
import { AnalyticsConfig } from './AnalyticsConfig';
import { getBackendSrv, getTemplateSrv, TemplateSrv } from '@grafana/runtime'; import { getBackendSrv, getTemplateSrv, TemplateSrv } from '@grafana/runtime';
import { InsightsConfig } from './InsightsConfig'; import { Alert } from '@grafana/ui';
import React, { PureComponent } from 'react';
import ResponseParser from '../azure_monitor/response_parser'; import ResponseParser from '../azure_monitor/response_parser';
import { AzureDataSourceJsonData, AzureDataSourceSecureJsonData, AzureDataSourceSettings } from '../types'; import { AzureDataSourceJsonData, AzureDataSourceSecureJsonData, AzureDataSourceSettings } from '../types';
import { isAppInsightsConfigured } from '../credentials';
import { routeNames } from '../utils/common'; import { routeNames } from '../utils/common';
import { AnalyticsConfig } from './deprecated/components/AnalyticsConfig';
import { InsightsConfig } from './deprecated/components/InsightsConfig';
import { gtGrafana9, isAppInsightsConfigured } from './deprecated/utils';
import { MonitorConfig } from './MonitorConfig';
export type Props = DataSourcePluginOptionsEditorProps<AzureDataSourceJsonData, AzureDataSourceSecureJsonData>; export type Props = DataSourcePluginOptionsEditorProps<AzureDataSourceJsonData, AzureDataSourceSecureJsonData>;
@ -27,7 +21,6 @@ interface ErrorMessage {
export interface State { export interface State {
unsaved: boolean; unsaved: boolean;
appInsightsInitiallyConfigured: boolean;
error?: ErrorMessage; error?: ErrorMessage;
} }
@ -40,7 +33,6 @@ export class ConfigEditor extends PureComponent<Props, State> {
this.state = { this.state = {
unsaved: false, unsaved: false,
appInsightsInitiallyConfigured: isAppInsightsConfigured(props.options),
}; };
this.baseURL = `/api/datasources/${this.props.options.id}/resources/${routeNames.azureMonitor}/subscriptions`; this.baseURL = `/api/datasources/${this.props.options.id}/resources/${routeNames.azureMonitor}/subscriptions`;
} }
@ -90,24 +82,6 @@ export class ConfigEditor extends PureComponent<Props, State> {
} }
}; };
// TODO: Used only by InsightsConfig
private onUpdateJsonDataOption =
(key: keyof AzureDataSourceJsonData) => (event: React.SyntheticEvent<HTMLInputElement | HTMLSelectElement>) => {
updateDatasourcePluginJsonDataOption(this.props, key, event.currentTarget.value);
};
// TODO: Used only by InsightsConfig
private onUpdateSecureJsonDataOption =
(key: keyof AzureDataSourceSecureJsonData) =>
(event: React.SyntheticEvent<HTMLInputElement | HTMLSelectElement>) => {
updateDatasourcePluginSecureJsonDataOption(this.props, key, event.currentTarget.value);
};
// TODO: Used only by InsightsConfig
private resetSecureKey = (key: keyof AzureDataSourceSecureJsonData) => {
updateDatasourcePluginResetOption(this.props, key);
};
render() { render() {
const { options } = this.props; const { options } = this.props;
const { error } = this.state; const { error } = this.state;
@ -115,16 +89,14 @@ export class ConfigEditor extends PureComponent<Props, State> {
return ( return (
<> <>
<MonitorConfig options={options} updateOptions={this.updateOptions} getSubscriptions={this.getSubscriptions} /> <MonitorConfig options={options} updateOptions={this.updateOptions} getSubscriptions={this.getSubscriptions} />
<AnalyticsConfig options={options} updateOptions={this.updateOptions} /> {/* Remove with Grafana 9 */}
{this.state.appInsightsInitiallyConfigured && ( {!gtGrafana9() && (
<InsightsConfig <>
options={options} <AnalyticsConfig options={options} updateOptions={this.updateOptions} />
onUpdateJsonDataOption={this.onUpdateJsonDataOption} {isAppInsightsConfigured(options) && <InsightsConfig {...this.props} />}
onUpdateSecureJsonDataOption={this.onUpdateSecureJsonDataOption} </>
onResetOptionKey={this.resetSecureKey}
/>
)} )}
{/* ===================== */}
{error && ( {error && (
<Alert severity="error" title={error.title}> <Alert severity="error" title={error.title}>
<p>{error.description}</p> <p>{error.description}</p>

@ -1,7 +1,8 @@
import React from 'react';
import { render, screen } from '@testing-library/react'; import { render, screen } from '@testing-library/react';
import AnalyticsConfig, { Props } from './AnalyticsConfig';
import userEvent from '@testing-library/user-event'; import userEvent from '@testing-library/user-event';
import React from 'react';
import AnalyticsConfig, { Props } from './AnalyticsConfig';
const setup = (propsFunc?: (props: Props) => Props) => { const setup = (propsFunc?: (props: Props) => Props) => {
let props: Props = { let props: Props = {

@ -1,8 +1,9 @@
import { Alert, Button } from '@grafana/ui';
import React, { FunctionComponent, useMemo } from 'react'; import React, { FunctionComponent, useMemo } from 'react';
import { AzureCredentialsForm } from './AzureCredentialsForm';
import { Button, Alert } from '@grafana/ui'; import { getCredentials } from '../../../credentials';
import { AzureDataSourceSettings } from '../types'; import { AzureDataSourceSettings } from '../../../types';
import { getCredentials } from '../credentials'; import { AzureCredentialsForm } from '../../AzureCredentialsForm';
export interface Props { export interface Props {
options: AzureDataSourceSettings; options: AzureDataSourceSettings;

@ -1,7 +1,10 @@
import React from 'react';
import { shallow } from 'enzyme';
import InsightsConfig, { Props } from './InsightsConfig';
import { Button, LegacyForms } from '@grafana/ui'; import { Button, LegacyForms } from '@grafana/ui';
import { shallow } from 'enzyme';
import React from 'react';
import { Props } from '../../ConfigEditor';
import InsightsConfig from './InsightsConfig';
const { Input } = LegacyForms; const { Input } = LegacyForms;
const setup = (propOverrides?: object) => { const setup = (propOverrides?: object) => {
@ -33,9 +36,7 @@ const setup = (propOverrides?: object) => {
version: 1, version: 1,
readOnly: false, readOnly: false,
}, },
onUpdateJsonDataOption: jest.fn(), onOptionsChange: jest.fn(),
onUpdateSecureJsonDataOption: jest.fn(),
onResetOptionKey: jest.fn(),
}; };
Object.assign(props, propOverrides); Object.assign(props, propOverrides);

@ -1,25 +1,38 @@
import {
updateDatasourcePluginJsonDataOption,
updateDatasourcePluginResetOption,
updateDatasourcePluginSecureJsonDataOption,
} from '@grafana/data';
import { Alert, Button, InlineFormLabel, LegacyForms } from '@grafana/ui';
import React, { PureComponent } from 'react'; import React, { PureComponent } from 'react';
import { InlineFormLabel, Button, LegacyForms, Alert } from '@grafana/ui';
import { AzureDataSourceJsonData, AzureDataSourceSecureJsonData } from '../../../types';
import { Props } from '../../ConfigEditor';
const { Input } = LegacyForms; const { Input } = LegacyForms;
import { AzureDataSourceSettings, AzureDataSourceJsonData, AzureDataSourceSecureJsonData } from '../types';
export interface Props {
options: AzureDataSourceSettings;
onUpdateJsonDataOption: (
key: keyof AzureDataSourceJsonData
) => (event: React.SyntheticEvent<HTMLInputElement | HTMLSelectElement>) => void;
onUpdateSecureJsonDataOption: (
key: keyof AzureDataSourceSecureJsonData
) => (event: React.SyntheticEvent<HTMLInputElement | HTMLSelectElement>) => void;
onResetOptionKey: (key: keyof AzureDataSourceSecureJsonData) => void;
}
export class InsightsConfig extends PureComponent<Props> { export class InsightsConfig extends PureComponent<Props> {
onAppInsightsResetApiKey = () => { private onAppInsightsResetApiKey = () => {
this.props.onResetOptionKey('appInsightsApiKey'); this.resetSecureKey('appInsightsApiKey');
};
private onUpdateJsonDataOption =
(key: keyof AzureDataSourceJsonData) => (event: React.SyntheticEvent<HTMLInputElement | HTMLSelectElement>) => {
updateDatasourcePluginJsonDataOption(this.props, key, event.currentTarget.value);
};
private onUpdateSecureJsonDataOption =
(key: keyof AzureDataSourceSecureJsonData) =>
(event: React.SyntheticEvent<HTMLInputElement | HTMLSelectElement>) => {
updateDatasourcePluginSecureJsonDataOption(this.props, key, event.currentTarget.value);
};
private resetSecureKey = (key: keyof AzureDataSourceSecureJsonData) => {
updateDatasourcePluginResetOption(this.props, key);
}; };
render() { render() {
const { options, onUpdateJsonDataOption, onUpdateSecureJsonDataOption } = this.props; const { options } = this.props;
return ( return (
<> <>
<h3 className="page-heading">Azure Application Insights</h3> <h3 className="page-heading">Azure Application Insights</h3>
@ -55,7 +68,7 @@ export class InsightsConfig extends PureComponent<Props> {
className="width-30" className="width-30"
placeholder="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" placeholder="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
value={options.secureJsonData!.appInsightsApiKey || ''} value={options.secureJsonData!.appInsightsApiKey || ''}
onChange={onUpdateSecureJsonDataOption('appInsightsApiKey')} onChange={this.onUpdateSecureJsonDataOption('appInsightsApiKey')}
disabled={this.props.options.readOnly} disabled={this.props.options.readOnly}
/> />
</div> </div>
@ -69,7 +82,7 @@ export class InsightsConfig extends PureComponent<Props> {
<Input <Input
className="width-30" className="width-30"
value={options.jsonData.appInsightsAppId || ''} value={options.jsonData.appInsightsAppId || ''}
onChange={onUpdateJsonDataOption('appInsightsAppId')} onChange={this.onUpdateJsonDataOption('appInsightsAppId')}
disabled={this.props.options.readOnly} disabled={this.props.options.readOnly}
/> />
</div> </div>

@ -65,6 +65,7 @@ exports[`Render should disable insights api key input 1`] = `
> >
<Input <Input
className="width-30" className="width-30"
onChange={[Function]}
value="cddcc020-2c94-460a-a3d0-df3147ffa792" value="cddcc020-2c94-460a-a3d0-df3147ffa792"
/> />
</div> </div>
@ -106,6 +107,7 @@ exports[`Render should enable insights api key input 1`] = `
> >
<Input <Input
className="width-30" className="width-30"
onChange={[Function]}
placeholder="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" placeholder="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
value="e7f3f661-a933-4b3f-8176-51c4f982ec48" value="e7f3f661-a933-4b3f-8176-51c4f982ec48"
/> />
@ -128,6 +130,7 @@ exports[`Render should enable insights api key input 1`] = `
> >
<Input <Input
className="width-30" className="width-30"
onChange={[Function]}
value="cddcc020-2c94-460a-a3d0-df3147ffa792" value="cddcc020-2c94-460a-a3d0-df3147ffa792"
/> />
</div> </div>
@ -170,6 +173,7 @@ exports[`Render should render component 1`] = `
<Input <Input
className="width-30" className="width-30"
disabled={false} disabled={false}
onChange={[Function]}
placeholder="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" placeholder="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
value="" value=""
/> />
@ -193,6 +197,7 @@ exports[`Render should render component 1`] = `
<Input <Input
className="width-30" className="width-30"
disabled={false} disabled={false}
onChange={[Function]}
value="" value=""
/> />
</div> </div>

@ -0,0 +1,13 @@
import { config } from '@grafana/runtime';
import { gt, valid } from 'semver';
import { AzureDataSourceSettings } from '../../types';
export function isAppInsightsConfigured(options: AzureDataSourceSettings) {
return !!(options.jsonData.appInsightsAppId && options.secureJsonFields.appInsightsApiKey);
}
export function gtGrafana9() {
// AppInsights configuration will be removed with Grafana 9
return valid(config.buildInfo.version) && gt(config.buildInfo.version, '9.0.0-beta1');
}

@ -1,4 +1,5 @@
import { config } from '@grafana/runtime'; import { config } from '@grafana/runtime';
import { import {
AzureAuthType, AzureAuthType,
AzureCloud, AzureCloud,
@ -165,7 +166,3 @@ export function updateCredentials(
return options; return options;
} }
} }
export function isAppInsightsConfigured(options: AzureDataSourceSettings) {
return !!(options.jsonData.appInsightsAppId && options.secureJsonFields.appInsightsApiKey);
}

Loading…
Cancel
Save