Azure Monitor: Add Resource Picker for Metrics Queries (#49029)

This commit is contained in:
Sarah Zinger 2022-05-17 12:53:39 -04:00 committed by GitHub
parent acd31ae9f0
commit c652849303
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 39 deletions

View File

@ -28,7 +28,9 @@ describe('Azure Monitor QueryEditor', () => {
}; };
render(<QueryEditor query={mockQuery} datasource={mockDatasource} onChange={() => {}} onRunQuery={() => {}} />); render(<QueryEditor query={mockQuery} datasource={mockDatasource} onChange={() => {}} onRunQuery={() => {}} />);
await waitFor(() => expect(screen.getByTestId('azure-monitor-metrics-query-editor')).toBeInTheDocument()); await waitFor(() =>
expect(screen.getByTestId('azure-monitor-metrics-query-editor-with-resource-picker')).toBeInTheDocument()
);
}); });
it('renders the Logs query editor when the query type is Logs', async () => { it('renders the Logs query editor when the query type is Logs', async () => {
@ -60,35 +62,14 @@ describe('Azure Monitor QueryEditor', () => {
it('displays error messages from frontend Azure calls', async () => { it('displays error messages from frontend Azure calls', async () => {
const mockDatasource = createMockDatasource(); const mockDatasource = createMockDatasource();
mockDatasource.azureMonitorDatasource.getSubscriptions = jest.fn().mockRejectedValue(invalidNamespaceError()); mockDatasource.azureMonitorDatasource.getMetricNamespaces = jest.fn().mockRejectedValue(invalidNamespaceError());
render( render(
<QueryEditor query={createMockQuery()} datasource={mockDatasource} onChange={() => {}} onRunQuery={() => {}} /> <QueryEditor query={createMockQuery()} datasource={mockDatasource} onChange={() => {}} onRunQuery={() => {}} />
); );
await waitFor(() => expect(screen.getByTestId('azure-monitor-query-editor')).toBeInTheDocument());
expect(screen.getByText("The resource namespace 'grafanadev' is invalid.")).toBeInTheDocument();
});
it('renders the new query editor for metrics when enabled with a feature toggle', async () => {
const originalConfigValue = config.featureToggles.azureMonitorResourcePickerForMetrics;
// To do this irl go to custom.ini file and add resourcePickerForMetrics = true under [feature_toggles]
config.featureToggles.azureMonitorResourcePickerForMetrics = true;
const mockDatasource = createMockDatasource();
const mockQuery = {
...createMockQuery(),
queryType: AzureQueryType.AzureMonitor,
};
render(<QueryEditor query={mockQuery} datasource={mockDatasource} onChange={() => {}} onRunQuery={() => {}} />);
await waitFor(() => await waitFor(() =>
expect(screen.getByTestId('azure-monitor-metrics-query-editor-with-resource-picker')).toBeInTheDocument() expect(screen.getByTestId('azure-monitor-metrics-query-editor-with-resource-picker')).toBeInTheDocument()
); );
expect(screen.getByText('An error occurred while requesting metadata from Azure Monitor')).toBeInTheDocument();
// reset config to not impact future tests
config.featureToggles.azureMonitorResourcePickerForMetrics = originalConfigValue;
}); });
it('should render the experimental QueryHeader when feature toggle is enabled', async () => { it('should render the experimental QueryHeader when feature toggle is enabled', async () => {

View File

@ -16,7 +16,6 @@ import {
import useLastError from '../../utils/useLastError'; import useLastError from '../../utils/useLastError';
import ArgQueryEditor from '../ArgQueryEditor'; import ArgQueryEditor from '../ArgQueryEditor';
import LogsQueryEditor from '../LogsQueryEditor'; import LogsQueryEditor from '../LogsQueryEditor';
import MetricsQueryEditor from '../MetricsQueryEditor';
import NewMetricsQueryEditor from '../NewMetricsQueryEditor/MetricsQueryEditor'; import NewMetricsQueryEditor from '../NewMetricsQueryEditor/MetricsQueryEditor';
import { QueryHeader } from '../QueryHeader'; import { QueryHeader } from '../QueryHeader';
import { Space } from '../Space'; import { Space } from '../Space';
@ -102,7 +101,6 @@ const EditorForQueryType: React.FC<EditorForQueryTypeProps> = ({
}) => { }) => {
switch (query.queryType) { switch (query.queryType) {
case AzureQueryType.AzureMonitor: case AzureQueryType.AzureMonitor:
if (config.featureToggles.azureMonitorResourcePickerForMetrics) {
return ( return (
<NewMetricsQueryEditor <NewMetricsQueryEditor
data={data} data={data}
@ -113,18 +111,6 @@ const EditorForQueryType: React.FC<EditorForQueryTypeProps> = ({
setError={setError} setError={setError}
/> />
); );
}
return (
<MetricsQueryEditor
data={data}
subscriptionId={subscriptionId}
query={query}
datasource={datasource}
onChange={onChange}
variableOptionGroup={variableOptionGroup}
setError={setError}
/>
);
case AzureQueryType.LogAnalytics: case AzureQueryType.LogAnalytics:
return ( return (