From 92454e65c3ee2e667206da129d2e9c9d0d307d8d Mon Sep 17 00:00:00 2001 From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com> Date: Wed, 10 May 2023 13:01:00 +0100 Subject: [PATCH] [v10.0.x] AzureMonitor: Add health check retry logic (#68161) AzureMonitor: Bump credential wait time (#68120) Bump credential wait time as 15s seems too short (cherry picked from commit 0d3a78d86dd84ed95024da0a4ada6bc2b0f7af6a) Co-authored-by: Andreas Christou --- e2e/cloud-plugins-suite/azure-monitor.spec.ts | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/e2e/cloud-plugins-suite/azure-monitor.spec.ts b/e2e/cloud-plugins-suite/azure-monitor.spec.ts index 5028371a299..98a2e0de423 100644 --- a/e2e/cloud-plugins-suite/azure-monitor.spec.ts +++ b/e2e/cloud-plugins-suite/azure-monitor.spec.ts @@ -1,3 +1,4 @@ +import { Interception } from 'cypress/types/net-stubbing'; import { load } from 'js-yaml'; import { v4 as uuidv4 } from 'uuid'; @@ -22,6 +23,20 @@ type AzureMonitorProvision = { datasources: AzureMonitorConfig[] }; const dataSourceName = `Azure Monitor E2E Tests - ${uuidv4()}`; +const maxRetryCount = 3; + +Cypress.Commands.add('checkHealthRetryable', function (fn: Function, retryCount: number) { + cy.then(() => { + const result = fn(++retryCount); + result.then((res: Interception) => { + if (retryCount < maxRetryCount && res.response.statusCode !== 200) { + cy.wait(20000); + cy.checkHealthRetryable(fn, retryCount); + } + }); + }); +}); + function provisionAzureMonitorDatasources(datasources: AzureMonitorProvision[]) { const datasource = datasources[0].datasources[0]; @@ -43,8 +58,11 @@ function provisionAzureMonitorDatasources(datasources: AzureMonitorProvision[]) .type(datasource.secureJsonData.clientSecret, { log: false }); e2eSelectors.configEditor.loadSubscriptions.button().click().wait('@subscriptions').wait(500); e2eSelectors.configEditor.defaultSubscription.input().find('input').type('datasources{enter}'); - // Wait for 15s so that credentials are ready. 5s has been tested locally before and seemed insufficient. - e2e().wait(15000); + + // We can do this because awaitHealth is set to true so @health is defined + cy.checkHealthRetryable(() => { + return e2e.pages.DataSource.saveAndTest().click().wait('@health'); + }, 0); }, expectedAlertMessage: 'Successfully connected to all Azure Monitor endpoints', // Reduce the timeout from 30s to error faster when an invalid alert message is presented