Skip to content

Commit

Permalink
cmd/hiveview: limit log bytes in suite view
Browse files Browse the repository at this point in the history
It was already limited to a certain number of lines, but that's not enough when
the test outputs very long lines.
  • Loading branch information
fjl authored and Eikix committed Mar 1, 2024
1 parent 42634bd commit 8ed34df
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
5 changes: 4 additions & 1 deletion cmd/hiveview/assets/lib/app-suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,12 @@ function formatTestDetails(suiteData, row) {
let spinner = $('<div><div class="spinner-grow text-secondary" role="status"></div>');
$(container).append(spinner);

const testlogMaxLines = 25;
const testlogMaxBytes = 2097152;

let url = routes.resultsRoot + suiteData.testDetailsLog;
let loader = new testlog.Loader(url, d.summaryResult.log);
loader.headAndTailLines(25).then(function (log) {
loader.headAndTailLines(testlogMaxLines, testlogMaxBytes).then(function (log) {
spinner.remove();
formatTestLog(suiteData, d.testIndex, log, container);
}).catch(function (error) {
Expand Down
12 changes: 8 additions & 4 deletions cmd/hiveview/assets/lib/testlog.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function countLines(text) {
}

const NEWLINE = 10;
const LOADER_CHUNK_SIZE = 32768;
const LOADER_CHUNK_SIZE = 262144;

// Loader provides incremental access to log files.
export class Loader {
Expand Down Expand Up @@ -99,7 +99,7 @@ export class Loader {

// headAndTailLines returns up to n lines from the beginning and
// end of the log.
async headAndTailLines(n) {
async headAndTailLines(n, maxBytes) {
var head = [];
var headEndPosition = 0;
var tail = [];
Expand All @@ -108,7 +108,8 @@ export class Loader {
let eofReached = await this.iterLines(function (line, offset) {
headEndPosition = offset;
head.push(line);
return head.length < n;
let tooMuchData = maxBytes && offset > maxBytes && head.length > 0;
return head.length < n && !tooMuchData;
});
if (eofReached || head.length < n) {
return {head, tail};
Expand All @@ -117,13 +118,16 @@ export class Loader {
// Now read from tail. This stops when the read enters the
// region already covered by the head.
let linkWithHead = false;
const totalSize = this.length;
await this._iterTailLines(function (line, offset) {
if (offset < headEndPosition) {
linkWithHead = true;
return false;
}
tail.unshift(line);
return tail.length < n;
let tailSize = totalSize - offset;
let tooMuchData = maxBytes && tailSize > maxBytes && tail.length > 0;
return tail.length < n && !tooMuchData;
});
if (linkWithHead) {
head = head.concat(tail);
Expand Down

0 comments on commit 8ed34df

Please sign in to comment.