Skip to content

[8.x] [Space time] extending Scout with perfTracker fixture (#212397)#215141

Merged
dmlemeshko merged 6 commits intoelastic:8.xfrom
dmlemeshko:backport/8.x/pr-212397
Mar 19, 2025
Merged

[8.x] [Space time] extending Scout with perfTracker fixture (#212397)#215141
dmlemeshko merged 6 commits intoelastic:8.xfrom
dmlemeshko:backport/8.x/pr-212397

Conversation

@dmlemeshko
Copy link
Contributor

Backport

This will backport the following commits from main to 8.x:

Questions ?

Please refer to the Backport tool documentation

## Summary

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

revisiting old PR elastic#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](https://github.com/elastic/kibana/blob/c013c39b7ed92248b94716d953ad692e9328a08d/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:
https://github.com/elastic/kibana/blob/7b18e85541d00c3c33a9640cd38a5896b3a758ed/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>
(cherry picked from commit b5f158b)

# Conflicts:
#	renovate.json
#	yarn.lock
@dmlemeshko dmlemeshko added the backport This PR is a backport of another PR label Mar 19, 2025
@dmlemeshko dmlemeshko enabled auto-merge (squash) March 19, 2025 11:33
@dmlemeshko dmlemeshko requested a review from pheyos March 19, 2025 11:35
kibanamachine and others added 4 commits March 19, 2025 12:04
…t --include-path /api/status --include-path /api/alerting/rule/ --include-path /api/alerting/rules --include-path /api/actions --include-path /api/security/role --include-path /api/spaces --include-path /api/dashboards --update --no-serverless'
@dmlemeshko dmlemeshko merged commit 0c2e8cd into elastic:8.x Mar 19, 2025
8 checks passed
@elasticmachine
Copy link
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #75 / @ess @serverless @serverlessQA SecuritySolution Timeline @skipInServerless Timeline migrations 8.0 id migration "before all" hook in "8.0 id migration"

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/scout 105 109 +4
@kbn/scout-oblt 65 66 +1
total +5

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
@kbn/scout 16 19 +3
Unknown metric groups

API count

id before after diff
@kbn/scout 396 420 +24
@kbn/scout-oblt 356 357 +1
total +25

History

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport This PR is a backport of another PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants