Skip to content

Commit e4d1f4e

Browse files
author
Dave Bartolomeo
committed
Fix newline handling for cross-platform logs
We were splitting JSONL records based on the current OS newline sequence. In order to handle reading of logs from the opposite OS, I've switched our split to handle both flavors of line ending. This originally showed up as log parser unit tests failing on Windows (the checked-in log used Unix line endings), but could affect real world usage as well.
1 parent c192212 commit e4d1f4e

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed
Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,31 @@
1-
import * as os from 'os';
2-
31
// TODO(angelapwen): Only load in necessary information and
4-
// location in bytes for this log to save memory.
2+
// location in bytes for this log to save memory.
53
export interface EvaluatorLogData {
64
queryCausingWork: string;
75
predicateName: string;
86
millis: number;
97
resultSize: number;
108
ra: Pipelines;
119
}
12-
10+
1311
interface Pipelines {
14-
// Key: pipeline identifier; Value: array of pipeline steps
12+
// Key: pipeline identifier; Value: array of pipeline steps
1513
pipelineNamesToSteps: Map<string, string[]>;
1614
}
17-
15+
1816
/**
1917
* A pure method that parses a string of evaluator log summaries into
20-
* an array of EvaluatorLogData objects.
21-
*
18+
* an array of EvaluatorLogData objects.
19+
*
2220
*/
2321
export function parseVisualizerData(logSummary: string): EvaluatorLogData[] {
2422
// Remove newline delimiters because summary is in .jsonl format.
25-
const jsonSummaryObjects: string[] = logSummary.split(os.EOL + os.EOL);
23+
const jsonSummaryObjects: string[] = logSummary.split(/\r?\n\r?\n/g);
2624
const visualizerData: EvaluatorLogData[] = [];
27-
25+
2826
for (const obj of jsonSummaryObjects) {
2927
const jsonObj = JSON.parse(obj);
30-
28+
3129
// Only convert log items that have an RA and millis field
3230
if (jsonObj.ra !== undefined && jsonObj.millis !== undefined) {
3331
const newLogData: EvaluatorLogData = {
@@ -39,6 +37,6 @@ interface Pipelines {
3937
};
4038
visualizerData.push(newLogData);
4139
}
42-
}
40+
}
4341
return visualizerData;
44-
}
42+
}

0 commit comments

Comments
 (0)