From 662052919c8663d76a93cce8fe0df687fff92a15 Mon Sep 17 00:00:00 2001 From: Sergi Romeu Date: Wed, 27 Nov 2024 16:51:23 +0100 Subject: [PATCH] [APM] Fix transactions test (#201755) ## Summary Closes #201531 This PR fixes the skipped test for MKI `Transaction groups alerts when data is loaded with avg transaction duration alerts returns the correct number of alert counts` in `x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/transactions/transactions_groups_alerts.spec.ts` --- .../observability/apm/transactions/latency.spec.ts | 12 +++++++++--- .../transactions/transactions_groups_alerts.spec.ts | 11 ++++++++--- .../deployment_agnostic/services/alerting_api.ts | 6 +++--- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/transactions/latency.spec.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/transactions/latency.spec.ts index f369bc63ca4ef..df72ca433340c 100644 --- a/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/transactions/latency.spec.ts +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/transactions/latency.spec.ts @@ -58,6 +58,14 @@ export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderCon } describe('Latency', () => { + let apmSynthtraceEsClient: ApmSynthtraceEsClient; + + before(async () => { + apmSynthtraceEsClient = await synthtrace.createApmSynthtraceEsClient(); + }); + + after(() => apmSynthtraceEsClient.clean()); + describe('when data is not loaded ', () => { it('handles the empty state', async () => { const response = await fetchLatencyCharts(); @@ -75,10 +83,8 @@ export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderCon const GO_DEV_RATE = 20; const GO_PROD_DURATION = 1000; const GO_DEV_DURATION = 500; - let apmSynthtraceEsClient: ApmSynthtraceEsClient; before(async () => { - apmSynthtraceEsClient = await synthtrace.createApmSynthtraceEsClient(); const serviceGoProdInstance = apm .service({ name: serviceName, environment: 'production', agentName: 'go' }) .instance('instance-a'); @@ -86,7 +92,7 @@ export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderCon .service({ name: serviceName, environment: 'development', agentName: 'go' }) .instance('instance-b'); - await apmSynthtraceEsClient.index([ + return apmSynthtraceEsClient.index([ timerange(start, end) .ratePerMinute(GO_PROD_RATE) .generator((timestamp) => diff --git a/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/transactions/transactions_groups_alerts.spec.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/transactions/transactions_groups_alerts.spec.ts index 07b19ecc0b2a5..7fd74d0efc6b6 100644 --- a/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/transactions/transactions_groups_alerts.spec.ts +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/transactions/transactions_groups_alerts.spec.ts @@ -74,9 +74,6 @@ export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderCon } describe('Transaction groups alerts', function () { - // fails on MKI, see https://github.com/elastic/kibana/issues/201531 - this.tags(['failsOnMKI']); - describe('when data is loaded', () => { const transactions = [ { @@ -111,6 +108,7 @@ export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderCon before(async () => { roleAuthc = await samlAuth.createM2mApiKeyWithRoleScope('admin'); apmSynthtraceEsClient = await synthtrace.createApmSynthtraceEsClient(); + await apmSynthtraceEsClient.clean(); const serviceGoProdInstance = apm .service({ name: serviceName, environment: 'production', agentName: 'go' }) .instance('instance-a'); @@ -153,6 +151,13 @@ export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderCon let alerts: Alerts; before(async () => { + await alertingApi.cleanUpAlerts({ + alertIndexName: APM_ALERTS_INDEX, + connectorIndexName: APM_ACTION_VARIABLE_INDEX, + consumer: 'apm', + roleAuthc, + }); + const createdRule = await alertingApi.createRule({ name: `Latency threshold | ${serviceName}`, params: { diff --git a/x-pack/test/api_integration/deployment_agnostic/services/alerting_api.ts b/x-pack/test/api_integration/deployment_agnostic/services/alerting_api.ts index ee1047d6024ca..d6660581938fa 100644 --- a/x-pack/test/api_integration/deployment_agnostic/services/alerting_api.ts +++ b/x-pack/test/api_integration/deployment_agnostic/services/alerting_api.ts @@ -1141,7 +1141,7 @@ export function AlertingApiProvider({ getService }: DeploymentAgnosticFtrProvide .set(samlAuth.getInternalRequestHeader()); }, - async deleteRules({ roleAuthc, filter }: { roleAuthc: RoleCredentials; filter: string }) { + async deleteRules({ roleAuthc, filter = '' }: { roleAuthc: RoleCredentials; filter?: string }) { const response = await this.searchRules(roleAuthc, filter); return Promise.all( response.body.data.map((rule: any) => this.deleteRuleById({ roleAuthc, ruleId: rule.id })) @@ -1186,14 +1186,14 @@ export function AlertingApiProvider({ getService }: DeploymentAgnosticFtrProvide connectorIndexName, }: { roleAuthc: RoleCredentials; - ruleId: string; + ruleId?: string; consumer?: string; alertIndexName?: string; connectorIndexName?: string; }) { return Promise.allSettled([ // Delete the rule by ID - this.deleteRuleById({ roleAuthc, ruleId }), + ruleId ? this.deleteRuleById({ roleAuthc, ruleId }) : this.deleteRules({ roleAuthc }), // Delete all documents in the alert index if specified alertIndexName ? es.deleteByQuery({