Skip to content
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

feat(fetch): record timings #32613

Merged
merged 15 commits into from
Sep 17, 2024
Merged

Conversation

Skn0tt
Copy link
Member

@Skn0tt Skn0tt commented Sep 13, 2024

Related to #19621

Adds some instrumentation to collect timings for APIRequestContext requests and adds them to the HAR trace. Doesn't yet expose them via an API, but makes our Duration field in the trace viewer show a nice duration:

Screenshot 2024-09-14 at 11 46 04

I'm gonna add it to our API in a separate PR.

@Skn0tt Skn0tt self-assigned this Sep 13, 2024

This comment has been minimized.

@Skn0tt Skn0tt changed the title feat(library): record timings for APIRequestContext feat(fetch): record timings Sep 14, 2024

This comment has been minimized.

This comment has been minimized.

@Skn0tt Skn0tt marked this pull request as ready for review September 14, 2024 10:19
@Skn0tt Skn0tt requested a review from dgozman September 14, 2024 10:19

This comment has been minimized.

@@ -132,9 +134,13 @@ export async function createConnectionAsync(
port: options.port as number,
host: address });

(socket as any).dnsLookupAt = dnsLookupAt;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should make this a proper part of the API in some way.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agree it's a little hacky, but I can't find anything better. How would you do it?

Copy link
Contributor

Choose a reason for hiding this comment

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

Create a function here called timingForSocket(socket) that can read values that were set through symbols to avoid clashing with proper fields. Basically, encapsulate the internal symbols to this file.

packages/playwright-core/src/server/har/harTracer.ts Outdated Show resolved Hide resolved
const request = requestConstructor(url, requestOptions as any, async response => {
const notifyRequestFinished = (body?: Buffer) => {
const timings: har.Timings = {
send: requestFinishAt! - startAt,
wait: firstByteAt! - requestFinishAt!,
Copy link
Contributor

Choose a reason for hiding this comment

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

What if body was empty, and we did not set firstByteAt?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch. I've replaced firstByteAt with a measure of when the response headers are sent in 5d8ab8a. I think that's more in-line with the HAR definition anyways.

packages/playwright-core/src/server/fetch.ts Show resolved Hide resolved
wait: firstByteAt! - requestFinishAt!,
receive: endAt! - firstByteAt!,
dns: dnsLookupAt ? dnsLookupAt - startAt : -1,
connect: (tlsHandshakeAt ?? tcpConnectionAt!) - startAt,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just tcpConnectionAt - startAt? This warrants a comment at least.

Copy link
Member Author

Choose a reason for hiding this comment

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

fair! added comments in 9479423

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

packages/playwright-core/src/server/fetch.ts Outdated Show resolved Hide resolved
@@ -132,9 +134,13 @@ export async function createConnectionAsync(
port: options.port as number,
host: address });

(socket as any).dnsLookupAt = dnsLookupAt;
Copy link
Contributor

Choose a reason for hiding this comment

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

Create a function here called timingForSocket(socket) that can read values that were set through symbols to avoid clashing with proper fields. Basically, encapsulate the internal symbols to this file.

Skn0tt and others added 2 commits September 17, 2024 08:59
Co-authored-by: Dmitry Gozman <dgozman@gmail.com>
Signed-off-by: Simon Knott <info@simonknott.de>

This comment has been minimized.

@Skn0tt
Copy link
Member Author

Skn0tt commented Sep 17, 2024

Should we be respecting options.omitTiming? I think it makes sense for timing, but I don't think we should respect options.omitCookies for API Requests for example.

This comment has been minimized.

@dgozman
Copy link
Contributor

dgozman commented Sep 17, 2024

Should we be respecting options.omitTiming? I think it makes sense for timing, but I don't think we should respect options.omitCookies for API Requests for example.

Nice catch! I think we should respect all the options.

@Skn0tt
Copy link
Member Author

Skn0tt commented Sep 17, 2024

I've implemented omitTiming in f4a986e, and will do the rest in a separate PR.

@Skn0tt Skn0tt merged commit 751b939 into microsoft:main Sep 17, 2024
27 of 29 checks passed
Copy link
Contributor

Test results for "tests 1"

1 failed
❌ [playwright-test] › babel.spec.ts:135:5 › should not transform external

1 flaky ⚠️ [webkit-library] › library/browsercontext-clearcookies.spec.ts:146:3 › should remove cookies by name and domain

35483 passed, 659 skipped
✔️✔️✔️

Merge workflow run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants