Skip to content

ci: Add new metrics overhead app #7300

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
merged 4 commits into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions packages/overhead-metrics/configs/ci/collect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Metrics } from '../../src/collector.js';
import { MetricsCollector } from '../../src/collector.js';
import type { NumberProvider } from '../../src/results/metrics-stats.js';
import { MetricsStats } from '../../src/results/metrics-stats.js';
import { JankTestScenario } from '../../src/scenarios.js';
import { BookingAppScenario } from '../../src/scenarios.js';
import { printStats } from '../../src/util/console.js';
import { latestResultFile } from './env.js';

Expand All @@ -26,9 +26,9 @@ const collector = new MetricsCollector({ headless: true, cpuThrottling: 2 });
const result = await collector.execute({
name: 'jank',
scenarios: [
new JankTestScenario('index.html'),
new JankTestScenario('with-sentry.html'),
new JankTestScenario('with-replay.html'),
new BookingAppScenario('index.html', 100),
new BookingAppScenario('with-sentry.html', 100),
new BookingAppScenario('with-replay.html', 100),
],
runs: 10,
tries: 10,
Expand Down
11 changes: 7 additions & 4 deletions packages/overhead-metrics/configs/dev/collect.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import type { Metrics } from '../../src/collector.js';
import { MetricsCollector } from '../../src/collector.js';
import { MetricsStats } from '../../src/results/metrics-stats.js';
import { JankTestScenario } from '../../src/scenarios.js';
import { BookingAppScenario } from '../../src/scenarios.js';
import { printStats } from '../../src/util/console.js';
import { latestResultFile } from './env.js';

const collector = new MetricsCollector();
const result = await collector.execute({
name: 'dummy',
scenarios: [
new JankTestScenario('index.html'),
new JankTestScenario('with-sentry.html'),
new JankTestScenario('with-replay.html'),
new BookingAppScenario('index.html', 50),
new BookingAppScenario('with-sentry.html', 50),
new BookingAppScenario('with-replay.html', 50),
new BookingAppScenario('index.html', 500),
new BookingAppScenario('with-sentry.html', 500),
new BookingAppScenario('with-replay.html', 500),
],
runs: 1,
tries: 1,
Expand Down
1 change: 1 addition & 0 deletions packages/overhead-metrics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"build": "tsc",
"dev:collect": "ts-node-esm ./configs/dev/collect.ts",
"dev:process": "ts-node-esm ./configs/dev/process.ts",
"dev:run:replay": "npx chrome ./test-apps/booking-app/with-replay.html",
"ci:collect": "ts-node-esm ./configs/ci/collect.ts",
"ci:process": "ts-node-esm ./configs/ci/process.ts",
"fix": "run-s fix:eslint fix:prettier",
Expand Down
4 changes: 4 additions & 0 deletions packages/overhead-metrics/src/results/metrics-stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ export class MetricsStats {
private static _filteredValues(numbers: number[]): number[] {
numbers.sort((a, b) => a - b);

if (numbers.length < 1) {
return [];
}

const q1 = ss.quantileSorted(numbers, 0.25);
const q3 = ss.quantileSorted(numbers, 0.75);
const iqr = q3 - q1;
Expand Down
25 changes: 25 additions & 0 deletions packages/overhead-metrics/src/scenarios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,28 @@ export class JankTestScenario implements Scenario {
await new Promise(resolve => setTimeout(resolve, 12000));
}
}

export class BookingAppScenario implements Scenario {
public constructor(private _indexFile: string, private _count: number) {}

/**
*
*/
public async run(_: playwright.Browser, page: playwright.Page): Promise<void> {
let url = path.resolve(`./test-apps/booking-app/${this._indexFile}`);
assert(fs.existsSync(url));
url = `file:///${url.replace(/\\/g, '/')}?count=${this._count}`;
console.log('Navigating to ', url);
await page.goto(url, { waitUntil: 'load', timeout: 60000 });

// Click "Update"
await page.click('#search button');

for (let i = 1; i < 10; i++) {
await page.click(`.result:nth-child(${i}) [data-select]`);
}

// Wait for flushing, which we set to 2000ms - to be safe, we add 1s on top
await new Promise(resolve => setTimeout(resolve, 3000));
}
}
10 changes: 4 additions & 6 deletions packages/overhead-metrics/src/vitals/cls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ class CLS {

const observer = new PerformanceObserver((list) => {
for (const entry of list.getEntries()) {
if (!entry.hadRecentInput) {
if (window.cumulativeLayoutShiftScore === undefined) {
window.cumulativeLayoutShiftScore = entry.value;
} else {
window.cumulativeLayoutShiftScore += entry.value;
}
if (window.cumulativeLayoutShiftScore === undefined) {
Copy link
Member

@Lms24 Lms24 Feb 28, 2023

Choose a reason for hiding this comment

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

q: That's the reason for removing this guard here?

Copy link
Member

Choose a reason for hiding this comment

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

Nevermind, I missed that you just rewrote this.

window.cumulativeLayoutShiftScore = entry.value;
} else if (!entry.hadRecentInput) {
window.cumulativeLayoutShiftScore += entry.value;
}
}
});
Expand Down
219 changes: 219 additions & 0 deletions packages/overhead-metrics/test-apps/booking-app/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<title>Demo Booking Engine</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<meta name="robots" content="noindex" />

<style>
html,
body {
margin: 0;
padding: 0;
}

body {
color: #4a4a4a;
font-size: 1em;
font-weight: 400;
line-height: 1.5;
font-family: system-ui, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica Neue, Arial, sans-serif;
box-sizing: border-box;
}

*,
*:before,
*:after {
font-family: inherit;
box-sizing: inherit;
}

.header {
margin-bottom: 1.5rem;
padding: 3rem;
}

.header h1 {
margin: 0 0 1em 0;
}

.search-form {
margin-bottom: 1.5rem;
}

.search-form-fields {
display: flex;
flex-basis: 0;
flex-grow: 5;
flex-shrink: 1;
}

.result {
margin-bottom: 1em;
padding-bottom: 1em;
border-bottom: 1px solid #dbdbdb;
display: flex;
}

.result-image {
width: 350px;
margin: 0 1.5em 0 0;
padding: 0;
}

.result-image img {
display: block;
}

.result-content h3 {
margin-top: 0;
margin-bottom: 0.5em;
}

.tags {
display: flex;
gap: 0.5em;
flex-wrap: wrap;
margin-bottom: 1.5rem;
}

.tag {
background-color: #f5f5f5;
border-radius: 4px;
color: #4a4a4a;
display: inline-flex;
font-size: 0.75rem;
line-height: 2;
justify-content: center;
padding-left: 0.75em;
padding-right: 0.75em;
white-space: nowrap;
}

.long-text {
margin-bottom: 1.5rem;
}

[data-long-text-open],
[data-long-text-close] {
all: unset;
font-weight: bold;
cursor: pointer;
}

:not([data-show-long]) > .long-text__long {
display: none;
}

[data-show-long] > .long-text__short {
display: none;
}

.select {
}

.select button {
font-size: 1.25em;
padding: 0.25em;
display: flex;
width: 100%;
gap: 0.25em;
}

.select__price {
margin-left: auto;
display: flex;
}

.price__amount {
font-weight: bold;
}

.options {
display: flex;
gap: 0.5em;
}

.result:not([data-show-options='yes']) .options {
display: none;
}

.result[data-show-options='yes'] .select {
display: none;
}
</style>
</head>

<body>
<div class="">
<div class="header">
<h1>This is a test app.</h1>

<div class="search-form">
<form name="search" id="search" data-form-state="0" action="" method="POST">
<div class="search-form-fields">
<div class="field">
<label for="check-in">Check-in</label>
<input name="check-in" type="date" class="input" />
</div>

<div class="field">
<label for="check-out">Check-out</label>
<input name="check-out" type="date" class="input" />
</div>

<div class="field">
<label for="adults">Number of persons</label>
<select name="adults">
<option value="1">1</option>
<option value="2" selected="">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
</select>
</div>

<div class="field">
<button type="submit">Update</button>
</div>
</div>
</form>
</div>

<div>
<form name="book" id="book" method="post">
<div class="result-list"></div>
</form>
</div>
</div>
</div>

<script src="./main.js"></script>
</body>
</html>
Loading