-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[Space time] extending Scout with perfTracker fixture #212397
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
Merged
dmlemeshko
merged 38 commits into
elastic:main
from
dmlemeshko:space-time/perf-insights
Mar 14, 2025
Merged
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 4bae636
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine 0847108
move helpers to fixtures, update specs
dmlemeshko 6865c0a
Merge branch 'space-time/perf-insights' of github.com:dmlemeshko/kiba…
dmlemeshko 6dec967
update deps owner for renovate
dmlemeshko ac423be
refactor tests
dmlemeshko b62bab9
fix type error
dmlemeshko 79e7718
Merge remote-tracking branch 'upstream/main' into space-time/perf-ins…
dmlemeshko ee4d62e
adjust timeouts, fix tests for svl
dmlemeshko 3fb5990
update tests
dmlemeshko 1e981a9
refactor perf tracker
dmlemeshko 59126ee
fix tests for security solution
dmlemeshko bcb8d8c
Merge remote-tracking branch 'upstream/main' into space-time/perf-ins…
dmlemeshko d6e2880
update tests
dmlemeshko 4dd3210
remove distName
dmlemeshko ee5dd49
update tests, add readme
dmlemeshko 7b18e85
Merge branch 'main' into space-time/perf-insights
dmlemeshko c013c39
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine 30f8cf0
Merge branch 'main' into space-time/perf-insights
dmlemeshko 0e1c604
Merge branch 'main' into space-time/perf-insights
dmlemeshko ba0b788
Merge branch 'main' into space-time/perf-insights
dmlemeshko e0ac395
Merge remote-tracking branch 'upstream/main' into space-time/perf-ins…
dmlemeshko 18bdfad
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine 7d713b1
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine c2687ed
Merge branch 'main' into space-time/perf-insights
dmlemeshko c2e67dd
Merge branch 'main' into space-time/perf-insights
dmlemeshko 39a930d
Merge branch 'main' into space-time/perf-insights
dmlemeshko 9029df5
review fixes
dmlemeshko 63704c5
Merge remote-tracking branch 'upstream/main' into space-time/perf-ins…
dmlemeshko fdec218
update exp metrics
dmlemeshko dda8a2c
Merge branch 'space-time/perf-insights' of github.com:dmlemeshko/kiba…
dmlemeshko 49e3fdd
Update post_command.sh
dmlemeshko a7fd660
remove space
dmlemeshko d7bea0a
Merge remote-tracking branch 'upstream/main' into space-time/perf-ins…
dmlemeshko 2688c45
remove EOF
dmlemeshko 66c5b9e
[CI] Auto-commit changed files from 'node scripts/capture_oas_snapsho…
kibanamachine cdfb6f8
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine ae19f6a
[CI] Auto-commit changed files from 'node scripts/capture_oas_snapsho…
kibanamachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/platform/packages/shared/kbn-scout/src/playwright/fixtures/test/context/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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' }, | ||
| ], | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
...rm/packages/shared/kbn-scout/src/playwright/fixtures/test/performance/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. | ||
dmlemeshko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ### 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm curious to hear from plugin code owners about these assertions.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. metrics: |
||
| ``` | ||
|
|
||
| ### 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) | ||
| }); | ||
| ``` | ||
25 changes: 25 additions & 0 deletions
25
src/platform/packages/shared/kbn-scout/src/playwright/fixtures/test/performance/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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>; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.