Bug 1844133 - [remote] WebSocketConnection logs should be truncated for huge objects r=webdriver-reviewers,Sasha

Puppeteer happens to send huge payloads as part of their test suite when using their $$eval API.
This is because they pass back and forth nodeLists for which all children are serialized by default.
This could be avoided by changing the serialization options (see https://github.com/puppeteer/puppeteer/issues/10582)

But without such a fix, we need to cap the size of the websocket logs, otherwise the logparser is unable to handle the
logs from the bidi puppeteer job.

Differential Revision: https://phabricator.services.mozilla.com/D184108
This commit is contained in:
Julian Descottes 2023-07-25 07:10:08 +00:00
parent 0cad8e2125
commit 525aa4d10f

View File

@ -17,6 +17,8 @@ ChromeUtils.defineESModuleGetters(lazy, {
XPCOMUtils.defineLazyGetter(lazy, "logger", () => lazy.Log.get()); XPCOMUtils.defineLazyGetter(lazy, "logger", () => lazy.Log.get());
const MAX_LOG_LENGTH = 2500;
export class WebSocketConnection { export class WebSocketConnection {
/** /**
* @param {WebSocket} webSocket * @param {WebSocket} webSocket
@ -45,12 +47,20 @@ export class WebSocketConnection {
return value; return value;
} }
const payload = JSON.stringify( let payload = JSON.stringify(
data, data,
replacer, replacer,
lazy.Log.verbose ? "\t" : null lazy.Log.verbose ? "\t" : null
); );
if (payload.length > MAX_LOG_LENGTH) {
// Even if we truncate individual values, the resulting message might be
// huge if we are serializing big objects with many properties or items.
// Truncate the overall message to avoid issues in logs.
const truncated = payload.substring(0, MAX_LOG_LENGTH);
payload = `${truncated} [... truncated after ${MAX_LOG_LENGTH} characters]`;
}
lazy.logger.debug( lazy.logger.debug(
`${this.constructor.name} ${this.id} ${direction} ${payload}` `${this.constructor.name} ${this.id} ${direction} ${payload}`
); );