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

[R&D] Stateful/stateless test harness options for observability #179549

Closed
13 tasks done
jasonrhodes opened this issue Mar 27, 2024 · 6 comments
Closed
13 tasks done

[R&D] Stateful/stateless test harness options for observability #179549

jasonrhodes opened this issue Mar 27, 2024 · 6 comments
Assignees
Labels
Team:obs-ux-management Observability Management User Experience Team

Comments

@jasonrhodes
Copy link
Member

jasonrhodes commented Mar 27, 2024

Currently to run tests in both a stateful and serverless context, the current recommendation is to "copy the tests that should run in stateful and serverless", which requires teams to maintain those files separately, as well. We would like the ability to tell CI to run a selection of tests in both contexts, rather than needing to copy/paste the files.

This issue is a time-boxed R&D for someone to look into whether we can create some kind of simple "test harness" wrapper for running a selection of our functional tests in both contexts, that would work for our observability purposes.

Existing Tests

Here's the current test coverage for the SLO and o11y alerting features for both serverless and stateful environments:

API Integration tests

Test Type ESS Serverless Notes
Custom threshold rule type Alerting Duplicate tests
Serverless: x-pack/test_serverless/api_integration/test_suites/observability/custom_threshold_rule ESS: x-pack/test/alerting_api_integration/observability/custom_threshold_rule
Metric threshold rule type Alerting ESS: x-pack/test/alerting_api_integration/observability/metric_threshold_rule.ts
ES query rule type Alerting Serverless: x-pack/test_serverless/api_integration/test_suites/observability/es_query_rule
Burn rate rule type Alerting Serverless: x-pack/test_serverless/api_integration/test_suites/observability/burn_rate_rule
SLO tests SLO Different implementation in both environments.
Serverless: x-pack/test_serverless/api_integration/test_suites/observability/slos ESS: x-pack/test/api_integration/apis/slos

Functional tests

Test Type ESS Serverless Notes
Rules page Alerting ESS: x-pack/test/observability_functional/apps/observability/pages/rules_page.ts
Rule details page Alerting ESS: x-pack/test/observability_functional/apps/observability/pages/rule_details_page.ts
Alerts page Alerting ESS: x-pack/test/observability_functional/apps/observability/pages/alerts
Overview page alerts table Alerting ESS: x-pack/test/observability_functional/apps/observability/pages/overview/alert_table.ts
SLO embeddable tests SLO ESS: x-pack/test/functional/apps/slo/embeddables

Our initial approach using Mocha tagging

We are going to write our tests in a new location and we will use ess & serverless configurations to specify environment specific options like extra services and Mocha options. Test suites and cases should be prefixed with specific tags to determine their execution in particular environments (@ess @serverless) or to exclude them from specific environments (@skipInServerless @skipInEss).

Test case example

describe('@ess @serverless SLO burn rate rule, () => {
  describe('Create rule', () => { 
  });

 describe('@skipInServerless missing something', () => { 
 });
}

Configuration examples

Tests tagged with @serverless are included, whereas tests tagged with @skipInServerless are excluded

 mochaOpts: {
    grep: '/^(?!.*@skipInServerless).*@serverless.*/',
 },

Tests tagged with @ess are included, whereas tests tagged with @skipInEss are excluded

mochaOpts: {
    grep: '/^(?!.*@skipInEss).*@ess.*/',
}

Final implementation using suiteTags

As per Platform's recommendation, FTR tests already make use of the it.tags(['my-tag-1', 'my-tag-2']) pattern, so we would like to stay with that pattern rather than introducing a new type of mocha tag in the it block's "description" as it was introduced in this POC. The main trade-off for this is that this tagging is only available at the suite level ("describe") and not individual test level ("it"). However, we consider this not a blocker since tests within one suite are usually all good for the same environment and the few exceptions can easily be handled.

Adding following in the config files:

serverless config

suiteTags: {
        include: ['serverless'],
        exclude: ['skipInServerless'],
      },

ess config

suiteTags: {
        include: ['ess'],
        exclude: ['skipInEss'],
      },

and then adding this.tags(['serverless', 'ess']) in the test suite instructs the test runner to run the same test suite in both environments.

Todo

@jasonrhodes jasonrhodes added the Team:obs-ux-management Observability Management User Experience Team label Mar 27, 2024
@elasticmachine
Copy link
Contributor

Pinging @elastic/obs-ux-management-team (Team:obs-ux-management)

@simianhacker
Copy link
Member

The approach we could take is to create an abstraction that basically injects dependencies for each environment (Stateless vs Stateful), then we would refactor our tests to use the abstractions instead of writing tests in both places.

@paulb-elastic
Copy link
Contributor

Linking #162698

@jasonrhodes
Copy link
Member Author

We now have a plan for deployment agnostic testing. Thanks for all of this work and collaboration, @mgiota and everyone else!

@jasonrhodes
Copy link
Member Author

Re-opening this so it can be closed by the PR in review.

@jasonrhodes jasonrhodes reopened this Aug 13, 2024
mgiota added a commit that referenced this issue Aug 21, 2024
Addresses #179549
Relates to #183113 

