Skip to content

Commit

Permalink
fix: Add guard to handle null decode results; Update log event query …
Browse files Browse the repository at this point in the history
…to use active event count (fixes #166). (#167)
  • Loading branch information
davemarco authored Jan 10, 2025
1 parent f74bacf commit ff13649
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
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) ?
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

0 comments on commit ff13649

Please sign in to comment.