Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 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
- 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 @@ -568,3 +570,7 @@ 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
- x-pack/test/observability_solution_api_integration/test_suites/alerting/custom_threshold/configs/serverless.config.ts
- x-pack/test/observability_solution_api_integration/test_suites/alerting/custom_threshold/configs/ess.config.ts
10 changes: 10 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,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 Expand Up @@ -1847,6 +1849,14 @@ module.exports = {
},
},

/** Observerability Solution API Integration tests
* Ensures appropriate mocha tagging for tests
*/
{
files: ['x-pack/test/observability_solution_api_integration/**/*.{ts,tsx}'],
rules: { '@kbn/eslint/require_mocha_tagging': 'error' },
},

/**
* Code inside .buildkite runs separately from everything else in CI, before bootstrap, with ts-node. It needs a few tweaks because of this.
*/
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-eslint-plugin-eslint/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ module.exports = {
no_constructor_args_in_property_initializers: require('./rules/no_constructor_args_in_property_initializers'),
no_this_in_property_initializers: require('./rules/no_this_in_property_initializers'),
no_unsafe_console: require('./rules/no_unsafe_console'),
require_mocha_tagging: require('./rules/require_mocha_tagging'),
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

const tsEstree = require('@typescript-eslint/typescript-estree');
const esTypes = tsEstree.AST_NODE_TYPES;

/** @typedef {import("eslint").Rule.RuleModule} Rule */
/** @typedef {import("@typescript-eslint/typescript-estree").TSESTree.Node} Node */
/** @typedef {import("@typescript-eslint/typescript-estree").TSESTree.CallExpression} CallExpression */
/** @typedef {import("@typescript-eslint/typescript-estree").TSESTree.FunctionExpression} FunctionExpression */
/** @typedef {import("@typescript-eslint/typescript-estree").TSESTree.ArrowFunctionExpression} ArrowFunctionExpression */
/** @typedef {import("eslint").Rule.RuleFixer} Fixer */

const ERROR_MSG = `Describe blocks must be tagged with either @ess or @serverless to specify the test execution environment. Ex: describe('@ess @serverless API Integration test', () => {})`;

/**
* @param {any} context
* @param {CallExpression} node
*/
const isDescribeBlockWithoutTagging = (node) => {
const isDescribeBlock =
node.type === esTypes.CallExpression &&
node.callee.type === esTypes.Identifier &&
node.callee.name === 'describe' &&
node.arguments.length >= 1;

if (!isDescribeBlock) {
return false;
}
const title = node.arguments[0].value;
const hasTags = /^(@ess|@serverless)/.test(title);
if (hasTags) {
return false;
} else {
return true;
}
};

/** @type {Rule} */
module.exports = {
meta: {
fixable: 'code',
schema: [],
},
create: (context) => ({
CallExpression(_) {
const node = /** @type {CallExpression} */ (_);

if (isDescribeBlockWithoutTagging(node)) {
context.report({
message: ERROR_MSG,
loc: node.arguments[0].loc,
});
}
},
}),
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

const { RuleTester } = require('eslint');
const rule = require('./require_mocha_tagging');
const dedent = require('dedent');

const ruleTester = new RuleTester({
parser: require.resolve('@typescript-eslint/parser'),
parserOptions: {
sourceType: 'module',
ecmaVersion: 2018,
ecmaFeatures: {
jsx: true,
},
},
});

ruleTester.run('@kbn/eslint/require_mocha_tagging', rule, {
valid: [
{
code: dedent`
describe('@ess @serverless API Integration test', () => {})
`,
},
{
code: dedent`
describe('@ess API Integration test', () => {})
`,
},
{
code: dedent`
describe('@serverless API Integration test', () => {})
`,
},
],

invalid: [
{
code: dedent`
describe('API Integration test', () => {})
`,
errors: [
{
line: 1,
message:
'Passing an async function to .forEach() prevents promise rejections from being handled. Use asyncForEach() or similar helper from "@kbn/std" instead.',
},
],
},
],
});
4 changes: 4 additions & 0 deletions x-pack/test/api_integration/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import { IngestPipelinesProvider } from './ingest_pipelines';
import { IndexManagementProvider } from './index_management';
import { DataViewApiProvider } from './data_view_api';
import { SloApiProvider } from './slo';
import { SloApiProvider as SloApiProviderNew } from './slo_api';
import { AlertingApiProvider } from './alerting_api';
import { SecuritySolutionApiProvider } from './security_solution_api.gen';

export const services = {
Expand All @@ -45,4 +47,6 @@ export const services = {
indexManagement: IndexManagementProvider,
slo: SloApiProvider,
securitySolutionApi: SecuritySolutionApiProvider,
alertingApi: AlertingApiProvider,
sloApi: SloApiProviderNew, // TODO: Need to unify SloApiProvider and SloApiProviderNew, there was already an slo service here, part of the slo API migration issue https://github.com/elastic/kibana/issues/183397
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
FetchHistoricalSummaryResponse,
} from '@kbn/slo-schema';
import * as t from 'io-ts';
import { FtrProviderContext } from '../ftr_provider_context';
import { FtrProviderContext } from '../../functional/ftr_provider_context';

type DurationUnit = 'm' | 'h' | 'd' | 'w' | 'M';

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,43 @@
/*
* 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 };
publicBaseUrl?: boolean;
}

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

return {
...xPackApiIntegrationTestsConfig.getAll(),
testFiles: options.testFiles,
services: {
...services,
},
junit: {
reportName: 'X-Pack Οbservability Solution API Integration Tests',
},
mochaOpts: {
grep: '/^(?!.*@skipInEss).*@ess.*/',
},
kbnTestServer: {
...xPackApiIntegrationTestsConfig.get('kbnTestServer'),
serverArgs: [
...xPackApiIntegrationTestsConfig.get('kbnTestServer.serverArgs'),
...(options.publicBaseUrl ? ['--server.publicBaseUrl=http://localhost:5620'] : []),
],
},
};
};
}
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 '../api_integration/ftr_provider_context';

export type { FtrProviderContext };
17 changes: 17 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,17 @@
{
"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",
"alerting_custom_threshold:server:serverless": "node ../../../scripts/functional_tests_server.js --config ./test_suites/alerting/custom_threshold/configs/serverless.config.ts",
"alerting_custom_threshold:runner:serverless": "node ../../../scripts/functional_test_runner --config=test_suites/alerting/custom_threshold/configs/serverless.config.ts --grep @serverless --grep @skipInServerless --invert",
"alerting_custom_threshold:server:ess": "node ../../../scripts/functional_tests_server.js --config ./test_suites/alerting/custom_threshold/configs/ess.config.ts",
"alerting_custom_threshold:runner:ess": "node ../../../scripts/functional_test_runner --config=test_suites/alerting/custom_threshold/configs/ess.config.ts --grep @ess --grep @skipInEss --invert"
}
}
Loading