Skip to content

Commit

Permalink
[APM] Migrate apm alerts tests to deployment agnostic (#199097)
Browse files Browse the repository at this point in the history
## Summary

Closes [#198959](#198959)
Part of #193245

This PR contains the changes to migrate `alerts` test folder to
Deployment-agnostic testing strategy.
It also fixes a bug when filtering alerts by
`kibana.alert.rule.producer`. On serverless ,the producer is
`observability`, not `apm`

### 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)
- This PR won't pass on MKI while the instance is not created using the
`kibana.alert.rule.producer` fix from this PR

- 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"
```

---------

Co-authored-by: kibanamachine <[email protected]>
Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
3 people authored Nov 12, 2024
1 parent 93d7044 commit fb666aa
Show file tree
Hide file tree
Showing 30 changed files with 2,046 additions and 1,670 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -1190,6 +1190,7 @@ x-pack/test_serverless/**/test_suites/observability/ai_assistant @elastic/obs-ai
/x-pack/plugins/observability_solution/infra/server/usage @elastic/obs-ux-infra_services-team
/x-pack/plugins/observability_solution/infra/server/utils @elastic/obs-ux-infra_services-team
/x-pack/test/api_integration/deployment_agnostic/apis/observability/infra @elastic/obs-ux-logs-team
/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm @elastic/obs-ux-logs-team

## Logs UI code exceptions -> @elastic/obs-ux-logs-team
/x-pack/test_serverless/functional/page_objects/svl_oblt_onboarding_stream_log_file.ts @elastic/obs-ux-logs-team
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
*/
import datemath from '@elastic/datemath';
import { ElasticsearchClient, Logger } from '@kbn/core/server';
import { rangeQuery, ScopedAnnotationsClient } from '@kbn/observability-plugin/server';
import { rangeQuery, ScopedAnnotationsClient, termsQuery } from '@kbn/observability-plugin/server';
import {
ALERT_RULE_PRODUCER,
ALERT_STATUS,
ALERT_STATUS_ACTIVE,
} from '@kbn/rule-registry-plugin/common/technical_rule_data_field_names';
import * as t from 'io-ts';
import { observabilityFeatureId } from '@kbn/observability-shared-plugin/common';
import { ENVIRONMENT_ALL } from '../../../../common/environment_filter_values';
import { Environment } from '../../../../common/environment_rt';
import { SERVICE_NAME } from '../../../../common/es_fields/apm';
Expand Down Expand Up @@ -139,7 +140,7 @@ export async function getApmServiceSummary({
query: {
bool: {
filter: [
...termQuery(ALERT_RULE_PRODUCER, 'apm'),
...termsQuery(ALERT_RULE_PRODUCER, 'apm', observabilityFeatureId),
...termQuery(ALERT_STATUS, ALERT_STATUS_ACTIVE),
...rangeQuery(start, end),
...termQuery(SERVICE_NAME, serviceName),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
* 2.0.
*/

import { kqlQuery } from '@kbn/observability-plugin/server';
import { ALERT_RULE_PRODUCER, ALERT_STATUS } from '@kbn/rule-data-utils';
import { kqlQuery, termQuery, termsQuery } from '@kbn/observability-plugin/server';
import { ALERT_RULE_PRODUCER, ALERT_STATUS, ALERT_STATUS_ACTIVE } from '@kbn/rule-data-utils';
import { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/types';
import { Logger } from '@kbn/core/server';
import { observabilityFeatureId } from '@kbn/observability-shared-plugin/common';
import { ApmPluginRequestHandlerContext } from '../typings';
import { SavedServiceGroup } from '../../../common/service_groups';
import { ApmAlertsClient } from '../../lib/helpers/get_apm_alerts_client';
Expand Down Expand Up @@ -42,8 +43,8 @@ export async function getServiceGroupAlerts({
query: {
bool: {
filter: [
{ term: { [ALERT_RULE_PRODUCER]: 'apm' } },
{ term: { [ALERT_STATUS]: 'active' } },
...termsQuery(ALERT_RULE_PRODUCER, 'apm', observabilityFeatureId),
...termQuery(ALERT_STATUS, ALERT_STATUS_ACTIVE),
],
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@
* 2.0.
*/

import { kqlQuery, termQuery, rangeQuery, wildcardQuery } from '@kbn/observability-plugin/server';
import {
kqlQuery,
termQuery,
rangeQuery,
wildcardQuery,
termsQuery,
} from '@kbn/observability-plugin/server';
import {
ALERT_RULE_PRODUCER,
ALERT_STATUS,
ALERT_STATUS_ACTIVE,
ALERT_RULE_PARAMETERS,
} from '@kbn/rule-data-utils';
import { observabilityFeatureId } from '@kbn/observability-shared-plugin/common';
import { SERVICE_NAME, TRANSACTION_NAME, TRANSACTION_TYPE } from '../../../common/es_fields/apm';
import { LatencyAggregationType } from '../../../common/latency_aggregation_types';
import { AggregationType } from '../../../common/rules/apm_rule_types';
Expand Down Expand Up @@ -59,7 +66,7 @@ export async function getServiceTransactionGroupsAlerts({
query: {
bool: {
filter: [
...termQuery(ALERT_RULE_PRODUCER, 'apm'),
...termsQuery(ALERT_RULE_PRODUCER, 'apm', observabilityFeatureId),
...termQuery(ALERT_STATUS, ALERT_STATUS_ACTIVE),
...rangeQuery(start, end),
...kqlQuery(kuery),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@
* 2.0.
*/

import { kqlQuery, termQuery, rangeQuery, wildcardQuery } from '@kbn/observability-plugin/server';
import {
kqlQuery,
termQuery,
rangeQuery,
wildcardQuery,
termsQuery,
} from '@kbn/observability-plugin/server';
import {
ALERT_RULE_PRODUCER,
ALERT_STATUS,
ALERT_STATUS_ACTIVE,
ALERT_UUID,
} from '@kbn/rule-data-utils';
import { observabilityFeatureId } from '@kbn/observability-shared-plugin/common';
import { SERVICE_NAME } from '../../../../common/es_fields/apm';
import { ServiceGroup } from '../../../../common/service_groups';
import { ApmAlertsClient } from '../../../lib/helpers/get_apm_alerts_client';
Expand Down Expand Up @@ -51,7 +58,7 @@ export async function getServicesAlerts({
query: {
bool: {
filter: [
...termQuery(ALERT_RULE_PRODUCER, 'apm'),
...termsQuery(ALERT_RULE_PRODUCER, 'apm', observabilityFeatureId),
...termQuery(ALERT_STATUS, ALERT_STATUS_ACTIVE),
...rangeQuery(start, end),
...kqlQuery(kuery),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderCon
APIClientRequestParamsOf<'GET /internal/apm/get_agents_per_service'>['params']
>
) {
return await apmApiClient.readUser({
return apmApiClient.readUser({
endpoint: 'GET /internal/apm/get_agents_per_service',
params: {
query: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderCon
const unlistedAgentName = 'unlistedAgent';

async function callApi() {
return await apmApiClient.readUser({
return apmApiClient.readUser({
endpoint: 'GET /internal/apm/get_latest_agent_versions',
});
}
Expand Down
Loading

0 comments on commit fb666aa

Please sign in to comment.