Azure Monitor: E2E Tests (#54619)
* Update credentials form with data-testids and aria-labels * Update gitignore * Add example dashboard * Stub out E2E test for creating ds and importing dashboard * Add component selectors * Remove subscription check temporarily * Appropriately set disabled prop * Fix lint issues * Update to use selectors and wait on subscriptions request * Add test for metrics panel - Add required selectors for resource picker and metrics query editor * Add logs and ARG basic query scenarios - More selector updates * Add E2E test for template variables - Tests advanced resource picker - Adds required selectors * Remove log and add annotation e2e test * Update test * Prettier/betterer updates - Remove gitignore change * Lint issues * Update betterer results * Lint issue and remove unneeded import * Don't print certain commands * Avoiding flakiness - Ensure code editor has sufficient time to load in ARG test - Avoid flakiness around correct template variable being selected by typing in resource name * Remove be.visible requirement * Update test * Update selector name * Reuse datasource * Fix datasource reuse and combine query tests * Remove import dashboard step as unneeded * Review - Randomise datasource name - Skip annotations test - Remove unused example dashboard * Update to ensure e2e test works in CI * Update e2e test - Update environment variables (process is not available in cypress) - Add wait on resource picker searches to avoid flakiness - Update subscription and resource group names * Update CODEOWNERS * Parse credentials in CI from outputs file * Update outputs file path * Fix selector * Undo selector change * Update e2e tests - Set default subscription - Fix datasource selection in variable editor - Fix resource picker search flakiness - Set subscription in ARG query test - Fix resource group selection - Update resource group * Review * Review 2
This commit is contained in:
@@ -0,0 +1,298 @@
|
||||
import { load } from 'js-yaml';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
import { e2e } from '@grafana/e2e';
|
||||
|
||||
import { selectors } from '../../public/app/plugins/datasource/grafana-azure-monitor-datasource/e2e/selectors';
|
||||
import {
|
||||
AzureDataSourceJsonData,
|
||||
AzureDataSourceSecureJsonData,
|
||||
AzureQueryType,
|
||||
} from '../../public/app/plugins/datasource/grafana-azure-monitor-datasource/types';
|
||||
|
||||
const provisioningPath = `../../provisioning/datasources/azmonitor-ds.yaml`;
|
||||
const e2eSelectors = e2e.getSelectors(selectors.components);
|
||||
|
||||
type AzureMonitorConfig = {
|
||||
secureJsonData: AzureDataSourceSecureJsonData;
|
||||
jsonData: AzureDataSourceJsonData;
|
||||
};
|
||||
|
||||
type AzureMonitorProvision = { datasources: AzureMonitorConfig[] };
|
||||
|
||||
const dataSourceName = `Azure Monitor E2E Tests - ${uuidv4()}`;
|
||||
|
||||
function provisionAzureMonitorDatasources(datasources: AzureMonitorProvision[]) {
|
||||
const datasource = datasources[0].datasources[0];
|
||||
|
||||
e2e()
|
||||
.intercept(/subscriptions/)
|
||||
.as('subscriptions');
|
||||
|
||||
e2e.flows.addDataSource({
|
||||
type: 'Azure Monitor',
|
||||
name: dataSourceName,
|
||||
form: () => {
|
||||
e2eSelectors.configEditor.azureCloud.input().find('input').type('Azure').type('{enter}');
|
||||
// We set the log value to false here to ensure that secrets aren't printed to logs
|
||||
e2eSelectors.configEditor.tenantID.input().find('input').type(datasource.jsonData.tenantId, { log: false });
|
||||
e2eSelectors.configEditor.clientID.input().find('input').type(datasource.jsonData.clientId, { log: false });
|
||||
e2eSelectors.configEditor.clientSecret
|
||||
.input()
|
||||
.find('input')
|
||||
.type(datasource.secureJsonData.clientSecret, { log: false });
|
||||
e2eSelectors.configEditor.loadSubscriptions.button().click().wait('@subscriptions').wait(500);
|
||||
e2eSelectors.configEditor.defaultSubscription.input().find('input').type('datasources{enter}');
|
||||
},
|
||||
expectedAlertMessage: 'Successfully connected to all Azure Monitor endpoints',
|
||||
});
|
||||
}
|
||||
|
||||
const addAzureMonitorVariable = (
|
||||
name: string,
|
||||
type: AzureQueryType,
|
||||
isFirst: boolean,
|
||||
options?: { subscription?: string; resourceGroup?: string; namespace?: string; resource?: string }
|
||||
) => {
|
||||
e2e.components.PageToolbar.item('Dashboard settings').click();
|
||||
e2e.components.Tab.title('Variables').click();
|
||||
if (isFirst) {
|
||||
e2e.pages.Dashboard.Settings.Variables.List.addVariableCTAV2().click();
|
||||
} else {
|
||||
e2e.pages.Dashboard.Settings.Variables.List.newButton().click();
|
||||
}
|
||||
e2e.pages.Dashboard.Settings.Variables.Edit.General.generalNameInputV2().clear().type(name);
|
||||
e2e.components.DataSourcePicker.inputV2().type(`${dataSourceName}{enter}`);
|
||||
e2eSelectors.variableEditor.queryType
|
||||
.input()
|
||||
.find('input')
|
||||
.type(`${type.replace('Azure', '').trim()}{enter}`);
|
||||
switch (type) {
|
||||
case AzureQueryType.ResourceGroupsQuery:
|
||||
e2eSelectors.variableEditor.subscription.input().find('input').type(`${options?.subscription}{enter}`);
|
||||
break;
|
||||
case AzureQueryType.NamespacesQuery:
|
||||
e2eSelectors.variableEditor.subscription.input().find('input').type(`${options?.subscription}{enter}`);
|
||||
e2eSelectors.variableEditor.resourceGroup.input().find('input').type(`${options?.resourceGroup}{enter}`);
|
||||
break;
|
||||
case AzureQueryType.ResourceNamesQuery:
|
||||
e2eSelectors.variableEditor.subscription.input().find('input').type(`${options?.subscription}{enter}`);
|
||||
e2eSelectors.variableEditor.resourceGroup.input().find('input').type(`${options?.resourceGroup}{enter}`);
|
||||
e2eSelectors.variableEditor.namespace.input().find('input').type(`${options?.namespace}{enter}`);
|
||||
break;
|
||||
case AzureQueryType.MetricNamesQuery:
|
||||
e2eSelectors.variableEditor.subscription.input().find('input').type(`${options?.subscription}{enter}`);
|
||||
e2eSelectors.variableEditor.resourceGroup.input().find('input').type(`${options?.resourceGroup}{enter}`);
|
||||
e2eSelectors.variableEditor.namespace.input().find('input').type(`${options?.namespace}{enter}`);
|
||||
e2eSelectors.variableEditor.resource.input().find('input').type(`${options?.resource}{enter}`);
|
||||
break;
|
||||
}
|
||||
e2e.pages.Dashboard.Settings.Variables.Edit.General.submitButton().click();
|
||||
e2e.components.PageToolbar.item('Go Back').click();
|
||||
};
|
||||
|
||||
e2e.scenario({
|
||||
describeName: 'Add Azure Monitor datasource',
|
||||
itName: 'fills out datasource connection configuration',
|
||||
scenario: () => {
|
||||
// This variable will be set in CI
|
||||
const CI = e2e.env('CI');
|
||||
if (CI) {
|
||||
e2e()
|
||||
.readFile('../../outputs.json')
|
||||
.then((outputs) => {
|
||||
provisionAzureMonitorDatasources([
|
||||
{
|
||||
datasources: [
|
||||
{
|
||||
jsonData: {
|
||||
cloudName: 'Azure',
|
||||
tenantId: outputs.tenantId,
|
||||
clientId: outputs.clientId,
|
||||
},
|
||||
secureJsonData: { clientSecret: outputs.clientSecret },
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
||||
});
|
||||
} else {
|
||||
e2e()
|
||||
.readFile(provisioningPath)
|
||||
.then((azMonitorProvision: string) => {
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
const yaml = load(azMonitorProvision) as AzureMonitorProvision;
|
||||
provisionAzureMonitorDatasources([yaml]);
|
||||
});
|
||||
}
|
||||
e2e.setScenarioContext({ addedDataSources: [] });
|
||||
},
|
||||
});
|
||||
|
||||
e2e.scenario({
|
||||
describeName: 'Create dashboard and add a panel for each query type',
|
||||
itName: 'create dashboard, add panel for metrics query, log analytics query, and ARG query',
|
||||
scenario: () => {
|
||||
e2e.flows.addDashboard({
|
||||
timeRange: {
|
||||
from: '2022-10-03 00:00:00',
|
||||
to: '2022-10-03 23:59:59',
|
||||
zone: 'Coordinated Universal Time',
|
||||
},
|
||||
});
|
||||
e2e.flows.addPanel({
|
||||
dataSourceName,
|
||||
visitDashboardAtStart: false,
|
||||
queriesForm: () => {
|
||||
e2eSelectors.queryEditor.resourcePicker.select.button().click();
|
||||
e2eSelectors.queryEditor.resourcePicker.search
|
||||
.input()
|
||||
.wait(100)
|
||||
.type('azmonmetricstest')
|
||||
.wait(500)
|
||||
.type('{enter}');
|
||||
e2e().contains('azmonmetricstest').click();
|
||||
e2eSelectors.queryEditor.resourcePicker.apply.button().click();
|
||||
e2e().contains('microsoft.storage/storageaccounts');
|
||||
e2eSelectors.queryEditor.metricsQueryEditor.metricName.input().find('input').type('Used capacity{enter}');
|
||||
},
|
||||
});
|
||||
e2e.components.PanelEditor.applyButton().click();
|
||||
e2e.flows.addPanel({
|
||||
dataSourceName,
|
||||
visitDashboardAtStart: false,
|
||||
queriesForm: () => {
|
||||
e2eSelectors.queryEditor.header.select().find('input').type('Logs{enter}');
|
||||
e2eSelectors.queryEditor.resourcePicker.select.button().click();
|
||||
e2eSelectors.queryEditor.resourcePicker.search
|
||||
.input()
|
||||
.wait(100)
|
||||
.type('azmonlogstest')
|
||||
.wait(500)
|
||||
.type('{enter}');
|
||||
e2e().contains('azmonlogstest').click();
|
||||
e2eSelectors.queryEditor.resourcePicker.apply.button().click();
|
||||
e2e.components.CodeEditor.container().type('AzureDiagnostics');
|
||||
e2eSelectors.queryEditor.logsQueryEditor.formatSelection.input().type('Time series{enter}');
|
||||
},
|
||||
});
|
||||
e2e.components.PanelEditor.applyButton().click();
|
||||
e2e.flows.addPanel({
|
||||
dataSourceName,
|
||||
visitDashboardAtStart: false,
|
||||
queriesForm: () => {
|
||||
e2eSelectors.queryEditor.header.select().find('input').type('Azure Resource Graph{enter}');
|
||||
e2e().wait(1000); // Need to wait for code editor to completely load
|
||||
e2e().get('[aria-label="Remove Primary Subscription"]').click();
|
||||
e2eSelectors.queryEditor.argsQueryEditor.subscriptions.input().find('input').type('datasources{enter}');
|
||||
e2e.components.CodeEditor.container().type(
|
||||
"Resources | where resourceGroup == 'cloud-plugins-e2e-test' | project name, resourceGroup"
|
||||
);
|
||||
e2e.components.PanelEditor.toggleTableView().click({ force: true });
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
e2e.scenario({
|
||||
describeName: 'Create dashboard with template variables',
|
||||
itName: 'creates a dashboard that includes a template variable',
|
||||
scenario: () => {
|
||||
e2e.flows.addDashboard({
|
||||
timeRange: {
|
||||
from: '2022-10-03 00:00:00',
|
||||
to: '2022-10-03 23:59:59',
|
||||
zone: 'Coordinated Universal Time',
|
||||
},
|
||||
});
|
||||
addAzureMonitorVariable('subscription', AzureQueryType.SubscriptionsQuery, true);
|
||||
addAzureMonitorVariable('resourceGroups', AzureQueryType.ResourceGroupsQuery, false, {
|
||||
subscription: '$subscription',
|
||||
});
|
||||
addAzureMonitorVariable('namespaces', AzureQueryType.NamespacesQuery, false, {
|
||||
subscription: '$subscription',
|
||||
resourceGroup: '$resourceGroups',
|
||||
});
|
||||
addAzureMonitorVariable('resource', AzureQueryType.ResourceNamesQuery, false, {
|
||||
subscription: '$subscription',
|
||||
resourceGroup: '$resourceGroups',
|
||||
namespace: '$namespace',
|
||||
});
|
||||
e2e.pages.Dashboard.SubMenu.submenuItemLabels('subscription').click();
|
||||
e2e.pages.Dashboard.SubMenu.submenuItemValueDropDownOptionTexts('grafanalabs-datasources-dev').click();
|
||||
e2e.pages.Dashboard.SubMenu.submenuItemLabels('resourceGroups').parent().find('button').click();
|
||||
e2e.pages.Dashboard.SubMenu.submenuItemLabels('resourceGroups')
|
||||
.parent()
|
||||
.find('input')
|
||||
.type('cloud-plugins-e2e-test{enter}');
|
||||
e2e.pages.Dashboard.SubMenu.submenuItemLabels('namespaces').parent().find('button').click();
|
||||
e2e.pages.Dashboard.SubMenu.submenuItemLabels('namespaces')
|
||||
.parent()
|
||||
.find('input')
|
||||
.type('microsoft.storage/storageaccounts{enter}');
|
||||
e2e.pages.Dashboard.SubMenu.submenuItemLabels('resource').parent().find('button').click();
|
||||
e2e.pages.Dashboard.SubMenu.submenuItemLabels('resource').parent().find('input').type('azmonmetricstest{enter}');
|
||||
e2e.flows.addPanel({
|
||||
dataSourceName,
|
||||
visitDashboardAtStart: false,
|
||||
queriesForm: () => {
|
||||
e2eSelectors.queryEditor.resourcePicker.select.button().click();
|
||||
e2eSelectors.queryEditor.resourcePicker.advanced.collapse().click();
|
||||
e2eSelectors.queryEditor.resourcePicker.advanced.subscription.input().find('input').type('$subscription');
|
||||
e2eSelectors.queryEditor.resourcePicker.advanced.resourceGroup.input().find('input').type('$resourceGroups');
|
||||
e2eSelectors.queryEditor.resourcePicker.advanced.namespace.input().find('input').type('$namespaces');
|
||||
e2eSelectors.queryEditor.resourcePicker.advanced.resource.input().find('input').type('$resource');
|
||||
e2eSelectors.queryEditor.resourcePicker.apply.button().click();
|
||||
e2eSelectors.queryEditor.metricsQueryEditor.metricName.input().find('input').type('Transactions{enter}');
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
e2e.scenario({
|
||||
describeName: 'Create dashboard with annotation',
|
||||
itName: 'creates a dashboard that includes an annotation',
|
||||
scenario: () => {
|
||||
e2e.flows.addDashboard({
|
||||
timeRange: {
|
||||
from: '2022-10-03 00:00:00',
|
||||
to: '2022-10-03 23:59:59',
|
||||
zone: 'Coordinated Universal Time',
|
||||
},
|
||||
});
|
||||
e2e.components.PageToolbar.item('Dashboard settings').click();
|
||||
e2e.components.Tab.title('Annotations').click();
|
||||
e2e.pages.Dashboard.Settings.Annotations.List.addAnnotationCTAV2().click();
|
||||
e2e.pages.Dashboard.Settings.Annotations.Settings.name().type('TestAnnotation');
|
||||
e2e.components.DataSourcePicker.inputV2().click().type(`${dataSourceName}{enter}`);
|
||||
e2eSelectors.queryEditor.resourcePicker.select.button().click();
|
||||
e2eSelectors.queryEditor.resourcePicker.search.input().type('azmonmetricstest');
|
||||
e2e().contains('azmonmetricstest').click();
|
||||
e2eSelectors.queryEditor.resourcePicker.apply.button().click();
|
||||
e2e().contains('microsoft.storage/storageaccounts');
|
||||
e2eSelectors.queryEditor.metricsQueryEditor.metricName.input().find('input').type('Transactions{enter}');
|
||||
e2e().get('table').contains('text').parent().find('input').click().type('Transactions (number){enter}');
|
||||
e2e.components.PageToolbar.item('Go Back').click();
|
||||
e2e.flows.addPanel({
|
||||
dataSourceName,
|
||||
visitDashboardAtStart: false,
|
||||
queriesForm: () => {
|
||||
e2eSelectors.queryEditor.resourcePicker.select.button().click();
|
||||
e2eSelectors.queryEditor.resourcePicker.search.input().type('azmonmetricstest');
|
||||
e2e().contains('azmonmetricstest').click();
|
||||
e2eSelectors.queryEditor.resourcePicker.apply.button().click();
|
||||
e2e().contains('microsoft.storage/storageaccounts');
|
||||
e2eSelectors.queryEditor.metricsQueryEditor.metricName.input().find('input').type('Used capacity{enter}');
|
||||
},
|
||||
});
|
||||
},
|
||||
skipScenario: true,
|
||||
});
|
||||
|
||||
e2e.scenario({
|
||||
describeName: 'Remove datasource',
|
||||
itName: 'remove azure monitor datasource',
|
||||
scenario: () => {
|
||||
e2e.flows.deleteDataSource({ name: dataSourceName, id: '', quick: true });
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user