-
Notifications
You must be signed in to change notification settings - Fork 60
feat(core): upload the snapshot log to the logs endpoint, not as a resource (PPLT-6034) #2417
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
Changes from all commits
6a164ef
b0a6575
f8fcfb1
dd06438
b947260
427346f
62dbc5d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| import logger from '@percy/logger'; | ||
| import PercyConfig from '@percy/config'; | ||
| import micromatch from 'micromatch'; | ||
| import Pako from 'pako'; | ||
| import { configSchema } from './config.js'; | ||
| import Queue from './queue.js'; | ||
| import { | ||
|
|
@@ -10,7 +11,9 @@ import { | |
| snapshotLogName, | ||
| decodeAndEncodeURLWithLogging, | ||
| compareObjectTypes, | ||
| normalizeOptions | ||
| normalizeOptions, | ||
| base64encode, | ||
| redactSecrets | ||
| } from './utils.js'; | ||
| import { JobData } from './wait-for-job.js'; | ||
|
|
||
|
|
@@ -393,6 +396,30 @@ async function runDoctorOnFailure(percy) { | |
| } | ||
| } | ||
|
|
||
| // Uploads a single web snapshot's CLI log to the logs endpoint, keyed by the | ||
| // snapshot id, so it lands directly in the log bucket instead of travelling as a | ||
| // snapshot resource. Best-effort: a failure here must never fail the snapshot. | ||
| export async function uploadSnapshotLog(percy, buildId, snapshotId, meta = {}) { | ||
| try { | ||
| if (!buildId || !snapshotId) return; | ||
|
|
||
| // Redact secrets before egress (CWE-532) — this per-snapshot log is a | ||
| // parallel egress path to sendBuildLogs and must scrub tokens/credentials. | ||
| let logs = redactSecrets(logger.snapshotLogs(meta.snapshot)); | ||
| if (!logs.length) return; | ||
|
|
||
| let content = base64encode(Pako.gzip(JSON.stringify(logs))); | ||
| await percy.client.sendSnapshotLog(buildId, snapshotId, content, meta); | ||
| percy.log.debug(`Snapshot log sent for ${meta.snapshot?.name}`, meta); | ||
| } catch (err) { | ||
| percy.log.debug(`Could not send the snapshot log for ${meta.snapshot?.name}`, meta); | ||
| percy.log.debug(err); | ||
| } finally { | ||
| // drop this snapshot's cached logs regardless of upload outcome | ||
| logger.evictSnapshot(meta.snapshot); | ||
| } | ||
| } | ||
|
|
||
| // Creates a snapshots queue that manages a Percy build and uploads snapshots. | ||
| export function createSnapshotsQueue(percy) { | ||
| let { concurrency } = percy.config.discovery; | ||
|
|
@@ -506,6 +533,13 @@ export function createSnapshotsQueue(percy) { | |
| let response = yield percy.client[send](build.id, snapshot); | ||
| if (percy.deferUploads) percy.log.info(`Snapshot uploaded: ${name}`, meta); | ||
|
|
||
| // upload the per-snapshot CLI log directly to the logs endpoint (web | ||
| // snapshots only; automate/app comparisons carry no snapshot log). For | ||
| // sendSnapshot, response.data.id is the snapshot id. Best-effort. | ||
| if (send === 'sendSnapshot') { | ||
| yield uploadSnapshotLog(percy, build.id, response.data.id, meta); | ||
|
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. [Medium] Snapshot log cache not evicted when the snapshot send fails
Suggestion: also call Reviewer: stack-code-reviewer |
||
| } | ||
|
|
||
| // Pushing to syncQueue, that will check for | ||
| // snapshot processing status, and will resolve once done | ||
| if (snapshot.sync) { | ||
|
|
||
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.
At this point, does the snapshot is ran, and all the logs are added in the logger ?
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.
Yes. This runs inside the snapshot upload task, right after
sendSnapshotresolves — so asset discovery and snapshot processing are complete and every log entry for this snapshot (matched bymeta.snapshot.name+testCase) is already in the logger;logger.queryreturns them. It's actually a more complete capture than the old approach, which built the log resource during discovery (earlier). Verified live:support:debugon a new-CLI snapshot downloaded the log with 47 real entries.