kibana/x-pack
Dzmitry Lemechko b5f158bc42
[Space time] extending Scout with perfTracker fixture (#212397)
## Summary

On-Week project "Client-side performance insights with Playwright &
Lighthouse"

revisiting old PR #66224

This PR extends Scout with `perfTracker` fixture designed to analyze
JavaScript bundle performance and page-level performance metrics in
Kibana by leveraging Chrome DevTools Protocol (CDP).

It intercepts network requests, filters static bundles, and computes
bundle size statistics per page load. Additionally, it collects CDP
Performance Domain Metrics, allowing in-depth analysis of rendering and
script execution times.


[README](c013c39b7e/src/platform/packages/shared/kbn-scout/src/playwright/fixtures/test/performance/README.md)
file with more details and examples was added

Output example for `/app/discover` (shorten, just to share the idea):

```
{
  "url": "http://localhost:5620/app/discover#/",
  "bundleCount": 87,
  "totalSize": 3133420,
  "pluginCount": 9,
  "plugins": [
    {
      "name": "aiops",
      "bundlesCount": 2,
      "totalSize": 5982,
      "bundles": [
        {
          "name": "aiops.chunk.1.js",
          "transferredSize": 2013
        },
        ...
      ]
    },
    {
      "name": "discover",
      "bundlesCount": 17,
      "totalSize": 631605,
      "bundles": [
        {
          "name": "discover.chunk.1.js",
          "transferredSize": 41915
        },
        ...
      ]
    },
    {
      "name": "eventAnnotation",
      "bundlesCount": 1,
      "totalSize": 8652,
      "bundles": [
        {
          "name": "eventAnnotation.chunk.1.js",
          "transferredSize": 8652
        }
      ]
    },
    {
      "name": "expressionXY",
      "bundlesCount": 5,
      "totalSize": 203127,
      "bundles": [
        {
          "name": "expressionXY.chunk.2.js",
          "transferredSize": 5328
        },
        ...
      ]
    },
  ]
}
```

You can create a Scout UI test and start bundle tracker whenever you
want to compute collected stats when all loading is done. Designed as
test, it allows you to have individual validations for plugins, total
bundle size, individual plugin size, etc.

```
      // Ensure all JS bundles are loaded
      await perfTracker.waitForJsLoad(cdp);

      // Collect and validate stats
      const stats = perfTracker.collectJsBundleStats(currentUrl);
      expect(
        stats.totalSize,
        `Total bundles size loaded on page should not exceed 3.0 MB`
      ).toBeLessThan(3 * 1024 * 1024);
      expect(stats.bundleCount, {
        message: `Total bundle chunks count loaded on page should not exceed 100`,
      }).toBeLessThan(100);
      expect(
        stats.plugins.map((p) => p.name),
        { message: 'Unexpected plugins were loaded on page' }
      ).toStrictEqual([
        'aiops',
        'discover',
        'eventAnnotation',
        'expressionXY',
        'kbn-ui-shared-deps-npm',
        'lens',
        'maps',
        'unifiedHistogram',
        'unifiedSearch',
      ]);
      // Validate individual plugin bundle sizes
      expect(stats.plugins.find((p) => p.name === 'discover')?.totalSize, {
        message: `Total 'discover' bundles size should not exceed 625 KB`,
      }).toBeLessThan(625 * 1024);
```

Full test example:
7b18e85541/x-pack/platform/plugins/private/discover_enhanced/ui_tests/tests/discover_cdp_perf.spec.ts

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2025-03-14 18:35:31 +01:00
..
build_chromium
dev-tools SKA: Update broken references and URLs (#206836) 2025-01-28 03:32:48 +00:00
examples [dashboard] clean up dashboard setup and start contracts (#212968) 2025-03-12 10:36:37 -06:00
packages Upgrade ES client to 9.0.0-alpha.3 (#208776) 2025-02-25 14:37:23 +00:00
performance SKA: Relocate /test to /src/platform/test (#210956) 2025-03-14 16:57:23 +00:00
platform [Space time] extending Scout with perfTracker fixture (#212397) 2025-03-14 18:35:31 +01:00
scripts [Streams] Replay loghub data with synthtrace (#212120) 2025-03-11 13:30:06 +01:00
solutions [Uptime] Fix skipped a11y tests (#214396) 2025-03-14 13:01:45 -04:00
test [Cases] Improve unit test flakiness (#212489) 2025-03-14 17:17:13 +00:00
test_serverless [Cases] Improve unit test flakiness (#212489) 2025-03-14 17:17:13 +00:00
.gitignore SKA: Update and breakdown x-pack/.gitignore (#212341) 2025-02-25 11:34:42 +01:00
.i18nrc.json Deprecate Cloud Defend 2025-03-11 15:45:13 +02:00
.telemetryrc.json
package.json chore(NA): bump version to 9.1.0 (#208990) 2025-01-31 06:05:13 +00:00
README.md SKA: Relocate "platform" packages that remain on /packages (#208704) 2025-02-24 11:03:30 +00:00

Elastic License Functionality

This directory tree contains files subject to the Elastic License 2.0. The files subject to the Elastic License 2.0 are grouped in this directory to clearly separate them from files licensed otherwise.

Alert Details page feature flags (feature-flag-per-App)

If you have:

xpack.observability.unsafe.alertDetails.uptime.enabled: true

[For Uptime rule type] In Kibana configuration, will allow the user to navigate to the new Alert Details page, instead of the Alert Flyout when clicking on View alert details in the Alert table

Development

By default, Kibana will run with X-Pack installed as mentioned in the contributing guide.

Elasticsearch will run with a basic license. To run with a trial license, including security, you can specifying that with the yarn es command.

Example: yarn es snapshot --license trial --password changeme

By default, this will also set the password for native realm accounts to the password provided (changeme by default). This includes that of the kibana_system user which elasticsearch.username defaults to in development. If you wish to specify a password for a given native realm account, you can do that like so: --password.kibana_system=notsecure

Testing

For information on testing, see the Elastic functional test development guide.

Running functional tests

The functional UI tests, the API integration tests, and the SAML API integration tests are all run against a live browser, Kibana, and Elasticsearch install. Each set of tests is specified with a unique config that describes how to start the Elasticsearch server, the Kibana server, and what tests to run against them. The sets of tests that exist today are functional UI tests (specified by this config), API integration tests (specified by this config), and SAML API integration tests (specified by this config).

The script runs all sets of tests sequentially like so:

  • builds Elasticsearch and X-Pack
  • runs Elasticsearch with X-Pack
  • starts up the Kibana server with X-Pack
  • runs the functional UI tests against those servers
  • tears down the servers
  • repeats the same process for the API and SAML API integration test configs.

To do all of this in a single command run:

node scripts/functional_tests

Developing functional UI tests

If you are developing functional tests then you probably don't want to rebuild Elasticsearch and wait for all that setup on every test run, so instead use this command to build and start just the Elasticsearch and Kibana servers:

node scripts/functional_tests_server

After the servers are started, open a new terminal and run this command to run just the tests (without tearing down Elasticsearch or Kibana):

node scripts/functional_test_runner

For both of the above commands, it's crucial that you pass in --config to specify the same config file to both commands. This makes sure that the right tests will run against the right servers. Typically a set of tests and server configuration go together.

Read more about how the scripts work here.

For a deeper dive, read more about the way functional tests and servers work here.

Running API integration tests

API integration tests are run with a unique setup usually without UI assets built for the Kibana server.

API integration tests are intended to test only programmatic API exposed by Kibana. There is no need to run browser and simulate user actions, which significantly reduces execution time. In addition, the configuration for API integration tests typically sets optimize.enabled=false for Kibana because UI assets are usually not needed for these tests.

To run only the API integration tests:

node scripts/functional_tests --config test/api_integration/config

Running SAML API integration tests

We also have SAML API integration tests which set up Elasticsearch and Kibana with SAML support. Run only API integration tests with SAML enabled like so:

node scripts/functional_tests --config test/security_api_integration/saml.config

Running Jest integration tests

Jest integration tests can be used to test behavior with Elasticsearch and the Kibana server.

yarn test:jest_integration

Running Reporting functional tests

See here for more information on running reporting tests.

Running Security Solution Cypress E2E/integration tests

See here for information on running this test suite.