Skip to content

Commit

Permalink
[8.x] [APM] Fix transactions test (elastic#201755) (elastic#202017)
Browse files Browse the repository at this point in the history
# Backport

This will backport the following commits from `main` to `8.x`:
- [[APM] Fix transactions test
(elastic#201755)](elastic#201755)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Sergi
Romeu","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-27T15:51:23Z","message":"[APM]
Fix transactions test (elastic#201755)\n\n## Summary\n\nCloses elastic#201531\n\nThis
PR fixes the skipped test for MKI `Transaction groups alerts when\ndata
is loaded with avg transaction duration alerts returns the
correct\nnumber of alert counts`
in\n`x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/transactions/transactions_groups_alerts.spec.ts`","sha":"662052919c8663d76a93cce8fe0df687fff92a15","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","backport:prev-minor","Team:obs-ux-infra_services"],"title":"[APM]
Fix transactions
test","number":201755,"url":"https://github.com/elastic/kibana/pull/201755","mergeCommit":{"message":"[APM]
Fix transactions test (elastic#201755)\n\n## Summary\n\nCloses elastic#201531\n\nThis
PR fixes the skipped test for MKI `Transaction groups alerts when\ndata
is loaded with avg transaction duration alerts returns the
correct\nnumber of alert counts`
in\n`x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/transactions/transactions_groups_alerts.spec.ts`","sha":"662052919c8663d76a93cce8fe0df687fff92a15"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/201755","number":201755,"mergeCommit":{"message":"[APM]
Fix transactions test (elastic#201755)\n\n## Summary\n\nCloses elastic#201531\n\nThis
PR fixes the skipped test for MKI `Transaction groups alerts when\ndata
is loaded with avg transaction duration alerts returns the
correct\nnumber of alert counts`
in\n`x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/transactions/transactions_groups_alerts.spec.ts`","sha":"662052919c8663d76a93cce8fe0df687fff92a15"}}]}]
BACKPORT-->

Co-authored-by: Sergi Romeu <[email protected]>
  • Loading branch information
kibanamachine and rmyz authored Nov 27, 2024
1 parent 0461ee3 commit 1c2c65f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -75,18 +83,16 @@ 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');
const serviceGoDevInstance = apm
.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) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
{
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }))
Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit 1c2c65f

Please sign in to comment.