kibana/test/analytics
Kibana Machine 9b606f7f72
[8.x] Add filters option to ftr_helper api (#196886) (#197509)
# Backport

This will backport the following commits from `main` to `8.x`:
- [Add filters option to ftr_helper api
(#196886)](https://github.com/elastic/kibana/pull/196886)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Sebastián
Zaffarano","email":"sebastian.zaffarano@elastic.co"},"sourceCommit":{"committedDate":"2024-10-23T17:18:05Z","message":"Add
filters option to ftr_helper api
(#196886)","sha":"48fe299d5bcd230d63ce2dd8e89c62307dd0ee82","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","backport:all-open"],"title":"Add
filters option to ftr_helper
api","number":196886,"url":"https://github.com/elastic/kibana/pull/196886","mergeCommit":{"message":"Add
filters option to ftr_helper api
(#196886)","sha":"48fe299d5bcd230d63ce2dd8e89c62307dd0ee82"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/196886","number":196886,"mergeCommit":{"message":"Add
filters option to ftr_helper api
(#196886)","sha":"48fe299d5bcd230d63ce2dd8e89c62307dd0ee82"}}]}]
BACKPORT-->

Co-authored-by: Sebastián Zaffarano <sebastian.zaffarano@elastic.co>
2024-10-23 14:24:10 -05:00
..
plugins [8.x] Add filters option to ftr_helper api (#196886) (#197509) 2024-10-23 14:24:10 -05:00
services [8.x] Add filters option to ftr_helper api (#196886) (#197509) 2024-10-23 14:24:10 -05:00
tests [8.x] Add filters option to ftr_helper api (#196886) (#197509) 2024-10-23 14:24:10 -05:00
config.ts [http] api_integration tests handle internal route restriction (#192407) 2024-09-12 09:23:10 +02:00
README.md [Obs AI Assistant] Add tests for if chat telemetry is sent and correctly shaped (#181086) 2024-05-02 12:00:56 +02:00

FTR tests for the core.analytics service

This suite allows us to test the event-based telemetry client provided by the core.analytics service.

How to add my own tests

Implement your own tests in the tests/instrumented_events/(from_the_browser|from_the_server)/ directory and list it in the tests/instrumented_events/(from_the_browser|from_the_server)/index.ts file.

There are 2 FTR helpers to allow you to retrieve the generated events:

  1. For events generated in the UI, you can use kibana_ebt_ui to retrieve the events.
  2. For events generated in the server, you can use the kibana_ebt_server helper.

The API is the same for both of them:

// To retrieve 2 events of type "my-event-type"
const events = await getService('kibana_ebt_ui').getEvents(2, { eventTypes: ['my-event-type'] });
expect(events).to...

Refer to EBTHelpersContract for more details about the existing APIs and all the options they accept.

Usage outside of this test suite

First, you'll need to add the services to your config, such as:

kibana_ebt_server: KibanaEBTServerProvider,
kibana_ebt_ui: KibanaEBTUIProvider,

The providers are found inside ./services/kibana_ebt.ts

You'll also need to inject a plugin to Kibana that loads the helper code, by adding a CLI flag like: --plugin-path=PATH_TO/test/analytics/plugins/analytics_ftr_helpers

If you are reusing these helpers in another suite, please remember to make sure to optIn via await getService('kibana_ebt_ui').setOptIn(true);

Note: This opt in is only stored in memory, so a page refresh will reset it.