## Update
Since the Appex QA team has taken on deployment agnostic tests, a lot of
the original implementation of this PR has changed. Now that the Appex
QA team has provided a current directly to write deployment agnostic
tests, the burn rate rule tests have been moved here.

To finish onboarding the burn rate rule test to this new framework, the
following was done.
1. Add an `oblt.stateful.config.ts` file to complement the existing
`oblt.serverless.config.ts` file to ensure the tests are run in CI
2. Ensure our test config is added to the buildkite pipepline
3. Add the alerting service to the new `deployment_agnostic/services`
directory.
4. Port the tests over to the new `deployment_agnostic` directory


To run 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="Burn rate rule"
```

To run 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="Burn rate rule"
```

For context, I've kept the history from the original PR description
below.

## 🍒 History

A new type of config file will be allowed for API integration and
functional tests within the `x-pack/test` folder, using a pattern of
`*.serverless.config.ts` — these config files will specify configuration
needed to run a set of tests in a serverless deployment context.

FTR tests already make use of the `it.tags(['my-tag-1', 'my-tag-2'])`
pattern, and so we would like to stay with that pattern rather than
introducing a new type of mocha tag in the it block's "description" as
it was introduced in this
[POC](#183113). The difference
with the previous PR in terms of tagging is that we use `suiteTags`
instead of `mochaOps`

Adding following in the config files:

**serverless config**

```
suiteTags: {
        include: ['serverless'],
      },
```

**ess config**

```
suiteTags: {
        include: ['ess'],
      },
```

and then adding `this.tags(['serverless', 'ess'])` in the test suite
instructs the test runner to run the same test suite in both
environments.

In order to keep things simple, we stay with the current skip approach,
which means that flaky tests will be skipped for all environments by
appending .skip() to the suite or to specific test cases.

## Description

- This PR uses `suiteTags` for tagging the tests appropriately. We
decide through following labels in which environment the tests are going
to be executed:
- **@ess**: Runs in an ESS environment (on-prem installation) as part of
the CI validation on PRs.
  - **@serverless**: Runs in a serverless environment.
- It introduces a new folder
`x-pack/test/observability_solution_api_integration` which will serve as
a centralized location for all tests by obs-ux-management team that must
be run in Serverless and ESS environments. A list of all tests can be
found in the R&D
[issue](#179549)
- Within this folder, there is a "**config**" subdirectory that stores
base configurations specific to both the Serverless and ESS
environments. These configurations build upon the base configuration
provided by test_serverless and api_integration, incorporating
additional settings such as environment variables and tagging options.
- The file
`x-pack/test/observability_solution_api_integration/test_suites/alerting/burn_rate/burn_rate_rule.ts`
is functional in both Serverless and ESS
- It removes the existing burn rate rule from
`x-pack/test_serverless/api_integration/test_suites/observability/alerting/burn_rate/burn_rate_rule.ts`
- The `alertingApi` and `sloApi` services are moved to
`test/api_integration` servers

In the screenshot below you can see the `test_suites` folder structure,
after having migrated the current slo burn rate rule. We recommend
having an `alerting` and `slo` subfolders. Rest observability apps could
be added as another subfolder under test_suites. As part of this PR, the
`alerting > burn_rate` subfolders are created.

<img width="376" alt="Screenshot 2024-05-13 at 09 21 28"
src="https://github.com/elastic/kibana/assets/2852703/3ccaf0a5-1443-4bad-ad06-daa347488bf1">

## How to run locally
You can navigate into the new `observability_solution_api_integration`
folder and use following commands to run the tests in serverless and ess
environments accordingly. You can find more information in the README
file of the observability_solution_api_integration folder.

```
cd x-pack/test/observability_solution_api_integration

// SERVERLESS
npm run alerting_burn_rate:server:serverless
npm run alerting_burn_rate:runner:serverless

// ESS
npm run alerting_burn_rate:server:ess
npm run alerting_burn_rate:runner:ess
```

## CI

- It includes a new entry in the `ftr_configs.yml` to execute the newly
added tests in the pipeline.
- It involves the addition of `suiteTags` in both
serverless/config.base.ts and ess/config.base.ts. In the case of
serverless, it includes **@serverless** while excluding
**@skipInServerless**. Similarly, for ess, it includes **@ess** and
excludes **@skipInEss**.

## Quality Gates and MKI pipeline
The Platform team will support config files within `x-pack/test` folder
with a pattern of `*.serverless.config.ts`, so these tests will be
included in Kibana's Quality gates and will be run against a real MKI
environment.

---------

Co-authored-by: Dominique Belcher <[email protected]>
Co-authored-by: Dominique Clarke <[email protected]>
Co-authored-by: kibanamachine <[email protected]>
Co-authored-by: Dzmitry Lemechko <[email protected]>
Co-authored-by: Robert Oskamp <[email protected]>
Co-authored-by: Elastic Machine <[email protected]>
@mgiota
Copy link
Contributor

mgiota commented Aug 21, 2024

Closing this, PR is already merged! Here's the ticket for the migration plan.

@mgiota mgiota closed this as completed Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team:obs-ux-management Observability Management User Experience Team
Projects
None yet
Development

No branches or pull requests

5 participants