Skip to content

Commit

Permalink
[APM] Migrate service group alert test (elastic#200789)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
crespocarlos authored and paulinashakirova committed Nov 26, 2024
1 parent 9f680c8 commit 24c784f
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 238 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,32 @@
*/
import expect from '@kbn/expect';
import type { ApmSynthtraceEsClient } from '@kbn/apm-synthtrace';
import type { RoleCredentials } from '@kbn/ftr-common-functional-services';
import { ApmRuleType } from '@kbn/rule-data-utils';
import { AggregationType } from '@kbn/apm-plugin/common/rules/apm_rule_types';
import type { DeploymentAgnosticFtrProviderContext } from '../../../../../ftr_provider_context';
import {
createServiceGroupApi,
deleteAllServiceGroups,
getServiceGroupCounts,
} from '../service_groups_api_methods';
import { generateData } from './generate_data';
import { APM_ACTION_VARIABLE_INDEX, APM_ALERTS_INDEX } from '../../alerts/helpers/alerting_helper';

export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderContext) {
const synthtrace = getService('synthtrace');
const apmApiClient = getService('apmApi');
const alertingApi = getService('alertingApi');
const samlAuth = getService('samlAuth');

const start = Date.now() - 24 * 60 * 60 * 1000;
const end = Date.now();

describe('Service group counts', () => {
let synthbeansServiceGroupId: string;
let opbeansServiceGroupId: string;
let apmSynthtraceEsClient: ApmSynthtraceEsClient;
let roleAuthc: RoleCredentials;

before(async () => {
apmSynthtraceEsClient = await synthtrace.createApmSynthtraceEsClient();
Expand Down Expand Up @@ -59,5 +67,50 @@ export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderCon
expect(response.body[synthbeansServiceGroupId]).to.have.property('services', 2);
expect(response.body[opbeansServiceGroupId]).to.have.property('services', 1);
});

describe('with alerts', () => {
let ruleId: string;

before(async () => {
roleAuthc = await samlAuth.createM2mApiKeyWithRoleScope('admin');
const createdRule = await alertingApi.createRule({
name: 'Latency threshold | synth-go',
params: {
serviceName: 'synth-go',
transactionType: undefined,
windowSize: 5,
windowUnit: 'h',
threshold: 100,
aggregationType: AggregationType.Avg,
environment: 'testing',
},
ruleTypeId: ApmRuleType.TransactionDuration,
consumer: 'apm',
roleAuthc,
});

ruleId = createdRule.id;
await alertingApi.waitForAlertInIndex({ ruleId, indexName: APM_ALERTS_INDEX });
});

after(async () => {
await alertingApi.cleanUpAlerts({
roleAuthc,
ruleId,
alertIndexName: APM_ALERTS_INDEX,
connectorIndexName: APM_ACTION_VARIABLE_INDEX,
consumer: 'apm',
});
await samlAuth.invalidateM2mApiKeyWithRoleScope(roleAuthc);
});

it('returns the correct number of alerts', async () => {
const response = await getServiceGroupCounts(apmApiClient);
expect(response.status).to.be(200);
expect(Object.keys(response.body).length).to.be(2);
expect(response.body[synthbeansServiceGroupId]).to.have.property('alerts', 1);
expect(response.body[opbeansServiceGroupId]).to.have.property('alerts', 0);
});
});
});
}

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 24c784f

Please sign in to comment.