Skip to content

Commit

Permalink
[8.x] [APM] Migrate service group alert test (elastic#200789) (elasti…
Browse files Browse the repository at this point in the history
…c#200894)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[APM] Migrate service group alert test
(elastic#200789)](elastic#200789)

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

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

<!--BACKPORT [{"author":{"name":"Carlos
Crespo","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-20T10:58:45Z","message":"[APM]
Migrate service group alert test (elastic#200789)\n\ncloses
https://github.com/elastic/kibana/issues/198982\r\n\r\n##
Summary\r\n\r\nMigrates a test covering alerts on service group feature.
It's possible\r\nto migrate it with `alertingApi`
service.\r\n\r\n\r\n### How to test\r\n\r\n-
Serverless\r\n\r\n```\r\nnode scripts/functional_tests_server --config
x-pack/test/api_integration/deployment_agnostic/configs/serverless/oblt.serverless.config.ts\r\nnode
scripts/functional_test_runner --config
x-pack/test/api_integration/deployment_agnostic/configs/serverless/oblt.serverless.config.ts
--grep=\"APM\"\r\n```\r\n\r\nIt's recommended to be run
against\r\n[MKI](https://github.com/crespocarlos/kibana/blob/main/x-pack/test_serverless/README.md#run-tests-on-mki)\r\n\r\n-
Stateful\r\n```\r\nnode scripts/functional_tests_server --config
x-pack/test/api_integration/deployment_agnostic/configs/stateful/oblt.stateful.config.ts\r\nnode
scripts/functional_test_runner --config
x-pack/test/api_integration/deployment_agnostic/configs/stateful/oblt.stateful.config.ts
--grep=\"APM\"\r\n```\r\n\r\n- [ ] ~(OPTIONAL, only if a test has been
unskipped) Run flaky test\r\nsuite~\r\n- [x] local run for
serverless\r\n- [x] local run for stateful\r\n- [x] MKI run for
serverless","sha":"8ba6839715bcd69440ca9dc5be448bc5e95b4475","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","backport:prev-minor","ci:project-deploy-observability","Team:obs-ux-infra_services"],"title":"[APM]
Migrate service group alert
test","number":200789,"url":"https://github.com/elastic/kibana/pull/200789","mergeCommit":{"message":"[APM]
Migrate service group alert test (elastic#200789)\n\ncloses
https://github.com/elastic/kibana/issues/198982\r\n\r\n##
Summary\r\n\r\nMigrates a test covering alerts on service group feature.
It's possible\r\nto migrate it with `alertingApi`
service.\r\n\r\n\r\n### How to test\r\n\r\n-
Serverless\r\n\r\n```\r\nnode scripts/functional_tests_server --config
x-pack/test/api_integration/deployment_agnostic/configs/serverless/oblt.serverless.config.ts\r\nnode
scripts/functional_test_runner --config
x-pack/test/api_integration/deployment_agnostic/configs/serverless/oblt.serverless.config.ts
--grep=\"APM\"\r\n```\r\n\r\nIt's recommended to be run
against\r\n[MKI](https://github.com/crespocarlos/kibana/blob/main/x-pack/test_serverless/README.md#run-tests-on-mki)\r\n\r\n-
Stateful\r\n```\r\nnode scripts/functional_tests_server --config
x-pack/test/api_integration/deployment_agnostic/configs/stateful/oblt.stateful.config.ts\r\nnode
scripts/functional_test_runner --config
x-pack/test/api_integration/deployment_agnostic/configs/stateful/oblt.stateful.config.ts
--grep=\"APM\"\r\n```\r\n\r\n- [ ] ~(OPTIONAL, only if a test has been
unskipped) Run flaky test\r\nsuite~\r\n- [x] local run for
serverless\r\n- [x] local run for stateful\r\n- [x] MKI run for
serverless","sha":"8ba6839715bcd69440ca9dc5be448bc5e95b4475"}},"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/200789","number":200789,"mergeCommit":{"message":"[APM]
Migrate service group alert test (elastic#200789)\n\ncloses
https://github.com/elastic/kibana/issues/198982\r\n\r\n##
Summary\r\n\r\nMigrates a test covering alerts on service group feature.
It's possible\r\nto migrate it with `alertingApi`
service.\r\n\r\n\r\n### How to test\r\n\r\n-
Serverless\r\n\r\n```\r\nnode scripts/functional_tests_server --config
x-pack/test/api_integration/deployment_agnostic/configs/serverless/oblt.serverless.config.ts\r\nnode
scripts/functional_test_runner --config
x-pack/test/api_integration/deployment_agnostic/configs/serverless/oblt.serverless.config.ts
--grep=\"APM\"\r\n```\r\n\r\nIt's recommended to be run
against\r\n[MKI](https://github.com/crespocarlos/kibana/blob/main/x-pack/test_serverless/README.md#run-tests-on-mki)\r\n\r\n-
Stateful\r\n```\r\nnode scripts/functional_tests_server --config
x-pack/test/api_integration/deployment_agnostic/configs/stateful/oblt.stateful.config.ts\r\nnode
scripts/functional_test_runner --config
x-pack/test/api_integration/deployment_agnostic/configs/stateful/oblt.stateful.config.ts
--grep=\"APM\"\r\n```\r\n\r\n- [ ] ~(OPTIONAL, only if a test has been
unskipped) Run flaky test\r\nsuite~\r\n- [x] local run for
serverless\r\n- [x] local run for stateful\r\n- [x] MKI run for
serverless","sha":"8ba6839715bcd69440ca9dc5be448bc5e95b4475"}}]}]
BACKPORT-->

Co-authored-by: Carlos Crespo <[email protected]>
  • Loading branch information
kibanamachine and crespocarlos authored Nov 20, 2024
1 parent 336e6fe commit 4bbe24c
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 4bbe24c

Please sign in to comment.