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 all 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
20 changes: 15 additions & 5 deletions src/services/LogFileManager/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint max-lines: ["error", 450] */
/* eslint max-lines: ["error", 500] */
import {
Decoder,
DecodeResult,
Expand Down Expand Up @@ -383,12 +383,22 @@ class LogFileManager {
// 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();
const numActiveEvents: number = (null !== filteredLogEventMap) ?
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.

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,
chunkEndIdx,
null !== this.#decoder.getFilteredLogEventMap()
null !== filteredLogEventMap
);

if (null === decodedEvents) {
Expand All @@ -400,13 +410,13 @@ class LogFileManager {
// 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
10 changes: 8 additions & 2 deletions src/services/decoders/ClpIrDecoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,14 @@ class ClpIrDecoder implements Decoder {
endIdx: number,
useFilter: boolean
): Nullable<DecodeResult[]> {
const results: DecodeResult[] =
this.#streamReader.decodeRange(beginIdx, endIdx, useFilter);
// eslint-disable-next-line no-warning-comments
// TODO: Correct DecodeResult typing in `clp-ffi-js` and remove below type assertion.
const results =
this.#streamReader.decodeRange(beginIdx, endIdx, useFilter) as Nullable<DecodeResult[]>;

if (null === results) {
return null;
}

if (null === this.#formatter) {
if (this.#streamType === CLP_IR_STREAM_TYPE.STRUCTURED) {
Expand Down
Loading