Skip to content
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

fix: Add guard to handle null decode results; Update log event query to use active event count (fixes #166). #167

Merged
merged 8 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions src/services/LogFileManager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,14 +366,6 @@
}
}

/**
* Queries a chunk of log events, sends the results, and schedules the next chunk query if more
* log events remain.
*
* @param queryId
* @param chunkBeginIdx
* @param queryRegex
*/
#queryChunkAndScheduleNext (
queryId: number,
chunkBeginIdx: number,
Expand All @@ -383,7 +375,17 @@
// Current task no longer corresponds to the latest query in the LogFileManager.
return;
}
const chunkEndIdx = Math.min(chunkBeginIdx + QUERY_CHUNK_SIZE, this.#numEvents);

const filteredLogEventMap = this.#decoder.getFilteredLogEventMap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's replace the this.#decoder.getFilteredLogEventMap() call in L401 with this const.

const numActiveEvents: number = filteredLogEventMap ?
filteredLogEventMap.length :
this.#numEvents;

if (0 === numActiveEvents) {
return;
}

const chunkEndIdx = Math.min(chunkBeginIdx + QUERY_CHUNK_SIZE, numActiveEvents);
const results: QueryResults = new Map();
const decodedEvents = this.#decoder.decodeRange(
chunkBeginIdx,
Expand All @@ -400,13 +402,13 @@
// The query progress takes the maximum of the progress based on the number of events
// queried over total log events, and the number of results over the maximum result limit.
const progress = Math.max(
chunkEndIdx / this.#numEvents,
chunkEndIdx / numActiveEvents,
this.#queryCount / MAX_QUERY_RESULT_COUNT
);

this.#onQueryResults(progress, results);

if (chunkEndIdx < this.#numEvents && MAX_QUERY_RESULT_COUNT > this.#queryCount) {
if (chunkEndIdx < numActiveEvents && MAX_QUERY_RESULT_COUNT > this.#queryCount) {
defer(() => {
this.#queryChunkAndScheduleNext(queryId, chunkEndIdx, queryRegex);
});
Expand Down Expand Up @@ -446,4 +448,4 @@
}
}

export default LogFileManager;

Check failure on line 451 in src/services/LogFileManager/index.ts

View workflow job for this annotation

GitHub Actions / lint-check

File has too many lines (451). Maximum allowed is 450
6 changes: 5 additions & 1 deletion src/services/decoders/ClpIrDecoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,13 @@
endIdx: number,
useFilter: boolean
): Nullable<DecodeResult[]> {
const results: DecodeResult[] =
const results: Nullable<DecodeResult[]> =
this.#streamReader.decodeRange(beginIdx, endIdx, useFilter);

if (null === results) {

Check failure on line 107 in src/services/decoders/ClpIrDecoder.ts

View workflow job for this annotation

GitHub Actions / lint-check

Unnecessary conditional, the types have no overlap
return null;
}

if (null === this.#formatter) {
if (this.#streamType === CLP_IR_STREAM_TYPE.STRUCTURED) {
// eslint-disable-next-line no-warning-comments
Expand Down
Loading