Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
00a0e7b
[scout] catch bundles per page with CDP
dmlemeshko Feb 25, 2025
4bae636
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine Feb 25, 2025
0847108
move helpers to fixtures, update specs
dmlemeshko Feb 26, 2025
6865c0a
Merge branch 'space-time/perf-insights' of github.com:dmlemeshko/kiba…
dmlemeshko Feb 26, 2025
6dec967
update deps owner for renovate
dmlemeshko Feb 26, 2025
ac423be
refactor tests
dmlemeshko Feb 26, 2025
b62bab9
fix type error
dmlemeshko Feb 26, 2025
79e7718
Merge remote-tracking branch 'upstream/main' into space-time/perf-ins…
dmlemeshko Feb 27, 2025
ee4d62e
adjust timeouts, fix tests for svl
dmlemeshko Feb 27, 2025
3fb5990
update tests
dmlemeshko Mar 2, 2025
1e981a9
refactor perf tracker
dmlemeshko Mar 3, 2025
59126ee
fix tests for security solution
dmlemeshko Mar 3, 2025
bcb8d8c
Merge remote-tracking branch 'upstream/main' into space-time/perf-ins…
dmlemeshko Mar 6, 2025
d6e2880
update tests
dmlemeshko Mar 7, 2025
4dd3210
remove distName
dmlemeshko Mar 7, 2025
ee5dd49
update tests, add readme
dmlemeshko Mar 7, 2025
7b18e85
Merge branch 'main' into space-time/perf-insights
dmlemeshko Mar 7, 2025
c013c39
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine Mar 7, 2025
30f8cf0
Merge branch 'main' into space-time/perf-insights
dmlemeshko Mar 10, 2025
0e1c604
Merge branch 'main' into space-time/perf-insights
dmlemeshko Mar 10, 2025
ba0b788
Merge branch 'main' into space-time/perf-insights
dmlemeshko Mar 11, 2025
e0ac395
Merge remote-tracking branch 'upstream/main' into space-time/perf-ins…
dmlemeshko Mar 12, 2025
18bdfad
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine Mar 12, 2025
7d713b1
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Mar 12, 2025
c2687ed
Merge branch 'main' into space-time/perf-insights
dmlemeshko Mar 13, 2025
c2e67dd
Merge branch 'main' into space-time/perf-insights
dmlemeshko Mar 13, 2025
39a930d
Merge branch 'main' into space-time/perf-insights
dmlemeshko Mar 13, 2025
9029df5
review fixes
dmlemeshko Mar 14, 2025
63704c5
Merge remote-tracking branch 'upstream/main' into space-time/perf-ins…
dmlemeshko Mar 14, 2025
fdec218
update exp metrics
dmlemeshko Mar 14, 2025
dda8a2c
Merge branch 'space-time/perf-insights' of github.com:dmlemeshko/kiba…
dmlemeshko Mar 14, 2025
49e3fdd
Update post_command.sh
dmlemeshko Mar 14, 2025
a7fd660
remove space
dmlemeshko Mar 14, 2025
d7bea0a
Merge remote-tracking branch 'upstream/main' into space-time/perf-ins…
dmlemeshko Mar 14, 2025
2688c45
remove EOF
dmlemeshko Mar 14, 2025
66c5b9e
[CI] Auto-commit changed files from 'node scripts/capture_oas_snapsho…
kibanamachine Mar 14, 2025
cdfb6f8
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine Mar 14, 2025
ae19f6a
[CI] Auto-commit changed files from 'node scripts/capture_oas_snapsho…
kibanamachine Mar 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1797,6 +1797,7 @@
"json5": "^2.2.3",
"jsondiffpatch": "0.4.1",
"license-checker": "^25.0.1",
"lighthouse": "^12.4.0",
"listr2": "^8.2.5",
"lmdb": "^2.9.2",
"marge": "^1.0.1",
Expand Down
1 change: 1 addition & 0 deletions renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
"@types/supertest",
"@types/react-test-renderer",
"babel-plugin-istanbul",
"lighthouse",
"nyc",
"oboe",
"pixelmatch",
Expand Down
3 changes: 2 additions & 1 deletion src/platform/packages/shared/kbn-scout/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export {
expect,
test,
spaceTest,
lighthouseTest,
globalSetupHook,
tags,
createPlaywrightConfig,
Expand All @@ -38,6 +39,6 @@ export type {
} from './src/types';

// re-export from Playwright
export type { Locator } from 'playwright/test';
export type { Locator, CDPSession } from 'playwright/test';

export { measurePerformance, measurePerformanceAsync } from './src/common';
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import path from 'path';
import Fs from 'fs';
import { ToolingLog } from '@kbn/tooling-log';
import { saveScoutTestConfigOnDisk } from './save_scout_test_config';
import { ServerlessProjectType } from '@kbn/es';

const MOCKED_SCOUT_SERVERS_ROOT = '/mock/repo/root/scout/servers';

Expand All @@ -34,6 +35,7 @@ const testServersConfig = {
password: 'changeme',
},
serverless: true,
projectType: 'oblt' as ServerlessProjectType,
isCloud: true,
license: 'trial',
cloudUsersFilePath: '/path/to/users',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ describe('createPlaywrightConfig', () => {
expect(config.use).toEqual({
serversConfigDir: SCOUT_SERVERS_ROOT,
[VALID_CONFIG_MARKER]: true,
actionTimeout: 10000,
navigationTimeout: 20000,
screenshot: 'only-on-failure',
testIdAttribute: 'data-test-subj',
trace: 'on-first-retry',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ export function createPlaywrightConfig(options: ScoutPlaywrightOptions): Playwri
],
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
actionTimeout: 10000, // Shorten timeout for actions like `click()`
navigationTimeout: 20000, // Shorter timeout for page navigations
// 'configName' is not defined by default to enforce using '--project' flag when running the tests
testIdAttribute: 'data-test-subj',
serversConfigDir: SCOUT_SERVERS_ROOT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
esArchiverFixture,
uiSettingsFixture,
synthtraceFixture,
lighthouseFixture,
} from './worker';
import type {
EsArchiverFixture,
Expand All @@ -31,9 +32,12 @@ import {
browserAuthFixture,
pageObjectsFixture,
validateTagsFixture,
persistentContext,
perfTrackerFixture,
} from './test';
import type { BrowserAuthFixture, ScoutPage, PageObjects } from './test';
import type { BrowserAuthFixture, ScoutPage, PageObjects, PerfTrackerFixture } from './test';
export type { ScoutPage, PageObjects } from './test';
export type { LighthouseAuditOptions } from './worker';

export const scoutFixtures = mergeTests(
// worker scope fixtures
Expand All @@ -47,13 +51,16 @@ export const scoutFixtures = mergeTests(
browserAuthFixture,
scoutPageFixture,
pageObjectsFixture,
validateTagsFixture
validateTagsFixture,
// performance fixtures
perfTrackerFixture
);

export interface ScoutTestFixtures {
browserAuth: BrowserAuthFixture;
page: ScoutPage;
pageObjects: PageObjects;
perfTracker: PerfTrackerFixture;
}

export interface ScoutWorkerFixtures extends ApiFixtures {
Expand All @@ -68,3 +75,5 @@ export interface ScoutWorkerFixtures extends ApiFixtures {
infraSynthtraceEsClient: SynthtraceFixture['infraSynthtraceEsClient'];
otelSynthtraceEsClient: SynthtraceFixture['otelSynthtraceEsClient'];
}

export const lighthouseFixtures = mergeTests(scoutFixtures, persistentContext, lighthouseFixture);
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import * as os from 'os';
import getPort from 'get-port';
import { BrowserContext, chromium } from 'playwright/test';
import { coreWorkerFixtures } from '../../worker';

/**
* Launches browser with persistent context across multiple tests / browser windows in the same test.
* E.g. Lighthouse launches a new browser window and the authentication state
* is not persisted between windows by default, so we can't do page audit without persistent context.
*/
export const persistentContext = coreWorkerFixtures.extend<
{
context: BrowserContext;
},
{ debuggingPort: number }
>({
debuggingPort: [
async ({ log }, use) => {
const port = await getPort({ port: [9222, 9223, 9224] });
log.serviceLoaded(`remote debugging port [${port}]`);
use(port);
},
{ scope: 'worker' },
],
context: [
async ({ log, debuggingPort }, use) => {
const userDataDir = os.tmpdir();
const context = await chromium.launchPersistentContext(userDataDir, {
args: [`--remote-debugging-port=${debuggingPort}`],
});
log.serviceLoaded(`persistentContext on port [${debuggingPort}]`);
await use(context);
await context.close();
},
{ scope: 'test' },
],
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ export type { ScoutPage } from './scout_page';
export { validateTagsFixture } from './validate_tags';
export { pageObjectsFixture, pageObjectsParallelFixture } from './page_objects';
export type { PageObjects } from './page_objects';
export { persistentContext } from './context';
export { perfTrackerFixture } from './performance';
export type { PerfTrackerFixture } from './performance';
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import { PageObjects, createCorePageObjects } from '../../../page_objects';
import { ScoutSpaceParallelFixture } from '../../worker';
import { ScoutSpaceParallelFixture, ScoutTestConfig } from '../../worker';
import { scoutPageParallelFixture } from '../scout_page';

/**
Expand All @@ -23,10 +23,10 @@ export const pageObjectsParallelFixture = scoutPageParallelFixture.extend<
{
pageObjects: PageObjects;
},
{ scoutSpace: ScoutSpaceParallelFixture }
{ scoutSpace: ScoutSpaceParallelFixture; config: ScoutTestConfig }
>({
pageObjects: async ({ page, log }, use) => {
const corePageObjects = createCorePageObjects(page);
pageObjects: async ({ page, config, log }, use) => {
const corePageObjects = createCorePageObjects({ page, config, log });
log.serviceLoaded(`pageObjects`);
await use(corePageObjects);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

import { PageObjects, createCorePageObjects } from '../../../page_objects';
import { ScoutTestConfig } from '../../worker';
import { scoutPageFixture } from '../scout_page';

/**
Expand All @@ -18,11 +19,14 @@ import { scoutPageFixture } from '../scout_page';
*
* Note: Page Objects are lazily instantiated on first access.
*/
export const pageObjectsFixture = scoutPageFixture.extend<{
pageObjects: PageObjects;
}>({
pageObjects: async ({ page, log }, use) => {
const corePageObjects = createCorePageObjects(page);
export const pageObjectsFixture = scoutPageFixture.extend<
{
pageObjects: PageObjects;
},
{ config: ScoutTestConfig }
>({
pageObjects: async ({ page, log, config }, use) => {
const corePageObjects = createCorePageObjects({ page, config, log });
log.serviceLoaded('pageObjects');
await use(corePageObjects);
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
## Performance Tracker Fixture

### Overview

`perfTrackerFixture` is a Playwright 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.

### Key Features

- Uses CDP session to monitor network requests in Playwright tests.
- Exposes `waitForJsLoad` to ensure all incoming bundle requests are fully resolved before proceeding.
- Exposes `captureBundleResponses` to start tracking network requests and collect JavaScript bundle responses.
- Exposes `collectJsBundleStats` to aggregate all captured responses by plugin, making validation easier in tests.
- Automatically attaches collected JS bundle stats as a JSON artifact in test reports, making them available in the `Playwright HTML report`.
- Captures `CDP Performance Domain Metrics`, including:
- JavaScript Heap Usage (jsHeapUsedSize, jsHeapTotalSize)
- CPU Execution Time (cpuTime)
- Script Execution Time (scriptTime)
- Layout & Rendering Performance (layoutTime, layoutCount, styleRecalcCount)
- Frames Per Second (FPS) (fps)
- DOM Complexity Metrics (nodesCount, documentsCount)


### Usage: capturing JS bundles on page

```ts
test.describe(
'Discover App - Performance Metrics & Bundle Analysis',
{ tag: [...tags.DEPLOYMENT_AGNOSTIC, ...tags.PERFORMANCE] },
() => {
let cdp: CDPSession;

test.beforeEach(async ({ browserAuth, page, context, perfTracker }) => {
await browserAuth.loginAsAdmin();
cdp = await context.newCDPSession(page);
await cdp.send('Network.enable');
// load the starting page, e.g. '/app/home'
await perfTracker.waitForJsLoad(cdp); // Ensure JS bundles are fully loaded
});

test('collects and validates JS Bundles loaded on page', async ({
page,
pageObjects,
perfTracker,
}) => {
perfTracker.captureBundleResponses(cdp); // Start tracking

// Navigate to Discover app
await pageObjects.collapsibleNav.clickItem('Discover');
const currentUrl = page.url();
expect(currentUrl).toContain('app/discover#/');

// 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);
});
Comment on lines +56 to +82
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious to hear from plugin code owners about these assertions.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

metrics:

{
  "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": "aiops.chunk.2.js",
          "transferredSize": 3969
        }
      ]
    },
    {
      "name": "discover",
      "bundlesCount": 17,
      "totalSize": 631605,
      "bundles": [
        {
          "name": "discover.chunk.1.js",
          "transferredSize": 41915
        },
        {
          "name": "discover.chunk.10.js",
          "transferredSize": 12758
        },
        {
          "name": "discover.chunk.12.js",
          "transferredSize": 27177
        },
        {
          "name": "discover.chunk.13.js",
          "transferredSize": 32681
        },
        {
          "name": "discover.chunk.19.js",
          "transferredSize": 2212
        },
        {
          "name": "discover.chunk.2.js",
          "transferredSize": 27501
        },
        {
          "name": "discover.chunk.21.js",
          "transferredSize": 14149
        },
        {
          "name": "discover.chunk.22.js",
          "transferredSize": 14593
        },
        {
          "name": "discover.chunk.26.js",
          "transferredSize": 25119
        },
        {
          "name": "discover.chunk.27.js",
          "transferredSize": 3096
        },
        {
          "name": "discover.chunk.32.js",
          "transferredSize": 18630
        },
        {
          "name": "discover.chunk.4.js",
          "transferredSize": 148773
        },
        {
          "name": "discover.chunk.5.js",
          "transferredSize": 192584
        },
        {
          "name": "discover.chunk.6.js",
          "transferredSize": 6757
        },
        {
          "name": "discover.chunk.7.js",
          "transferredSize": 29444
        },
        {
          "name": "discover.chunk.8.js",
          "transferredSize": 7620
        },
        {
          "name": "discover.chunk.9.js",
          "transferredSize": 26596
        }
      ]
    },
    {
      "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
        },
        {
          "name": "expressionXY.chunk.3.js",
          "transferredSize": 189419
        },
        {
          "name": "expressionXY.chunk.4.js",
          "transferredSize": 3827
        },
        {
          "name": "expressionXY.chunk.5.js",
          "transferredSize": 2243
        },
        {
          "name": "expressionXY.chunk.6.js",
          "transferredSize": 2310
        }
      ]
    },
    {
      "name": "kbn-ui-shared-deps-npm",
      "bundlesCount": 33,
      "totalSize": 80062,
      "bundles": [
        {
          "name": "kbn-ui-shared-deps-npm.chunk.106.js",
          "transferredSize": 2373
        },
        {
          "name": "kbn-ui-shared-deps-npm.chunk.110.js",
          "transferredSize": 2315
        },
        {
          "name": "kbn-ui-shared-deps-npm.chunk.166.js",
          "transferredSize": 2361
        },
        {
          "name": "kbn-ui-shared-deps-npm.chunk.175.js",
          "transferredSize": 2298
        },
        {
          "name": "kbn-ui-shared-deps-npm.chunk.185.js",
          "transferredSize": 2410
        },
        {
          "name": "kbn-ui-shared-deps-npm.chunk.189.js",
          "transferredSize": 2430
        },
        {
          "name": "kbn-ui-shared-deps-npm.chunk.195.js",
          "transferredSize": 2301
        },
        {
          "name": "kbn-ui-shared-deps-npm.chunk.207.js",
          "transferredSize": 2412
        },
        {
          "name": "kbn-ui-shared-deps-npm.chunk.211.js",
          "transferredSize": 2374
        },
        {
          "name": "kbn-ui-shared-deps-npm.chunk.221.js",
          "transferredSize": 2420
        },
        {
          "name": "kbn-ui-shared-deps-npm.chunk.34.js",
          "transferredSize": 2618
        },
        {
          "name": "kbn-ui-shared-deps-npm.chunk.361.js",
          "transferredSize": 2301
        },
        {
          "name": "kbn-ui-shared-deps-npm.chunk.363.js",
          "transferredSize": 2323
        },
        {
          "name": "kbn-ui-shared-deps-npm.chunk.367.js",
          "transferredSize": 2544
        },
        {
          "name": "kbn-ui-shared-deps-npm.chunk.369.js",
          "transferredSize": 2336
        },
        {
          "name": "kbn-ui-shared-deps-npm.chunk.372.js",
          "transferredSize": 2723
        },
        {
          "name": "kbn-ui-shared-deps-npm.chunk.381.js",
          "transferredSize": 2511
        },
        {
          "name": "kbn-ui-shared-deps-npm.chunk.387.js",
          "transferredSize": 2376
        },
        {
          "name": "kbn-ui-shared-deps-npm.chunk.388.js",
          "transferredSize": 2368
        },
        {
          "name": "kbn-ui-shared-deps-npm.chunk.390.js",
          "transferredSize": 2352
        },
        {
          "name": "kbn-ui-shared-deps-npm.chunk.430.js",
          "transferredSize": 2642
        },
        {
          "name": "kbn-ui-shared-deps-npm.chunk.441.js",
          "transferredSize": 2807
        },
        {
          "name": "kbn-ui-shared-deps-npm.chunk.443.js",
          "transferredSize": 2402
        },
        {
          "name": "kbn-ui-shared-deps-npm.chunk.447.js",
          "transferredSize": 2391
        },
        {
          "name": "kbn-ui-shared-deps-npm.chunk.455.js",
          "transferredSize": 2416
        },
        {
          "name": "kbn-ui-shared-deps-npm.chunk.469.js",
          "transferredSize": 2443
        },
        {
          "name": "kbn-ui-shared-deps-npm.chunk.480.js",
          "transferredSize": 2488
        },
        {
          "name": "kbn-ui-shared-deps-npm.chunk.482.js",
          "transferredSize": 2485
        },
        {
          "name": "kbn-ui-shared-deps-npm.chunk.64.js",
          "transferredSize": 2373
        },
        {
          "name": "kbn-ui-shared-deps-npm.chunk.76.js",
          "transferredSize": 2300
        },
        {
          "name": "kbn-ui-shared-deps-npm.chunk.83.js",
          "transferredSize": 2464
        },
        {
          "name": "kbn-ui-shared-deps-npm.chunk.9.js",
          "transferredSize": 2356
        },
        {
          "name": "kbn-ui-shared-deps-npm.chunk.90.js",
          "transferredSize": 2349
        }
      ]
    },
    {
      "name": "lens",
      "bundlesCount": 12,
      "totalSize": 1570506,
      "bundles": [
        {
          "name": "lens.chunk.1.js",
          "transferredSize": 1049920
        },
        {
          "name": "lens.chunk.10.js",
          "transferredSize": 3750
        },
        {
          "name": "lens.chunk.11.js",
          "transferredSize": 7670
        },
        {
          "name": "lens.chunk.12.js",
          "transferredSize": 10194
        },
        {
          "name": "lens.chunk.13.js",
          "transferredSize": 34755
        },
        {
          "name": "lens.chunk.14.js",
          "transferredSize": 2178
        },
        {
          "name": "lens.chunk.15.js",
          "transferredSize": 2507
        },
        {
          "name": "lens.chunk.2.js",
          "transferredSize": 284826
        },
        {
          "name": "lens.chunk.4.js",
          "transferredSize": 117286
        },
        {
          "name": "lens.chunk.5.js",
          "transferredSize": 41750
        },
        {
          "name": "lens.chunk.7.js",
          "transferredSize": 5830
        },
        {
          "name": "lens.chunk.9.js",
          "transferredSize": 9840
        }
      ]
    },
    {
      "name": "maps",
      "bundlesCount": 1,
      "totalSize": 44110,
      "bundles": [
        {
          "name": "maps.chunk.9.js",
          "transferredSize": 44110
        }
      ]
    },
    {
      "name": "unifiedHistogram",
      "bundlesCount": 3,
      "totalSize": 143461,
      "bundles": [
        {
          "name": "unifiedHistogram.chunk.1.js",
          "transferredSize": 44713
        },
        {
          "name": "unifiedHistogram.chunk.2.js",
          "transferredSize": 80110
        },
        {
          "name": "unifiedHistogram.chunk.5.js",
          "transferredSize": 18638
        }
      ]
    },
    {
      "name": "unifiedSearch",
      "bundlesCount": 13,
      "totalSize": 445915,
      "bundles": [
        {
          "name": "unifiedSearch.chunk.1.js",
          "transferredSize": 202563
        },
        {
          "name": "unifiedSearch.chunk.10.js",
          "transferredSize": 10508
        },
        {
          "name": "unifiedSearch.chunk.12.js",
          "transferredSize": 91557
        },
        {
          "name": "unifiedSearch.chunk.13.js",
          "transferredSize": 10287
        },
        {
          "name": "unifiedSearch.chunk.14.js",
          "transferredSize": 3740
        },
        {
          "name": "unifiedSearch.chunk.15.js",
          "transferredSize": 6307
        },
        {
          "name": "unifiedSearch.chunk.2.js",
          "transferredSize": 32739
        },
        {
          "name": "unifiedSearch.chunk.20.js",
          "transferredSize": 5306
        },
        {
          "name": "unifiedSearch.chunk.4.js",
          "transferredSize": 6703
        },
        {
          "name": "unifiedSearch.chunk.5.js",
          "transferredSize": 21393
        },
        {
          "name": "unifiedSearch.chunk.6.js",
          "transferredSize": 25519
        },
        {
          "name": "unifiedSearch.chunk.7.js",
          "transferredSize": 14076
        },
        {
          "name": "unifiedSearch.chunk.8.js",
          "transferredSize": 15217
        }
      ]
    }
  ]
}

```

### Uage: collecting CDP Performance metrics

```ts
test.describe(
'Discover App - Performance Metrics & Bundle Analysis',
{ tag: [...tags.DEPLOYMENT_AGNOSTIC, ...tags.PERFORMANCE] },
() => {
let cdp: CDPSession;

test.beforeEach(async ({ browserAuth, page, context, perfTracker }) => {
await browserAuth.loginAsAdmin();
cdp = await context.newCDPSession(page);
// load the starting page, e.g. '/app/home' and wait for loading to finish
});

test('measures Performance Metrics before and after Discover load', async ({
page,
pageObjects,
perfTracker,
}) => {
const beforeMetrics = await perfTracker.capturePagePerformanceMetrics(cdp);

// Navigate to Discover app
await pageObjects.collapsibleNav.clickItem('Discover');
await page.waitForLoadingIndicatorHidden();
const currentUrl = page.url();
expect(currentUrl).toContain('app/discover#/');

await pageObjects.discover.waitForHistogramRendered();

const afterMetrics = await perfTracker.capturePagePerformanceMetrics(cdp);
const perfStats = perfTracker.collectPagePerformanceStats(
currentUrl,
beforeMetrics,
afterMetrics
);

expect(perfStats.cpuTime.diff).toBeLessThan(1.5); // CPU time (seconds) usage during page navigation
expect(perfStats.scriptTime.diff).toBeLessThan(0.4); // Additional time (seconds) spent executing JS scripts
expect(perfStats.layoutTime.diff).toBeLessThan(0.06); // Total layout computation time (seconds)
});
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { coreWorkerFixtures } from '../../worker';
import { PerformanceTracker } from './performance_tracker';

export const perfTrackerFixture = coreWorkerFixtures.extend<{ perfTracker: PerformanceTracker }>({
perfTracker: [
async ({ log }, use, testInfo) => {
log.serviceLoaded('perfTracker');

const tracker = new PerformanceTracker(testInfo);
await use(tracker);
},
{ scope: 'test' },
],
});

export type PerfTrackerFixture = ReturnType<typeof perfTrackerFixture>;
Loading