Skip to content

Commit

Permalink
[APM] Fix transactions test (elastic#201755)
Browse files Browse the repository at this point in the history
## Summary

Closes elastic#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`
  • Loading branch information
rmyz authored Nov 27, 2024
1 parent eb87889 commit 6620529
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 6620529

Please sign in to comment.