Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Observability solution] [SLO] Run burn rate api tests in serverless & ess using mocha tagging #183113

Closed
Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
5b687c0
run burn rate api tests in serverless & ess using mocha tagging
mgiota May 10, 2024
0c04a91
move alertingApi and sloApi services in the new observability_solutio…
mgiota May 10, 2024
0cf722e
Merge branch 'main' of github.com:elastic/kibana into observability_s…
mgiota May 10, 2024
3f1eae3
remove burn rate tests from test_serverless
mgiota May 11, 2024
ddb3621
clean up
mgiota May 11, 2024
8c0c86e
restructure and add a how to run section in the readme
mgiota May 13, 2024
3c90711
update README
mgiota May 13, 2024
0917e44
fix ftr_provider_context
mgiota May 13, 2024
b8237fc
refactor reading services from test_serverless
mgiota May 14, 2024
b518160
Merge branch 'main' into observability_solution_api_integration
kibanamachine May 14, 2024
f0cf7e2
scripts/lint_ts_projects fix
mgiota May 14, 2024
8ac4d04
exlude observability_solution_api_integration
mgiota May 14, 2024
e535b65
fix CI
mgiota May 14, 2024
3c4bd06
add custom linting
dominiqueclarke May 16, 2024
79f51ba
Merge branch 'observability_solution_api_integration' of https://gith…
dominiqueclarke May 16, 2024
92db76a
Merge branch 'main' into observability_solution_api_integration
kibanamachine May 17, 2024
6aa6b28
Add avg_pct_fired test
maryam-saeidi May 17, 2024
33ef0b8
Merge branch 'main' of github.com:elastic/kibana into observability_s…
mgiota May 27, 2024
00ae289
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine May 27, 2024
4d21820
move alerting and slo apis under deployment agnostic services
mgiota May 27, 2024
330ef06
add require mocha tagging
dominiqueclarke Jun 3, 2024
778fd0c
load ftrProvider context from test folder instead of test_serverless
mgiota Jul 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .buildkite/ftr_configs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ disabled:
- x-pack/test/security_solution_api_integration/config/serverless/config.base.essentials.ts
- x-pack/test/security_solution_endpoint/config.base.ts
- x-pack/test/security_solution_endpoint_api_int/config.base.ts
- x-pack/test/observability_solution_api_integration/config/serverless/config.base.ts
mgiota marked this conversation as resolved.
Show resolved Hide resolved
- x-pack/test/observability_solution_api_integration/config/ess/config.base.ts

