Skip to content

Commit 322c9df

Browse files
crespocarlosCAWilson94
authored andcommitted
[APM] Migrate service group alert test (elastic#200789)
closes elastic#198982 ## Summary Migrates a test covering alerts on service group feature. It's possible to migrate it with `alertingApi` service. ### How to test - Serverless ``` node scripts/functional_tests_server --config x-pack/test/api_integration/deployment_agnostic/configs/serverless/oblt.serverless.config.ts node scripts/functional_test_runner --config x-pack/test/api_integration/deployment_agnostic/configs/serverless/oblt.serverless.config.ts --grep="APM" ``` It's recommended to be run against [MKI](https://github.com/crespocarlos/kibana/blob/main/x-pack/test_serverless/README.md#run-tests-on-mki) - Stateful ``` node scripts/functional_tests_server --config x-pack/test/api_integration/deployment_agnostic/configs/stateful/oblt.stateful.config.ts node scripts/functional_test_runner --config x-pack/test/api_integration/deployment_agnostic/configs/stateful/oblt.stateful.config.ts --grep="APM" ``` - [ ] ~(OPTIONAL, only if a test has been unskipped) Run flaky test suite~ - [x] local run for serverless - [x] local run for stateful - [x] MKI run for serverless
1 parent b973a2a commit 322c9df

File tree

4 files changed

+53
-238
lines changed

4 files changed

+53
-238
lines changed

x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/service_groups/service_group_count/service_group_count.spec.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,32 @@
66
*/
77
import expect from '@kbn/expect';
88
import type { ApmSynthtraceEsClient } from '@kbn/apm-synthtrace';
9+
import type { RoleCredentials } from '@kbn/ftr-common-functional-services';
10+
import { ApmRuleType } from '@kbn/rule-data-utils';
11+
import { AggregationType } from '@kbn/apm-plugin/common/rules/apm_rule_types';
912
import type { DeploymentAgnosticFtrProviderContext } from '../../../../../ftr_provider_context';
1013
import {
1114
createServiceGroupApi,
1215
deleteAllServiceGroups,
1316
getServiceGroupCounts,
1417
} from '../service_groups_api_methods';
1518
import { generateData } from './generate_data';
19+
import { APM_ACTION_VARIABLE_INDEX, APM_ALERTS_INDEX } from '../../alerts/helpers/alerting_helper';
1620

1721
export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderContext) {
1822
const synthtrace = getService('synthtrace');
1923
const apmApiClient = getService('apmApi');
24+
const alertingApi = getService('alertingApi');
25+
const samlAuth = getService('samlAuth');
26+
2027
const start = Date.now() - 24 * 60 * 60 * 1000;
2128
const end = Date.now();
2229

2330
describe('Service group counts', () => {
2431
let synthbeansServiceGroupId: string;
2532
let opbeansServiceGroupId: string;
2633
let apmSynthtraceEsClient: ApmSynthtraceEsClient;
34+
let roleAuthc: RoleCredentials;
2735

2836
before(async () => {
2937
apmSynthtraceEsClient = await synthtrace.createApmSynthtraceEsClient();
@@ -59,5 +67,50 @@ export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderCon
5967
expect(response.body[synthbeansServiceGroupId]).to.have.property('services', 2);
6068
expect(response.body[opbeansServiceGroupId]).to.have.property('services', 1);
6169
});
70+
71+
describe('with alerts', () => {
72+
let ruleId: string;
73+
74+
before(async () => {
75+
roleAuthc = await samlAuth.createM2mApiKeyWithRoleScope('admin');
76+
const createdRule = await alertingApi.createRule({
77+
name: 'Latency threshold | synth-go',
78+
params: {
79+
serviceName: 'synth-go',
80+
transactionType: undefined,
81+
windowSize: 5,
82+
windowUnit: 'h',
83+
threshold: 100,
84+
aggregationType: AggregationType.Avg,
85+
environment: 'testing',
86+
},
87+
ruleTypeId: ApmRuleType.TransactionDuration,
88+
consumer: 'apm',
89+
roleAuthc,
90+
});
91+
92+
ruleId = createdRule.id;
93+
await alertingApi.waitForAlertInIndex({ ruleId, indexName: APM_ALERTS_INDEX });
94+
});
95+
96+
after(async () => {
97+
await alertingApi.cleanUpAlerts({
98+
roleAuthc,
99+
ruleId,
100+
alertIndexName: APM_ALERTS_INDEX,
101+
connectorIndexName: APM_ACTION_VARIABLE_INDEX,
102+
consumer: 'apm',
103+
});
104+
await samlAuth.invalidateM2mApiKeyWithRoleScope(roleAuthc);
105+
});
106+
107+
it('returns the correct number of alerts', async () => {
108+
const response = await getServiceGroupCounts(apmApiClient);
109+
expect(response.status).to.be(200);
110+
expect(Object.keys(response.body).length).to.be(2);
111+
expect(response.body[synthbeansServiceGroupId]).to.have.property('alerts', 1);
112+
expect(response.body[opbeansServiceGroupId]).to.have.property('alerts', 0);
113+
});
114+
});
62115
});
63116
}

x-pack/test/apm_api_integration/tests/service_groups/service_group_count/generate_data.ts

Lines changed: 0 additions & 74 deletions
This file was deleted.

x-pack/test/apm_api_integration/tests/service_groups/service_group_count/service_group_count.spec.ts

Lines changed: 0 additions & 98 deletions
This file was deleted.

x-pack/test/apm_api_integration/tests/service_groups/service_groups_api_methods.ts

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)