mirror of
https://github.com/grafana/grafana.git
synced 2025-09-27 02:14:33 +08:00
AzureMonitor: Move rest of deprecated code (#46109)
This commit is contained in:

committed by
GitHub

parent
0880e0a472
commit
cfbf58fb92
@ -1,14 +1,13 @@
|
|||||||
import React from 'react';
|
import * as ui from '@grafana/ui';
|
||||||
import { render, screen, waitFor } from '@testing-library/react';
|
import { render, screen, waitFor } from '@testing-library/react';
|
||||||
|
import React from 'react';
|
||||||
import selectEvent from 'react-select-event';
|
import selectEvent from 'react-select-event';
|
||||||
|
|
||||||
import QueryEditor from './QueryEditor';
|
|
||||||
|
|
||||||
import createMockQuery from '../../__mocks__/query';
|
|
||||||
import createMockDatasource from '../../__mocks__/datasource';
|
import createMockDatasource from '../../__mocks__/datasource';
|
||||||
import { AzureQueryType } from '../../types';
|
|
||||||
import { invalidNamespaceError } from '../../__mocks__/errors';
|
import { invalidNamespaceError } from '../../__mocks__/errors';
|
||||||
import * as ui from '@grafana/ui';
|
import createMockQuery from '../../__mocks__/query';
|
||||||
|
import { AzureQueryType, DeprecatedAzureQueryType } from '../../types';
|
||||||
|
import QueryEditor from './QueryEditor';
|
||||||
|
|
||||||
// Have to mock CodeEditor because it doesnt seem to work in tests???
|
// Have to mock CodeEditor because it doesnt seem to work in tests???
|
||||||
jest.mock('@grafana/ui', () => ({
|
jest.mock('@grafana/ui', () => ({
|
||||||
@ -45,7 +44,7 @@ describe('Azure Monitor QueryEditor', () => {
|
|||||||
const mockDatasource = createMockDatasource();
|
const mockDatasource = createMockDatasource();
|
||||||
const mockQuery = {
|
const mockQuery = {
|
||||||
...createMockQuery(),
|
...createMockQuery(),
|
||||||
queryType: AzureQueryType.ApplicationInsights,
|
queryType: DeprecatedAzureQueryType.ApplicationInsights,
|
||||||
appInsights: {
|
appInsights: {
|
||||||
metricName: 'requests/count',
|
metricName: 'requests/count',
|
||||||
timeGrain: 'PT1H',
|
timeGrain: 'PT1H',
|
||||||
@ -116,7 +115,7 @@ describe('Azure Monitor QueryEditor', () => {
|
|||||||
const mockDatasource = createMockDatasource();
|
const mockDatasource = createMockDatasource();
|
||||||
const mockQuery = {
|
const mockQuery = {
|
||||||
...createMockQuery(),
|
...createMockQuery(),
|
||||||
queryType: AzureQueryType.ApplicationInsights,
|
queryType: DeprecatedAzureQueryType.ApplicationInsights,
|
||||||
};
|
};
|
||||||
|
|
||||||
render(<QueryEditor query={mockQuery} datasource={mockDatasource} onChange={() => {}} onRunQuery={() => {}} />);
|
render(<QueryEditor query={mockQuery} datasource={mockDatasource} onChange={() => {}} onRunQuery={() => {}} />);
|
||||||
|
@ -1,23 +1,26 @@
|
|||||||
import { Alert } from '@grafana/ui';
|
|
||||||
import { QueryEditorProps } from '@grafana/data';
|
import { QueryEditorProps } from '@grafana/data';
|
||||||
|
import { Alert } from '@grafana/ui';
|
||||||
|
import { debounce } from 'lodash';
|
||||||
import React, { useCallback, useMemo } from 'react';
|
import React, { useCallback, useMemo } from 'react';
|
||||||
|
|
||||||
import AzureMonitorDatasource from '../../datasource';
|
import AzureMonitorDatasource from '../../datasource';
|
||||||
import {
|
import {
|
||||||
|
AzureDataSourceJsonData,
|
||||||
|
AzureMonitorErrorish,
|
||||||
|
AzureMonitorOption,
|
||||||
AzureMonitorQuery,
|
AzureMonitorQuery,
|
||||||
AzureQueryType,
|
AzureQueryType,
|
||||||
AzureMonitorOption,
|
DeprecatedAzureQueryType,
|
||||||
AzureMonitorErrorish,
|
|
||||||
AzureDataSourceJsonData,
|
|
||||||
} from '../../types';
|
} from '../../types';
|
||||||
import MetricsQueryEditor from '../MetricsQueryEditor';
|
|
||||||
import QueryTypeField from './QueryTypeField';
|
|
||||||
import useLastError from '../../utils/useLastError';
|
import useLastError from '../../utils/useLastError';
|
||||||
import LogsQueryEditor from '../LogsQueryEditor';
|
|
||||||
import ArgQueryEditor from '../ArgQueryEditor';
|
import ArgQueryEditor from '../ArgQueryEditor';
|
||||||
import ApplicationInsightsEditor from '../ApplicationInsightsEditor';
|
import ApplicationInsightsEditor from '../deprecated/components/ApplicationInsightsEditor';
|
||||||
import InsightsAnalyticsEditor from '../InsightsAnalyticsEditor';
|
import InsightsAnalyticsEditor from '../deprecated/components/InsightsAnalyticsEditor';
|
||||||
|
import { gtGrafana9 } from '../deprecated/utils';
|
||||||
|
import LogsQueryEditor from '../LogsQueryEditor';
|
||||||
|
import MetricsQueryEditor from '../MetricsQueryEditor';
|
||||||
import { Space } from '../Space';
|
import { Space } from '../Space';
|
||||||
import { debounce } from 'lodash';
|
import QueryTypeField from './QueryTypeField';
|
||||||
import usePreparedQuery from './usePreparedQuery';
|
import usePreparedQuery from './usePreparedQuery';
|
||||||
|
|
||||||
export type AzureMonitorQueryEditorProps = QueryEditorProps<
|
export type AzureMonitorQueryEditorProps = QueryEditorProps<
|
||||||
@ -115,12 +118,6 @@ const EditorForQueryType: React.FC<EditorForQueryTypeProps> = ({
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
case AzureQueryType.ApplicationInsights:
|
|
||||||
return <ApplicationInsightsEditor query={query} />;
|
|
||||||
|
|
||||||
case AzureQueryType.InsightsAnalytics:
|
|
||||||
return <InsightsAnalyticsEditor query={query} />;
|
|
||||||
|
|
||||||
case AzureQueryType.AzureResourceGraph:
|
case AzureQueryType.AzureResourceGraph:
|
||||||
return (
|
return (
|
||||||
<ArgQueryEditor
|
<ArgQueryEditor
|
||||||
@ -133,6 +130,44 @@ const EditorForQueryType: React.FC<EditorForQueryTypeProps> = ({
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/** Remove with Grafana 9 */
|
||||||
|
case DeprecatedAzureQueryType.ApplicationInsights:
|
||||||
|
if (gtGrafana9()) {
|
||||||
|
return (
|
||||||
|
<Alert title="Deprecated">
|
||||||
|
Application Insights has been deprecated.{' '}
|
||||||
|
<a
|
||||||
|
href="https://grafana.com/docs/grafana/latest/datasources/azuremonitor/deprecated-application-insights/#application-insights"
|
||||||
|
target="_blank"
|
||||||
|
rel="noreferrer"
|
||||||
|
>
|
||||||
|
Use the Metrics service instead
|
||||||
|
</a>
|
||||||
|
.
|
||||||
|
</Alert>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return <ApplicationInsightsEditor query={query} />;
|
||||||
|
|
||||||
|
case DeprecatedAzureQueryType.InsightsAnalytics:
|
||||||
|
if (gtGrafana9()) {
|
||||||
|
return (
|
||||||
|
<Alert title="Deprecated">
|
||||||
|
Insight Analytics has been deprecated.{' '}
|
||||||
|
<a
|
||||||
|
href="https://grafana.com/docs/grafana/latest/datasources/azuremonitor/deprecated-application-insights/#insights-analytics"
|
||||||
|
target="_blank"
|
||||||
|
rel="noreferrer"
|
||||||
|
>
|
||||||
|
Queries can be written with Kusto in the Logs query type by selecting your Application Insights resource
|
||||||
|
</a>
|
||||||
|
.
|
||||||
|
</Alert>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return <InsightsAnalyticsEditor query={query} />;
|
||||||
|
/** ===================== */
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return <Alert title="Unknown query type" />;
|
return <Alert title="Unknown query type" />;
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
import React, { useCallback, useState } from 'react';
|
|
||||||
import { Select } from '@grafana/ui';
|
|
||||||
import { Field } from '../Field';
|
|
||||||
import { AzureMonitorQuery, AzureQueryType } from '../../types';
|
|
||||||
import { SelectableValue } from '@grafana/data';
|
import { SelectableValue } from '@grafana/data';
|
||||||
|
import { Select } from '@grafana/ui';
|
||||||
|
import React, { useCallback, useState } from 'react';
|
||||||
|
|
||||||
|
import { AzureMonitorQuery, AzureQueryType, DeprecatedAzureQueryType } from '../../types';
|
||||||
|
import { gtGrafana9 } from '../deprecated/utils';
|
||||||
|
import { Field } from '../Field';
|
||||||
|
|
||||||
interface QueryTypeFieldProps {
|
interface QueryTypeFieldProps {
|
||||||
query: AzureMonitorQuery;
|
query: AzureMonitorQuery;
|
||||||
@ -13,24 +15,26 @@ const QueryTypeField: React.FC<QueryTypeFieldProps> = ({ query, onQueryChange })
|
|||||||
// Use useState to capture the initial value on first mount. We're not interested in when it changes
|
// Use useState to capture the initial value on first mount. We're not interested in when it changes
|
||||||
// We only show App Insights and Insights Analytics if they were initially selected. Otherwise, hide them.
|
// We only show App Insights and Insights Analytics if they were initially selected. Otherwise, hide them.
|
||||||
const [initialQueryType] = useState(query.queryType);
|
const [initialQueryType] = useState(query.queryType);
|
||||||
const showAppInsights =
|
|
||||||
initialQueryType === AzureQueryType.ApplicationInsights || initialQueryType === AzureQueryType.InsightsAnalytics;
|
|
||||||
|
|
||||||
const queryTypes = [
|
const queryTypes: Array<{ value: AzureQueryType | DeprecatedAzureQueryType; label: string }> = [
|
||||||
{ value: AzureQueryType.AzureMonitor, label: 'Metrics' },
|
{ value: AzureQueryType.AzureMonitor, label: 'Metrics' },
|
||||||
{ value: AzureQueryType.LogAnalytics, label: 'Logs' },
|
{ value: AzureQueryType.LogAnalytics, label: 'Logs' },
|
||||||
{ value: AzureQueryType.AzureResourceGraph, label: 'Azure Resource Graph' },
|
{ value: AzureQueryType.AzureResourceGraph, label: 'Azure Resource Graph' },
|
||||||
];
|
];
|
||||||
|
|
||||||
if (showAppInsights) {
|
if (
|
||||||
|
!gtGrafana9() &&
|
||||||
|
(initialQueryType === DeprecatedAzureQueryType.ApplicationInsights ||
|
||||||
|
initialQueryType === DeprecatedAzureQueryType.InsightsAnalytics)
|
||||||
|
) {
|
||||||
queryTypes.push(
|
queryTypes.push(
|
||||||
{ value: AzureQueryType.ApplicationInsights, label: 'Application Insights' },
|
{ value: DeprecatedAzureQueryType.ApplicationInsights, label: 'Application Insights' },
|
||||||
{ value: AzureQueryType.InsightsAnalytics, label: 'Insights Analytics' }
|
{ value: DeprecatedAzureQueryType.InsightsAnalytics, label: 'Insights Analytics' }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleChange = useCallback(
|
const handleChange = useCallback(
|
||||||
(change: SelectableValue<AzureQueryType>) => {
|
(change: SelectableValue<AzureQueryType | DeprecatedAzureQueryType>) => {
|
||||||
change.value &&
|
change.value &&
|
||||||
onQueryChange({
|
onQueryChange({
|
||||||
...query,
|
...query,
|
||||||
|
@ -1,10 +1,15 @@
|
|||||||
import { DataQueryRequest, DataSourceInstanceSettings, ScopedVars } from '@grafana/data';
|
import { DataQueryRequest, DataSourceInstanceSettings, ScopedVars } from '@grafana/data';
|
||||||
import { getTemplateSrv, DataSourceWithBackend } from '@grafana/runtime';
|
import { DataSourceWithBackend, getTemplateSrv } from '@grafana/runtime';
|
||||||
import { isString } from 'lodash';
|
import { isString } from 'lodash';
|
||||||
|
|
||||||
import TimegrainConverter from '../time_grain_converter';
|
import TimegrainConverter from '../../../time_grain_converter';
|
||||||
import { AzureDataSourceJsonData, AzureMonitorQuery, AzureQueryType, DatasourceValidationResult } from '../types';
|
import {
|
||||||
import { routeNames } from '../utils/common';
|
AzureDataSourceJsonData,
|
||||||
|
AzureMonitorQuery,
|
||||||
|
DatasourceValidationResult,
|
||||||
|
DeprecatedAzureQueryType,
|
||||||
|
} from '../../../types';
|
||||||
|
import { routeNames } from '../../../utils/common';
|
||||||
import ResponseParser from './response_parser';
|
import ResponseParser from './response_parser';
|
||||||
|
|
||||||
export interface LogAnalyticsColumn {
|
export interface LogAnalyticsColumn {
|
||||||
@ -94,7 +99,7 @@ export default class AppInsightsDatasource extends DataSourceWithBackend<AzureMo
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
refId: target.refId,
|
refId: target.refId,
|
||||||
queryType: AzureQueryType.ApplicationInsights,
|
queryType: DeprecatedAzureQueryType.ApplicationInsights,
|
||||||
appInsights: {
|
appInsights: {
|
||||||
timeGrain: templateSrv.replace((item.timeGrain || '').toString(), scopedVars),
|
timeGrain: templateSrv.replace((item.timeGrain || '').toString(), scopedVars),
|
||||||
metricName: templateSrv.replace(item.metricName, scopedVars),
|
metricName: templateSrv.replace(item.metricName, scopedVars),
|
@ -1,7 +1,8 @@
|
|||||||
import React from 'react';
|
|
||||||
import { AzureMonitorQuery } from '../../types';
|
|
||||||
import { Alert, Input } from '@grafana/ui';
|
import { Alert, Input } from '@grafana/ui';
|
||||||
import { Field } from '../Field';
|
import React from 'react';
|
||||||
|
|
||||||
|
import { Field } from '../../../Field';
|
||||||
|
import { DeprecatedAzureMonitorQuery } from '../../types';
|
||||||
|
|
||||||
const ReadOnlyTimeGrain = ({
|
const ReadOnlyTimeGrain = ({
|
||||||
timeGrainCount,
|
timeGrainCount,
|
||||||
@ -25,7 +26,7 @@ const ReadOnlyTimeGrain = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const ApplicationInsightsEditor = ({ query }: { query: AzureMonitorQuery }) => {
|
const ApplicationInsightsEditor = ({ query }: { query: DeprecatedAzureMonitorQuery }) => {
|
||||||
const groupBy = query.appInsights?.dimension || [];
|
const groupBy = query.appInsights?.dimension || [];
|
||||||
|
|
||||||
return (
|
return (
|
@ -1,11 +1,13 @@
|
|||||||
import { Alert, CodeEditor, Select } from '@grafana/ui';
|
import { Alert, CodeEditor, Select } from '@grafana/ui';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { AzureMonitorOption, AzureMonitorQuery } from '../../types';
|
|
||||||
import { Field } from '../Field';
|
import { AzureMonitorOption } from '../../../../types';
|
||||||
import { Space } from '../Space';
|
import { Field } from '../../../Field';
|
||||||
|
import { Space } from '../../../Space';
|
||||||
|
import { DeprecatedAzureMonitorQuery } from '../../types';
|
||||||
|
|
||||||
interface InsightsAnalyticsEditorProps {
|
interface InsightsAnalyticsEditorProps {
|
||||||
query: AzureMonitorQuery;
|
query: DeprecatedAzureMonitorQuery;
|
||||||
}
|
}
|
||||||
|
|
||||||
const FORMAT_OPTIONS: Array<AzureMonitorOption<string>> = [
|
const FORMAT_OPTIONS: Array<AzureMonitorOption<string>> = [
|
@ -1,15 +1,16 @@
|
|||||||
import { ScopedVars, DataSourceInstanceSettings } from '@grafana/data';
|
import { DataSourceInstanceSettings, ScopedVars } from '@grafana/data';
|
||||||
import { getTemplateSrv } from '@grafana/runtime';
|
import { getTemplateSrv } from '@grafana/runtime';
|
||||||
|
|
||||||
import { AzureDataSourceJsonData, AzureMonitorQuery, AzureQueryType } from '../types';
|
import { AzureDataSourceJsonData, DeprecatedAzureQueryType } from '../../../types';
|
||||||
import AppInsightsDatasource from '../app_insights/app_insights_datasource';
|
import AppInsightsDatasource from '../app_insights/app_insights_datasource';
|
||||||
|
import { DeprecatedAzureMonitorQuery } from '../types';
|
||||||
|
|
||||||
export default class InsightsAnalyticsDatasource extends AppInsightsDatasource {
|
export default class InsightsAnalyticsDatasource extends AppInsightsDatasource {
|
||||||
constructor(instanceSettings: DataSourceInstanceSettings<AzureDataSourceJsonData>) {
|
constructor(instanceSettings: DataSourceInstanceSettings<AzureDataSourceJsonData>) {
|
||||||
super(instanceSettings);
|
super(instanceSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
applyTemplateVariables(target: AzureMonitorQuery, scopedVars: ScopedVars): AzureMonitorQuery {
|
applyTemplateVariables(target: DeprecatedAzureMonitorQuery, scopedVars: ScopedVars): DeprecatedAzureMonitorQuery {
|
||||||
const item = target.insightsAnalytics;
|
const item = target.insightsAnalytics;
|
||||||
if (!item) {
|
if (!item) {
|
||||||
return target;
|
return target;
|
||||||
@ -19,7 +20,7 @@ export default class InsightsAnalyticsDatasource extends AppInsightsDatasource {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
refId: target.refId,
|
refId: target.refId,
|
||||||
queryType: AzureQueryType.InsightsAnalytics,
|
queryType: DeprecatedAzureQueryType.InsightsAnalytics,
|
||||||
insightsAnalytics: {
|
insightsAnalytics: {
|
||||||
query: getTemplateSrv().replace(query, scopedVars),
|
query: getTemplateSrv().replace(query, scopedVars),
|
||||||
resultFormat: item.resultFormat,
|
resultFormat: item.resultFormat,
|
@ -0,0 +1 @@
|
|||||||
|
export * from './query';
|
@ -0,0 +1,61 @@
|
|||||||
|
import { DataQuery } from '@grafana/data';
|
||||||
|
|
||||||
|
import {
|
||||||
|
AzureLogsQuery,
|
||||||
|
AzureMetricQuery,
|
||||||
|
AzureQueryType,
|
||||||
|
AzureResourceGraphQuery,
|
||||||
|
DeprecatedAzureQueryType,
|
||||||
|
} from '../../../types';
|
||||||
|
import { GrafanaTemplateVariableQuery } from '../../../types/templateVariables';
|
||||||
|
|
||||||
|
export interface DeprecatedAzureMonitorQuery extends DataQuery {
|
||||||
|
queryType?: AzureQueryType | DeprecatedAzureQueryType;
|
||||||
|
|
||||||
|
subscription?: string;
|
||||||
|
|
||||||
|
/** ARG uses multiple subscriptions */
|
||||||
|
subscriptions?: string[];
|
||||||
|
|
||||||
|
azureMonitor?: AzureMetricQuery;
|
||||||
|
azureLogAnalytics?: AzureLogsQuery;
|
||||||
|
azureResourceGraph?: AzureResourceGraphQuery;
|
||||||
|
grafanaTemplateVariableFn?: GrafanaTemplateVariableQuery;
|
||||||
|
|
||||||
|
/** @deprecated App Insights/Insights Analytics deprecated in v8 */
|
||||||
|
appInsights?: ApplicationInsightsQuery;
|
||||||
|
|
||||||
|
/** @deprecated App Insights/Insights Analytics deprecated in v8 */
|
||||||
|
insightsAnalytics?: InsightsAnalyticsQuery;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Azure Monitor App Insights sub-query properties
|
||||||
|
* @deprecated App Insights deprecated in v8 in favor of Metrics queries
|
||||||
|
*/
|
||||||
|
export interface ApplicationInsightsQuery {
|
||||||
|
metricName?: string;
|
||||||
|
timeGrain?: string;
|
||||||
|
timeGrainCount?: string;
|
||||||
|
timeGrainType?: string;
|
||||||
|
timeGrainUnit?: string;
|
||||||
|
aggregation?: string;
|
||||||
|
dimension?: string[]; // Was string before 7.1
|
||||||
|
dimensionFilter?: string;
|
||||||
|
alias?: string;
|
||||||
|
|
||||||
|
/** @deprecated Migrated to Insights Analytics query */
|
||||||
|
rawQuery?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Azure Monitor Insights Analytics sub-query properties
|
||||||
|
* @deprecated Insights Analytics deprecated in v8 in favor of Logs queries
|
||||||
|
*/
|
||||||
|
export interface InsightsAnalyticsQuery {
|
||||||
|
query?: string;
|
||||||
|
resultFormat?: string;
|
||||||
|
|
||||||
|
/** @deprecated Migrate field to query */
|
||||||
|
rawQueryString?: string;
|
||||||
|
}
|
@ -1,9 +1,3 @@
|
|||||||
import { cloneDeep, upperFirst } from 'lodash';
|
|
||||||
import AzureMonitorDatasource from './azure_monitor/azure_monitor_datasource';
|
|
||||||
import AppInsightsDatasource from './app_insights/app_insights_datasource';
|
|
||||||
import AzureLogAnalyticsDatasource from './azure_log_analytics/azure_log_analytics_datasource';
|
|
||||||
import ResourcePickerData from './resourcePicker/resourcePickerData';
|
|
||||||
import { AzureDataSourceJsonData, AzureMonitorQuery, AzureQueryType, DatasourceValidationResult } from './types';
|
|
||||||
import {
|
import {
|
||||||
DataFrame,
|
DataFrame,
|
||||||
DataQueryRequest,
|
DataQueryRequest,
|
||||||
@ -13,15 +7,29 @@ import {
|
|||||||
LoadingState,
|
LoadingState,
|
||||||
ScopedVars,
|
ScopedVars,
|
||||||
} from '@grafana/data';
|
} from '@grafana/data';
|
||||||
import { forkJoin, Observable, of } from 'rxjs';
|
|
||||||
import { getTemplateSrv, TemplateSrv } from 'app/features/templating/template_srv';
|
import { getTemplateSrv, TemplateSrv } from 'app/features/templating/template_srv';
|
||||||
import InsightsAnalyticsDatasource from './insights_analytics/insights_analytics_datasource';
|
import { cloneDeep, upperFirst } from 'lodash';
|
||||||
import { datasourceMigrations } from './utils/migrateQuery';
|
import { forkJoin, Observable, of } from 'rxjs';
|
||||||
import { map } from 'rxjs/operators';
|
import { map } from 'rxjs/operators';
|
||||||
|
|
||||||
|
import AzureLogAnalyticsDatasource from './azure_log_analytics/azure_log_analytics_datasource';
|
||||||
|
import AzureMonitorDatasource from './azure_monitor/azure_monitor_datasource';
|
||||||
import AzureResourceGraphDatasource from './azure_resource_graph/azure_resource_graph_datasource';
|
import AzureResourceGraphDatasource from './azure_resource_graph/azure_resource_graph_datasource';
|
||||||
|
import AppInsightsDatasource from './components/deprecated/app_insights/app_insights_datasource';
|
||||||
|
import InsightsAnalyticsDatasource from './components/deprecated/insights_analytics/insights_analytics_datasource';
|
||||||
import { getAzureCloud } from './credentials';
|
import { getAzureCloud } from './credentials';
|
||||||
|
import ResourcePickerData from './resourcePicker/resourcePickerData';
|
||||||
|
import {
|
||||||
|
AzureDataSourceJsonData,
|
||||||
|
AzureMonitorQuery,
|
||||||
|
AzureQueryType,
|
||||||
|
DatasourceValidationResult,
|
||||||
|
DeprecatedAzureQueryType,
|
||||||
|
} from './types';
|
||||||
import migrateAnnotation from './utils/migrateAnnotation';
|
import migrateAnnotation from './utils/migrateAnnotation';
|
||||||
|
import { datasourceMigrations } from './utils/migrateQuery';
|
||||||
import { VariableSupport } from './variables';
|
import { VariableSupport } from './variables';
|
||||||
|
|
||||||
export default class Datasource extends DataSourceApi<AzureMonitorQuery, AzureDataSourceJsonData> {
|
export default class Datasource extends DataSourceApi<AzureMonitorQuery, AzureDataSourceJsonData> {
|
||||||
annotations = {
|
annotations = {
|
||||||
prepareAnnotation: migrateAnnotation,
|
prepareAnnotation: migrateAnnotation,
|
||||||
@ -37,7 +45,7 @@ export default class Datasource extends DataSourceApi<AzureMonitorQuery, AzureDa
|
|||||||
insightsAnalyticsDatasource?: InsightsAnalyticsDatasource;
|
insightsAnalyticsDatasource?: InsightsAnalyticsDatasource;
|
||||||
|
|
||||||
pseudoDatasource: {
|
pseudoDatasource: {
|
||||||
[key in AzureQueryType]?:
|
[key in AzureQueryType | DeprecatedAzureQueryType]?:
|
||||||
| AzureMonitorDatasource
|
| AzureMonitorDatasource
|
||||||
| AzureLogAnalyticsDatasource
|
| AzureLogAnalyticsDatasource
|
||||||
| AzureResourceGraphDatasource
|
| AzureResourceGraphDatasource
|
||||||
@ -68,8 +76,8 @@ export default class Datasource extends DataSourceApi<AzureMonitorQuery, AzureDa
|
|||||||
// AppInsights and InsightAnalytics are only supported for Public and Azure China clouds
|
// AppInsights and InsightAnalytics are only supported for Public and Azure China clouds
|
||||||
this.appInsightsDatasource = new AppInsightsDatasource(instanceSettings);
|
this.appInsightsDatasource = new AppInsightsDatasource(instanceSettings);
|
||||||
this.insightsAnalyticsDatasource = new InsightsAnalyticsDatasource(instanceSettings);
|
this.insightsAnalyticsDatasource = new InsightsAnalyticsDatasource(instanceSettings);
|
||||||
this.pseudoDatasource[AzureQueryType.ApplicationInsights] = this.appInsightsDatasource;
|
this.pseudoDatasource[DeprecatedAzureQueryType.ApplicationInsights] = this.appInsightsDatasource;
|
||||||
this.pseudoDatasource[AzureQueryType.InsightsAnalytics] = this.insightsAnalyticsDatasource;
|
this.pseudoDatasource[DeprecatedAzureQueryType.InsightsAnalytics] = this.insightsAnalyticsDatasource;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.variables = new VariableSupport(this);
|
this.variables = new VariableSupport(this);
|
||||||
@ -84,7 +92,7 @@ export default class Datasource extends DataSourceApi<AzureMonitorQuery, AzureDa
|
|||||||
}
|
}
|
||||||
|
|
||||||
query(options: DataQueryRequest<AzureMonitorQuery>): Observable<DataQueryResponse> {
|
query(options: DataQueryRequest<AzureMonitorQuery>): Observable<DataQueryResponse> {
|
||||||
const byType = new Map<AzureQueryType, DataQueryRequest<AzureMonitorQuery>>();
|
const byType = new Map<AzureQueryType | DeprecatedAzureQueryType, DataQueryRequest<AzureMonitorQuery>>();
|
||||||
|
|
||||||
for (const baseTarget of options.targets) {
|
for (const baseTarget of options.targets) {
|
||||||
// Migrate old query structures
|
// Migrate old query structures
|
||||||
@ -314,10 +322,10 @@ function hasQueryForType(query: AzureMonitorQuery): boolean {
|
|||||||
case AzureQueryType.GrafanaTemplateVariableFn:
|
case AzureQueryType.GrafanaTemplateVariableFn:
|
||||||
return !!query.grafanaTemplateVariableFn;
|
return !!query.grafanaTemplateVariableFn;
|
||||||
|
|
||||||
case AzureQueryType.ApplicationInsights:
|
case DeprecatedAzureQueryType.ApplicationInsights:
|
||||||
return !!query.appInsights;
|
return !!query.appInsights;
|
||||||
|
|
||||||
case AzureQueryType.InsightsAnalytics:
|
case DeprecatedAzureQueryType.InsightsAnalytics:
|
||||||
return !!query.insightsAnalytics;
|
return !!query.insightsAnalytics;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -1,21 +1,25 @@
|
|||||||
import { DataQuery } from '@grafana/data';
|
import { DeprecatedAzureMonitorQuery } from '../components/deprecated/types';
|
||||||
import { GrafanaTemplateVariableQuery } from './templateVariables';
|
import { GrafanaTemplateVariableQuery } from './templateVariables';
|
||||||
|
|
||||||
export enum AzureQueryType {
|
export enum AzureQueryType {
|
||||||
AzureMonitor = 'Azure Monitor',
|
AzureMonitor = 'Azure Monitor',
|
||||||
ApplicationInsights = 'Application Insights',
|
|
||||||
InsightsAnalytics = 'Insights Analytics',
|
|
||||||
LogAnalytics = 'Azure Log Analytics',
|
LogAnalytics = 'Azure Log Analytics',
|
||||||
AzureResourceGraph = 'Azure Resource Graph',
|
AzureResourceGraph = 'Azure Resource Graph',
|
||||||
GrafanaTemplateVariableFn = 'Grafana Template Variable Function',
|
GrafanaTemplateVariableFn = 'Grafana Template Variable Function',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeprecatedAzureQueryType won't be available after Grafana 9
|
||||||
|
export enum DeprecatedAzureQueryType {
|
||||||
|
ApplicationInsights = 'Application Insights',
|
||||||
|
InsightsAnalytics = 'Insights Analytics',
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the query as it moves through the frontend query editor and datasource files.
|
* Represents the query as it moves through the frontend query editor and datasource files.
|
||||||
* It can represent new queries that are still being edited, so all properties are optional
|
* It can represent new queries that are still being edited, so all properties are optional
|
||||||
*/
|
*/
|
||||||
export interface AzureMonitorQuery extends DataQuery {
|
export interface AzureMonitorQuery extends DeprecatedAzureMonitorQuery {
|
||||||
queryType?: AzureQueryType;
|
queryType?: AzureQueryType | DeprecatedAzureQueryType;
|
||||||
|
|
||||||
subscription?: string;
|
subscription?: string;
|
||||||
|
|
||||||
@ -26,12 +30,6 @@ export interface AzureMonitorQuery extends DataQuery {
|
|||||||
azureLogAnalytics?: AzureLogsQuery;
|
azureLogAnalytics?: AzureLogsQuery;
|
||||||
azureResourceGraph?: AzureResourceGraphQuery;
|
azureResourceGraph?: AzureResourceGraphQuery;
|
||||||
grafanaTemplateVariableFn?: GrafanaTemplateVariableQuery;
|
grafanaTemplateVariableFn?: GrafanaTemplateVariableQuery;
|
||||||
|
|
||||||
/** @deprecated App Insights/Insights Analytics deprecated in v8 */
|
|
||||||
appInsights?: ApplicationInsightsQuery;
|
|
||||||
|
|
||||||
/** @deprecated App Insights/Insights Analytics deprecated in v8 */
|
|
||||||
insightsAnalytics?: InsightsAnalyticsQuery;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -84,37 +82,6 @@ export interface AzureResourceGraphQuery {
|
|||||||
resultFormat?: string;
|
resultFormat?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Azure Monitor App Insights sub-query properties
|
|
||||||
* @deprecated App Insights deprecated in v8 in favor of Metrics queries
|
|
||||||
*/
|
|
||||||
export interface ApplicationInsightsQuery {
|
|
||||||
metricName?: string;
|
|
||||||
timeGrain?: string;
|
|
||||||
timeGrainCount?: string;
|
|
||||||
timeGrainType?: string;
|
|
||||||
timeGrainUnit?: string;
|
|
||||||
aggregation?: string;
|
|
||||||
dimension?: string[]; // Was string before 7.1
|
|
||||||
dimensionFilter?: string;
|
|
||||||
alias?: string;
|
|
||||||
|
|
||||||
/** @deprecated Migrated to Insights Analytics query */
|
|
||||||
rawQuery?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Azure Monitor Insights Analytics sub-query properties
|
|
||||||
* @deprecated Insights Analytics deprecated in v8 in favor of Logs queries
|
|
||||||
*/
|
|
||||||
export interface InsightsAnalyticsQuery {
|
|
||||||
query?: string;
|
|
||||||
resultFormat?: string;
|
|
||||||
|
|
||||||
/** @deprecated Migrate field to query */
|
|
||||||
rawQueryString?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface AzureMetricDimension {
|
export interface AzureMetricDimension {
|
||||||
dimension: string;
|
dimension: string;
|
||||||
operator: string;
|
operator: string;
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import { AzureMonitorQuery, AzureQueryType } from '../types';
|
import { setKustoQuery } from '../components/LogsQueryEditor/setQueryValue';
|
||||||
import TimegrainConverter from '../time_grain_converter';
|
|
||||||
import {
|
import {
|
||||||
appendDimensionFilter,
|
appendDimensionFilter,
|
||||||
setTimeGrain as setMetricsTimeGrain,
|
setTimeGrain as setMetricsTimeGrain,
|
||||||
} from '../components/MetricsQueryEditor/setQueryValue';
|
} from '../components/MetricsQueryEditor/setQueryValue';
|
||||||
import { setKustoQuery } from '../components/LogsQueryEditor/setQueryValue';
|
import TimegrainConverter from '../time_grain_converter';
|
||||||
|
import { AzureMonitorQuery, AzureQueryType, DeprecatedAzureQueryType } from '../types';
|
||||||
|
|
||||||
const OLD_DEFAULT_DROPDOWN_VALUE = 'select';
|
const OLD_DEFAULT_DROPDOWN_VALUE = 'select';
|
||||||
|
|
||||||
@ -138,10 +138,10 @@ function migrateMetricsDimensionFilters(query: AzureMonitorQuery): AzureMonitorQ
|
|||||||
export function datasourceMigrations(query: AzureMonitorQuery): AzureMonitorQuery {
|
export function datasourceMigrations(query: AzureMonitorQuery): AzureMonitorQuery {
|
||||||
let workingQuery = query;
|
let workingQuery = query;
|
||||||
|
|
||||||
if (workingQuery.queryType === AzureQueryType.ApplicationInsights && workingQuery.appInsights?.rawQuery) {
|
if (workingQuery.queryType === DeprecatedAzureQueryType.ApplicationInsights && workingQuery.appInsights?.rawQuery) {
|
||||||
workingQuery = {
|
workingQuery = {
|
||||||
...workingQuery,
|
...workingQuery,
|
||||||
queryType: AzureQueryType.InsightsAnalytics,
|
queryType: DeprecatedAzureQueryType.InsightsAnalytics,
|
||||||
appInsights: undefined,
|
appInsights: undefined,
|
||||||
insightsAnalytics: {
|
insightsAnalytics: {
|
||||||
query: workingQuery.appInsights.rawQuery,
|
query: workingQuery.appInsights.rawQuery,
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
import { DataQueryRequest, DataQueryResponseData, toDataFrame } from '@grafana/data';
|
import { DataQueryRequest, DataQueryResponseData, toDataFrame } from '@grafana/data';
|
||||||
import { from } from 'rxjs';
|
import { from } from 'rxjs';
|
||||||
import { AzureMonitorQuery, AzureQueryType } from './types';
|
|
||||||
import { VariableSupport } from './variables';
|
|
||||||
import createMockDatasource from './__mocks__/datasource';
|
import createMockDatasource from './__mocks__/datasource';
|
||||||
import { invalidSubscriptionError } from './__mocks__/errors';
|
import { invalidSubscriptionError } from './__mocks__/errors';
|
||||||
|
import { AzureMonitorQuery, AzureQueryType } from './types';
|
||||||
|
import { VariableSupport } from './variables';
|
||||||
|
|
||||||
jest.mock('@grafana/runtime', () => ({
|
jest.mock('@grafana/runtime', () => ({
|
||||||
...(jest.requireActual('@grafana/runtime') as unknown as object),
|
...(jest.requireActual('@grafana/runtime') as unknown as object),
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import { from, lastValueFrom, Observable } from 'rxjs';
|
|
||||||
import {
|
import {
|
||||||
CustomVariableSupport,
|
CustomVariableSupport,
|
||||||
DataQueryRequest,
|
DataQueryRequest,
|
||||||
@ -6,13 +5,16 @@ import {
|
|||||||
MetricFindValue,
|
MetricFindValue,
|
||||||
toDataFrame,
|
toDataFrame,
|
||||||
} from '@grafana/data';
|
} from '@grafana/data';
|
||||||
|
import { getTemplateSrv } from '@grafana/runtime';
|
||||||
|
import { from, lastValueFrom, Observable } from 'rxjs';
|
||||||
|
|
||||||
import VariableEditor from './components/VariableEditor/VariableEditor';
|
import VariableEditor from './components/VariableEditor/VariableEditor';
|
||||||
import DataSource from './datasource';
|
import DataSource from './datasource';
|
||||||
import { AzureQueryType, AzureMonitorQuery } from './types';
|
|
||||||
import { getTemplateSrv } from '@grafana/runtime';
|
|
||||||
import { migrateStringQueriesToObjectQueries } from './grafanaTemplateVariableFns';
|
import { migrateStringQueriesToObjectQueries } from './grafanaTemplateVariableFns';
|
||||||
|
import { AzureMonitorQuery, AzureQueryType } from './types';
|
||||||
import { GrafanaTemplateVariableQuery } from './types/templateVariables';
|
import { GrafanaTemplateVariableQuery } from './types/templateVariables';
|
||||||
import messageFromError from './utils/messageFromError';
|
import messageFromError from './utils/messageFromError';
|
||||||
|
|
||||||
export class VariableSupport extends CustomVariableSupport<DataSource, AzureMonitorQuery> {
|
export class VariableSupport extends CustomVariableSupport<DataSource, AzureMonitorQuery> {
|
||||||
constructor(private readonly datasource: DataSource) {
|
constructor(private readonly datasource: DataSource) {
|
||||||
super();
|
super();
|
||||||
|
Reference in New Issue
Block a user