# QA suites that are run out-of-band
- x-pack/test/stack_functional_integration/configs/config.stack_functional_integration_base.js
Expand Down Expand Up @@ -564,3 +566,5 @@ enabled:
- x-pack/test/security_solution_api_integration/test_suites/investigation/timeline/trial_license_complete_tier/configs/serverless.config.ts
- x-pack/test/security_solution_api_integration/test_suites/sources/indices/trial_license_complete_tier/configs/ess.config.ts
- x-pack/test/security_solution_api_integration/test_suites/sources/indices/trial_license_complete_tier/configs/serverless.config.ts
- x-pack/test/observability_solution_api_integration/test_suites/alerting/burn_rate/configs/serverless.config.ts
- x-pack/test/observability_solution_api_integration/test_suites/alerting/burn_rate/configs/ess.config.ts
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,8 @@ module.exports = {
'x-pack/test/profiling_api_integration/**/*.ts',
'x-pack/test/security_solution_api_integration/*/test_suites/**/*',
'x-pack/test/security_solution_api_integration/**/config*.ts',
'x-pack/test/observability_solution_api_integration/*/test_suites/**/*',
'x-pack/test/observability_solution_api_integration/**/config*.ts',
],
rules: {
'import/no-default-export': 'off',
Expand Down
78 changes: 78 additions & 0 deletions x-pack/test/observability_solution_api_integration/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# observability_solution_api_integration

This directory serves as a centralized location to place the observability solution tests that run in Serverless and ESS environments

## Subdirectories

1. `config` stores base configurations specific to both the Serverless and ESS environments. These configurations build upon the base configuration provided by `x-pack/test_serverless` and `x-pack/test/api_integration`, incorporating additional settings such as environmental variables and tagging options

2. `test_suites` directory houses all the tests along with the utility functions.

## Overview

- In this directory Mocha tagging is utilized to assign tags to specific test suites and individual test cases. This tagging system enables the ability to selectively apply tags to test suites and test cases, facilitating the exclusion of specific test cases within a test suite as needed.

- Test suites and cases are prefixed with specific tags to determine their execution in particular environments or to exclude them from specific environments.

- We are using the following tags:
* `@ess`: Runs in an ESS environment (on-prem installation) as part of the CI validation on PRs.

* `@serverless`: Runs in the first quality gate and in the periodic pipeline.

* `@skipInEss`: Skipped for ESS environment.

* `@skipInServerless`: Skipped for all quality gates, CI and periodic pipeline.

ex:
```
describe('@serverless @ess create_rules', () => { ==> tests in this suite will run in both Ess and Serverless
describe('creating rules', () => {});

describe('@skipInServerless missing timestamps', () => {}); ==> tests in this suite will be excluded in Serverless

```

# Adding new observabiluty area's tests

1. Within the `test_suites` directory, create a new area folder, for example slos, rules, apm etc
2. Introduce `ess.config` and `serverless.config` files to reference the new test files and incorporate any additional custom properties defined in the `CreateTestConfigOptions` interface.
3. In these new configuration files, include references to the base configurations located under the config directory to inherit CI configurations, environment variables, and other settings.
4. Append a new entry in the `ftr_configs.yml` file to enable the execution of the newly added tests within the CI pipeline.


# Testing locally

In the `package.json` file, you'll find commands to configure the server for each environment and to run tests against that specific environment. These commands adhere to the Mocha tagging system, allowing for the inclusion and exclusion of tags, mirroring the setup of the CI pipeline.

# How to run
You can run various commands with different parameters for the different test worflows.

The command structure follows this pattern:

- `<test>`: The test workflow you want to run.
- `<type>`: The type of operation, either "server" or "runner."
- `<environment>`: The testing environment, such as "serverless," or "ess", specifies the correct configuration file for the tests.

Run the server for "alerting_burn_rate" in the "serverless" environment:

```shell
npm run alerting_burn_rate:server:serverless
```

Run tests for "alerting_burn_rate" in the "serverless" environment:

```shell
npm run alerting_burn_rate:runner:serverless
```

Run the server for "alerting_burn_rate" in the "ess" environment:

```shell
npm run alerting_burn_rate:server:ess
```

Run tests for "alerting_burn_rate" in the "ess" environment:

```shell
npm run alerting_burn_rate:runner:ess
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { FtrConfigProviderContext } from '@kbn/test';
import { services } from '../../../api_integration/services';

export interface CreateTestConfigOptions {
testFiles: string[];
junit: { reportName: string };
}

export function createTestConfig(options: CreateTestConfigOptions) {
return async ({ readConfigFile }: FtrConfigProviderContext) => {
const xPackApiIntegrationTestsConfig = await readConfigFile(
require.resolve('../../../api_integration/config.ts')
);

const svlSharedConfig = await readConfigFile(
require.resolve('../../../../test_serverless/shared/config.base.ts')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I import shared services from test_serverless, since I want to reuse the sloApi and alertingApi

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a dangerous approach. Services from the test_serverless area are not guaranteed to work in stateful / ESS.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep I can understand this. In our case the exact same service works for both ESS and Serveless. What is the recommended approach here? Before doing this, I had the slo_api and alerting_api services within the new folder. Each configuration then (ess & serverless) can decide from where to get the service. Would this be a better approach?

I think we need to see which services can be reused in both environments and clean up/restructure them while we start migrating more tests into this kind of deployment agnostic solution. I would like to further discuss this with you. I'll arrange something

Copy link
Contributor Author

@mgiota mgiota May 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pheyos As per our discussion I moved these 2 services under deployment agnostic services in this commit and tests still work fine! Does it look better this way?

);
const svlSharedServices = svlSharedConfig.get('services');

return {
...xPackApiIntegrationTestsConfig.getAll(),
testFiles: options.testFiles,
services: {
...services,
sloApi: svlSharedServices.sloApi,
alertingApi: svlSharedServices.alertingApi,
},
junit: {
reportName: 'X-Pack Οbservability Solution API Integration Tests',
},
mochaOpts: {
grep: '/^(?!.*@skipInEss).*@ess.*/',
},
};
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { FtrConfigProviderContext } from '@kbn/test';
import { services } from '../../../../test_serverless/api_integration/services';

export interface CreateTestConfigOptions {
testFiles: string[];
junit: { reportName: string };
}

export function createTestConfig(options: CreateTestConfigOptions) {
return async ({ readConfigFile }: FtrConfigProviderContext) => {
const svlSharedConfig = await readConfigFile(
require.resolve('../../../../test_serverless/shared/config.base.ts')
);

return {
...svlSharedConfig.getAll(),
services: {
...services,
},
kbnTestServer: {
...svlSharedConfig.get('kbnTestServer'),
serverArgs: [...svlSharedConfig.get('kbnTestServer.serverArgs'), `--serverless=oblt`],
},
testFiles: options.testFiles,
junit: options.junit,
mochaOpts: {
...svlSharedConfig.get('mochaOpts'),
grep: '/^(?!.*@skipInServerless).*@serverless.*/',
},
};
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import type { FtrProviderContext } from '../../test_serverless/api_integration/ftr_provider_context';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the serverless ftr_provider_context here can lead to issues with non-serverless tests (e.g. they might pick the wrong version of an overloaded test service).

Copy link
Contributor Author

@mgiota mgiota May 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a look at this file, where services are loaded from test_serverless, but I totally get the point. That was my concern as well and I was expecting a comment from you regarding this. Let's address this topic in our chat next week.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pheyos In this commit I moved my services to the deployment agnostic services. I don't recall what I need to do about the ftr_provider_context file. Could you assist?


export type { FtrProviderContext };
13 changes: 13 additions & 0 deletions x-pack/test/observability_solution_api_integration/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"author": "Elastic",
"name": "@kbn/observability_solution_api_integration",
"version": "1.0.0",
"private": true,
"license": "Elastic License 2.0",
"scripts": {
"alerting_burn_rate:server:serverless": "node ../../../scripts/functional_tests_server.js --config ./test_suites/alerting/burn_rate/configs/serverless.config.ts",
"alerting_burn_rate:runner:serverless": "node ../../../scripts/functional_test_runner --config=test_suites/alerting/burn_rate/configs/serverless.config.ts --grep @serverless --grep @skipInServerless --invert",
"alerting_burn_rate:server:ess": "node ../../../scripts/functional_tests_server.js --config ./test_suites/alerting/burn_rate/configs/ess.config.ts",
"alerting_burn_rate:runner:ess": "node ../../../scripts/functional_test_runner --config=test_suites/alerting/burn_rate/configs/ess.config.ts --grep @ess --grep @skipInEss --invert"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { cleanup, Dataset, generate, PartialConfig } from '@kbn/data-forge';
import expect from '@kbn/expect';
Expand All @@ -23,8 +17,11 @@ export default function ({ getService }: FtrProviderContext) {
const alertingApi = getService('alertingApi');
const dataViewApi = getService('dataViewApi');
const sloApi = getService('sloApi');
const config = getService('config');
const isServerless = config.get('serverless');
const expectedConsumer = isServerless ? 'observability' : 'slo';
mgiota marked this conversation as resolved.
Show resolved Hide resolved

describe('Burn rate rule', () => {
describe('@serverless @ess Burn rate rule', () => {
const RULE_TYPE_ID = 'slo.rules.burnRate';
const DATA_VIEW = 'kbn-data-forge-fake_hosts.fake_hosts-*';
const RULE_ALERT_INDEX = '.alerts-observability.slo.alerts-default';
Expand Down Expand Up @@ -120,7 +117,7 @@ export default function ({ getService }: FtrProviderContext) {

const dependencyRule = await alertingApi.createRule({
tags: ['observability'],
consumer: 'observability',
consumer: expectedConsumer,
name: 'SLO Burn Rate rule - Dependency',
ruleTypeId: RULE_TYPE_ID,
schedule: {
Expand Down Expand Up @@ -192,7 +189,7 @@ export default function ({ getService }: FtrProviderContext) {

const createdRule = await alertingApi.createRule({
tags: ['observability'],
consumer: 'observability',
consumer: expectedConsumer,
name: 'SLO Burn Rate rule',
ruleTypeId: RULE_TYPE_ID,
schedule: {
Expand Down Expand Up @@ -294,7 +291,7 @@ export default function ({ getService }: FtrProviderContext) {
it('should find the created rule with correct information about the consumer', async () => {
const match = await alertingApi.findRule(ruleId);
expect(match).not.to.be(undefined);
expect(match.consumer).to.be('observability');
expect(match.consumer).to.be(expectedConsumer);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { createTestConfig } from '../../../../config/ess/config.base';

export default createTestConfig({
testFiles: [require.resolve('..')],
junit: {
reportName: 'SLO - Burn rate Integration Tests - ESS Env',
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { createTestConfig } from '../../../../config/serverless/config.base';

export default createTestConfig({
testFiles: [require.resolve('..')],
junit: {
reportName: 'SLO - Integration Tests - Serverless Env',
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { FtrProviderContext } from '../../../ftr_provider_context';

export default function ({ loadTestFile }: FtrProviderContext) {
describe('Slo - Burn rate rule', function () {
loadTestFile(require.resolve('./burn_rate_rule'));
});
}
48 changes: 48 additions & 0 deletions x-pack/test/observability_solution_api_integration/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types",
"types": ["node", "jest","@kbn/ambient-ftr-types"]
},
"include": [
"**/*",
"../../../typings/**/*",
"../../../packages/kbn-test/types/ftr_globals/**/*",
],
"exclude": [
"target/**/*"
],
"kbn_references": [
{ "path": "../../test_serverless/tsconfig.json" },
{ "path": "../../test_serverless/api_integration/**/*" },
{ "path": "../../test_serverless/shared/**/*" },
{ "path": "../../api_integration/services/**/*" },
"@kbn/dev-utils",
"@kbn/test",
"@kbn/expect",
"@kbn/security-solution-plugin",
"@kbn/securitysolution-io-ts-list-types",
"@kbn/lists-plugin",
"@kbn/securitysolution-io-ts-alerting-types",
"@kbn/tooling-log",
"@kbn/rule-data-utils",
"@kbn/securitysolution-list-constants",
"@kbn/core-saved-objects-server",
"@kbn/core",
"@kbn/alerting-plugin",
"@kbn/securitysolution-ecs",
"@kbn/securitysolution-rules",
"@kbn/core-http-common",
"@kbn/securitysolution-ecs",
"@kbn/fleet-plugin",
"@kbn/repo-info",
"@kbn/securitysolution-es-utils",
"@kbn/datemath",
"@kbn/safer-lodash-set",
"@kbn/stack-connectors-plugin",
"@kbn/ftr-common-functional-services",
"@kbn/actions-plugin",
"@kbn/task-manager-plugin",
]
}

5 changes: 0 additions & 5 deletions x-pack/test_serverless/api_integration/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@
import { GenericFtrProviderContext } from '@kbn/test';
import { services as deploymentAgnosticSharedServices } from '../../shared/services/deployment_agnostic_services';
import { services as svlSharedServices } from '../../shared/services';

import { AlertingApiProvider } from './alerting_api';
import { SamlToolsProvider } from './saml_tools';
import { SvlCasesServiceProvider } from './svl_cases';
import { SloApiProvider } from './slo_api';
import { TransformProvider } from './transform';

export const services = {
Expand All @@ -21,10 +18,8 @@ export const services = {

// serverless FTR services
...svlSharedServices,
alertingApi: AlertingApiProvider,
samlTools: SamlToolsProvider,
svlCases: SvlCasesServiceProvider,
sloApi: SloApiProvider,
transform: TransformProvider,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export default function ({ loadTestFile }: FtrProviderContext) {
loadTestFile(require.resolve('./telemetry/telemetry_config'));
loadTestFile(require.resolve('./apm_api_integration/feature_flags.ts'));
loadTestFile(require.resolve('./cases'));
loadTestFile(require.resolve('./burn_rate_rule/burn_rate_rule'));
mgiota marked this conversation as resolved.
Show resolved Hide resolved
loadTestFile(require.resolve('./es_query_rule/es_query_rule'));
loadTestFile(require.resolve('./slos'));
loadTestFile(require.resolve('./synthetics'));
Expand Down
Loading