-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Observability solution] [SLO] Run burn rate api tests in serverless & ess using mocha tagging #183113
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
Closed
mgiota
wants to merge
22
commits into
elastic:main
from
mgiota:observability_solution_api_integration
Closed
[Observability solution] [SLO] Run burn rate api tests in serverless & ess using mocha tagging #183113
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 0c04a91
move alertingApi and sloApi services in the new observability_solutio…
mgiota 0cf722e
Merge branch 'main' of github.com:elastic/kibana into observability_s…
mgiota 3f1eae3
remove burn rate tests from test_serverless
mgiota ddb3621
clean up
mgiota 8c0c86e
restructure and add a how to run section in the readme
mgiota 3c90711
update README
mgiota 0917e44
fix ftr_provider_context
mgiota b8237fc
refactor reading services from test_serverless
mgiota b518160
Merge branch 'main' into observability_solution_api_integration
kibanamachine f0cf7e2
scripts/lint_ts_projects fix
mgiota 8ac4d04
exlude observability_solution_api_integration
mgiota e535b65
fix CI
mgiota 3c4bd06
add custom linting
dominiqueclarke 79f51ba
Merge branch 'observability_solution_api_integration' of https://gith…
dominiqueclarke 92db76a
Merge branch 'main' into observability_solution_api_integration
kibanamachine 6aa6b28
Add avg_pct_fired test
maryam-saeidi 33ef0b8
Merge branch 'main' of github.com:elastic/kibana into observability_s…
mgiota 00ae289
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine 4d21820
move alerting and slo apis under deployment agnostic services
mgiota 330ef06
add require mocha tagging
dominiqueclarke 778fd0c
load ftrProvider context from test folder instead of test_serverless
mgiota File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
packages/kbn-eslint-plugin-eslint/rules/require_mocha_tagging.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, | ||
| }); | ||
| } | ||
| }, | ||
| }), | ||
| }; |
57 changes: 57 additions & 0 deletions
57
packages/kbn-eslint-plugin-eslint/rules/require_mocha_tagging.test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.', | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| }); |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
x-pack/test/observability_solution_api_integration/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| ``` |
43 changes: 43 additions & 0 deletions
43
x-pack/test/observability_solution_api_integration/config/ess/config.base.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'] : []), | ||
| ], | ||
| }, | ||
| }; | ||
| }; | ||
| } |
39 changes: 39 additions & 0 deletions
39
x-pack/test/observability_solution_api_integration/config/serverless/config.base.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.*/', | ||
| }, | ||
| }; | ||
| }; | ||
| } |
9 changes: 9 additions & 0 deletions
9
x-pack/test/observability_solution_api_integration/ftr_provider_context.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
17
x-pack/test/observability_solution_api_integration/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.