-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
misc: receive afterSpec durations from app capture code, and report them to the Cloud API #29500
Merged
Merged
Changes from 20 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
5c0b0a3
misc: report protocol capture afterSpec duration to cloud
cacieprins 37e93ce
WIP: collecting afterSpec durations, TODO: system test scaffolding
cacieprins 2fd2de2
Merge branch 'develop' into cacie/misc/record-tr-afterspec-timing
cacieprins abe9bf6
push all afterSpec timings to cloud
cacieprins 6fb1a51
push afterSpecTotal instead of afterSpec property
cacieprins 1ebcf77
Merge branch 'develop' into cacie/misc/record-tr-afterspec-timing
cacieprins 78acd61
Merge branch 'develop' into cacie/misc/record-tr-afterspec-timing
cacieprins 0083c44
changelog
cacieprins 86367ae
fix trailing slash in readme
cacieprins 16fa3db
fix afterspec duration unit test
cacieprins 96d0519
Merge branch 'develop' into cacie/misc/record-tr-afterspec-timing
cacieprins 8378e9d
correct return signature of afterSpec; add debug
cacieprins 8e8c9aa
Merge branch 'develop' into cacie/misc/record-tr-afterspec-timing
cacieprins 5936bff
changelog
cacieprins c5ddeb3
Update packages/server/lib/cloud/api/index.ts
cacieprins b97e748
Update packages/server/lib/cloud/protocol.ts
cacieprins 18c2809
fix ts check
cacieprins 9219138
Merge branch 'develop' into cacie/misc/record-tr-afterspec-timing
cacieprins 53c5ae4
fix unit tests re: expected afterSpec sig
cacieprins ce66723
fix return sig of protocol afterSpec stub for system tests
cacieprins 7dd103b
use env var directly in tests for capture error codepath, rather than…
cacieprins b986f42
Merge branch 'develop' into cacie/misc/record-tr-afterspec-timing
cacieprins 5a50875
Merge branch 'develop' into cacie/misc/record-tr-afterspec-timing
cacieprins d54c018
Merge branch 'develop' into cacie/misc/record-tr-afterspec-timing
cacieprins 3b2a2e2
Merge branch 'develop' into cacie/misc/record-tr-afterspec-timing
cacieprins 53d792d
Merge branch 'develop' into cacie/misc/record-tr-afterspec-timing
cacieprins 834fc65
Merge branch 'develop' into cacie/misc/record-tr-afterspec-timing
cacieprins fbc720b
Merge branch 'develop' into cacie/misc/record-tr-afterspec-timing
cacieprins 6d1307a
rm unused param
cacieprins a6ad4a1
bump cache
cacieprins c2536a5
Merge branch 'develop' into cacie/misc/record-tr-afterspec-timing
jennifer-shehane efce271
changelog
cacieprins c7a41cd
remove pending runnables duration from afterspec report
cacieprins 87e77fa
Merge branch 'develop' into cacie/misc/record-tr-afterspec-timing
jennifer-shehane 53448a7
Merge branch 'develop' into cacie/misc/record-tr-afterspec-timing
cacieprins File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
|
@@ -7,15 +7,14 @@ import fs from 'fs-extra' | |
import Module from 'module' | ||
import os from 'os' | ||
import path from 'path' | ||
|
||
import { agent } from '@packages/network' | ||
import pkg from '@packages/root' | ||
|
||
import { performance } from 'perf_hooks' | ||
import env from '../util/env' | ||
import { putProtocolArtifact } from './api/put_protocol_artifact' | ||
|
||
import type { Readable } from 'stream' | ||
import type { ProtocolManagerShape, AppCaptureProtocolInterface, CDPClient, ProtocolError, CaptureArtifact, ProtocolErrorReport, ProtocolCaptureMethod, ProtocolManagerOptions, ResponseStreamOptions, ResponseEndedWithEmptyBodyOptions, ResponseStreamTimedOutOptions } from '@packages/types' | ||
import type { ProtocolManagerShape, AppCaptureProtocolInterface, CDPClient, ProtocolError, CaptureArtifact, ProtocolErrorReport, ProtocolCaptureMethod, ProtocolManagerOptions, ResponseStreamOptions, ResponseEndedWithEmptyBodyOptions, ResponseStreamTimedOutOptions, AfterSpecDurations } from '@packages/types' | ||
|
||
const routes = require('./routes') | ||
|
||
|
@@ -25,7 +24,7 @@ const debugVerbose = Debug('cypress-verbose:server:protocol') | |
const CAPTURE_ERRORS = !process.env.CYPRESS_LOCAL_PROTOCOL_PATH | ||
const DELETE_DB = !process.env.CYPRESS_LOCAL_PROTOCOL_PATH | ||
|
||
const DB_SIZE_LIMIT = 5000000000 | ||
export const DB_SIZE_LIMIT = 5000000000 | ||
|
||
const dbSizeLimit = () => { | ||
return env.get('CYPRESS_INTERNAL_SYSTEM_TESTS') === '1' ? | ||
|
@@ -59,6 +58,9 @@ export class ProtocolManager implements ProtocolManagerShape { | |
private _protocol: AppCaptureProtocolInterface | undefined | ||
private _runnableId: string | undefined | ||
private _captureHash: string | undefined | ||
private _afterSpecDurations: AfterSpecDurations & { | ||
afterSpecTotal: number | ||
} | undefined | ||
|
||
get protocolEnabled (): boolean { | ||
return !!this._protocol | ||
|
@@ -130,6 +132,8 @@ export class ProtocolManager implements ProtocolManagerShape { | |
} | ||
|
||
beforeSpec (spec: { instanceId: string }) { | ||
this._afterSpecDurations = undefined | ||
|
||
if (!this._protocol) { | ||
return | ||
} | ||
|
@@ -170,7 +174,30 @@ export class ProtocolManager implements ProtocolManagerShape { | |
} | ||
|
||
async afterSpec () { | ||
await this.invokeAsync('afterSpec', { isEssential: true }) | ||
const startTime = performance.now() + performance.timeOrigin | ||
|
||
try { | ||
const ret = await this.invokeAsync('afterSpec', { isEssential: true }) | ||
const durations = ret?.durations | ||
|
||
const afterSpecTotal = (performance.now() + performance.timeOrigin) - startTime | ||
|
||
this._afterSpecDurations = { | ||
afterSpecTotal, | ||
...(durations ? durations : {}), | ||
} | ||
|
||
debug('Persisting after spec durations in state: %O', this._afterSpecDurations) | ||
|
||
return undefined | ||
} catch (e) { | ||
// rethrow; this is try/catch so we can 'finally' ascertain duration | ||
this._afterSpecDurations = { | ||
afterSpecTotal: (performance.now() + performance.timeOrigin - startTime), | ||
} | ||
|
||
throw e | ||
} | ||
} | ||
|
||
async beforeTest (test: { id: string } & Record<string, any>) { | ||
|
@@ -277,11 +304,7 @@ export class ProtocolManager implements ProtocolManagerShape { | |
} | ||
} | ||
|
||
async uploadCaptureArtifact ({ uploadUrl, fileSize, filePath }: CaptureArtifact): Promise<{ | ||
success: boolean | ||
fileSize: number | bigint | ||
specAccess: ReturnType<AppCaptureProtocolInterface['getDbMetadata']> | ||
} | undefined> { | ||
async uploadCaptureArtifact ({ uploadUrl, fileSize, filePath }: CaptureArtifact, captureErrorsOverride?: boolean) { | ||
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. Is captureErrorsOverride just used for testing purposes? 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. Yep. Could refactor a bit to have caller pass in the env var to make things a little cleaner. |
||
if (!this._protocol || !filePath || !this._db) { | ||
debug('not uploading due to one of the following being falsy: %O', { | ||
_protocol: !!this._protocol, | ||
|
@@ -292,6 +315,8 @@ export class ProtocolManager implements ProtocolManagerShape { | |
return | ||
} | ||
|
||
const captureErrors = captureErrorsOverride ?? CAPTURE_ERRORS | ||
|
||
debug(`uploading %s to %s with a file size of %s`, filePath, uploadUrl, fileSize) | ||
|
||
try { | ||
|
@@ -301,9 +326,12 @@ export class ProtocolManager implements ProtocolManagerShape { | |
fileSize, | ||
success: true, | ||
specAccess: this._protocol.getDbMetadata(), | ||
...(this._afterSpecDurations ? { | ||
afterSpecDurations: this._afterSpecDurations, | ||
} : {}), | ||
} | ||
} catch (e) { | ||
if (CAPTURE_ERRORS) { | ||
if (captureErrors) { | ||
this._errors.push({ | ||
error: e, | ||
captureMethod: 'uploadCaptureArtifact', | ||
|
@@ -403,9 +431,9 @@ export class ProtocolManager implements ProtocolManagerShape { | |
* Abstracts invoking a synchronous method on the AppCaptureProtocol instance, so we can handle | ||
* errors in a uniform way | ||
*/ | ||
private async invokeAsync <K extends ProtocolAsyncMethods> (method: K, { isEssential }: { isEssential: boolean }, ...args: Parameters<AppCaptureProtocolInterface[K]>) { | ||
private async invokeAsync <K extends ProtocolAsyncMethods> (method: K, { isEssential }: { isEssential: boolean }, ...args: Parameters<AppCaptureProtocolInterface[K]>): Promise<ReturnType<AppCaptureProtocolInterface[K]> | undefined> { | ||
if (!this._protocol) { | ||
return | ||
return undefined | ||
} | ||
|
||
try { | ||
|
@@ -417,6 +445,8 @@ export class ProtocolManager implements ProtocolManagerShape { | |
} else { | ||
throw error | ||
} | ||
|
||
return undefined | ||
} | ||
} | ||
|
||
|
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AfterSpecDurations
is the shape that the protocol capture codebase will return; we're augmenting that with the total duration ofafterSpec
, so the shape is modified here.