Skip to content

refactor(new-webui): Improve logging for easier debugging; Improve names of Mongo SocketIO library classes.#997

Merged
davemarco merged 14 commits into
y-scope:mainfrom
davemarco:logg
Jun 11, 2025
Merged

refactor(new-webui): Improve logging for easier debugging; Improve names of Mongo SocketIO library classes.#997
davemarco merged 14 commits into
y-scope:mainfrom
davemarco:logg

Conversation

@davemarco

@davemarco davemarco commented Jun 10, 2025

Copy link
Copy Markdown
Contributor

Description

PR adds more info to certains logs, and reduces verbosity of others to reduce clutter when debugging. I decided to make these changes while i was testing.

Adds a few new logs as well.

I also renamed a couple variables.

Checklist

  • The PR satisfies the contribution guidelines.
  • This is a breaking change and that has been indicated in the PR title, OR this isn't a
    breaking change.
  • Necessary docs have been updated, OR no docs need to be updated.

Validation performed

Logs look better when running queries

Summary by CodeRabbit

Summary by CodeRabbit

  • Refactor
    • Renamed several classes and imports for improved clarity and consistency across the application.
  • Style
    • Updated logging throughout the app, replacing some console logs with more detailed debug messages and removing unnecessary log statements.
  • Chores
    • Enhanced log messages to provide clearer context during subscription and unsubscription events.

@davemarco davemarco requested a review from a team as a code owner June 10, 2025 20:59
@coderabbitai

coderabbitai Bot commented Jun 10, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

This update standardizes class and variable names related to MongoDB socket collections and cursors throughout the codebase, renaming them for consistency. Logging statements are revised to use console.debug instead of console.log or console.info, with improved contextual information in log messages. No core logic or control flow changes are introduced.

Changes

File(s) Change Summary
.../client/src/api/socket/MongoSocketCollection.ts
.../client/src/api/socket/MongoSocketCursor.ts
Renamed classes and exports: MongoCollectionSocketMongoSocketCollection, MongoCursorSocketMongoSocketCursor. Updated related imports, type annotations, and documentation. Removed or updated log statements.
.../client/src/api/socket/useCursor.tsx Updated import and type annotations to use MongoSocketCursor. Removed subscription/unsubscription log statements.
.../client/src/pages/SearchPage/SearchResults/SearchResultsTable/useSearchResults.ts
.../SearchResultsTimeline/useAggregationResults.ts
.../SearchState/useResultsMetadata.ts
Updated imports and instantiations to use MongoSocketCollection. Added console.log statements for subscription events.
.../client/src/pages/SearchPage/SearchControls/search-requests.ts Enhanced logging: switched from console.log to console.debug, improved log detail, and adjusted variable assignment for job IDs.
.../server/src/plugins/MongoSocketIoServer/index.ts Changed log level from info to debug for watcher and subscription events; improved log message detail and consistency.

Sequence Diagram(s)

sequenceDiagram
    participant UI
    participant MongoSocketCollection
    participant MongoSocketCursor
    participant Server

    UI->>MongoSocketCollection: new MongoSocketCollection()
    UI->>MongoSocketCollection: find(query, options)
    MongoSocketCollection->>MongoSocketCursor: new MongoSocketCursor(query, options)
    MongoSocketCursor->>Server: subscribe(query, options)
    Server-->>MongoSocketCursor: subscription confirmation / data
    MongoSocketCursor-->>UI: emits data updates
    UI->>MongoSocketCursor: unsubscribe()
    MongoSocketCursor->>Server: unsubscribe(queryId)
    Server-->>MongoSocketCursor: unsubscription confirmation
Loading

Possibly related PRs

Suggested reviewers

  • junhaoliao
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 10

🔭 Outside diff range comments (3)
components/log-viewer-webui/server/src/plugins/MongoSocketIoServer/index.ts (2)

229-233: 🧹 Nitpick (assertive)

Replace string concatenation with a single template literal

Biome flagged this; switching removes the unnecessary + operators and is easier to read.

-        this.#fastify.log.debug(
-            `Socket:${socket.id} requested query:${JSON.stringify(query)} ` +
-            `with options:${JSON.stringify(options)} to collection:${collectionName}`
-        );
+        this.#fastify.log.debug(
+            `Socket:${socket.id} requested query:${JSON.stringify(query)} with options:${JSON.stringify(options)} to collection:${collectionName}`
+        );

318-324: 🧹 Nitpick (assertive)

Template-literal cleanup & minor re-wrap

Same concatenation issue as above plus a trailing line break inside the template.

-        this.#fastify.log.debug(
-            "Query ID to query hash map:" +
-            ` ${JSON.stringify(Array.from(this.#queryIdToQueryHashMap.entries()))}`
-        );
+        this.#fastify.log.debug(
+            `Query ID to query hash map: ${JSON.stringify(
+                Array.from(this.#queryIdToQueryHashMap.entries()),
+            )}`,
+        );
🧰 Tools
🪛 Biome (1.9.4)

[error] 318-319: Template literals are preferred over string concatenation.

Unsafe fix: Use a template literal.

(lint/style/useTemplate)


[error] 323-324: Template literals are preferred over string concatenation.

Unsafe fix: Use a template literal.

(lint/style/useTemplate)

components/log-viewer-webui/client/src/api/socket/MongoSocketCollection.ts (1)

15-28: 🧹 Nitpick (assertive)

Typo in JSDoc.

InitalizesInitializes.

-     * Initalizes socket connection to a MongoDB collection on the server.
+     * Initializes socket connection to a MongoDB collection on the server.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8e1c32b and 84726c5.

📒 Files selected for processing (8)
  • components/log-viewer-webui/client/src/api/socket/MongoSocketCollection.ts (3 hunks)
  • components/log-viewer-webui/client/src/api/socket/MongoSocketCursor.ts (4 hunks)
  • components/log-viewer-webui/client/src/api/socket/useCursor.tsx (1 hunks)
  • components/log-viewer-webui/client/src/pages/SearchPage/SearchControls/search-requests.ts (2 hunks)
  • components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/useSearchResults.ts (2 hunks)
  • components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTimeline/useAggregationResults.ts (2 hunks)
  • components/log-viewer-webui/client/src/pages/SearchPage/SearchState/useResultsMetadata.ts (2 hunks)
  • components/log-viewer-webui/server/src/plugins/MongoSocketIoServer/index.ts (7 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}`: - Prefer `false == ` rather than `!`.

**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}: - Prefer false == <expression> rather than !<expression>.

  • components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/useSearchResults.ts
  • components/log-viewer-webui/client/src/pages/SearchPage/SearchControls/search-requests.ts
  • components/log-viewer-webui/client/src/api/socket/useCursor.tsx
  • components/log-viewer-webui/server/src/plugins/MongoSocketIoServer/index.ts
  • components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTimeline/useAggregationResults.ts
  • components/log-viewer-webui/client/src/api/socket/MongoSocketCursor.ts
  • components/log-viewer-webui/client/src/pages/SearchPage/SearchState/useResultsMetadata.ts
  • components/log-viewer-webui/client/src/api/socket/MongoSocketCollection.ts
🧠 Learnings (3)
components/log-viewer-webui/client/src/api/socket/useCursor.tsx (1)
Learnt from: davemarco
PR: y-scope/clp#892
File: components/log-viewer-webui/client/src/api/socket/MongoCollectionSocket.ts:27-31
Timestamp: 2025-05-09T19:15:26.180Z
Learning: For the MongoDB real-time updates implementation in components/log-viewer-webui/client/src/api/socket, a socket singleton pattern is used where a single shared socket connection is maintained rather than creating multiple connections. The socket lifecycle is managed centrally, with unsubscription handling in the useCursor React hook's cleanup function.
components/log-viewer-webui/client/src/api/socket/MongoSocketCursor.ts (1)
Learnt from: davemarco
PR: y-scope/clp#892
File: components/log-viewer-webui/client/src/api/socket/MongoCollectionSocket.ts:27-31
Timestamp: 2025-05-09T19:15:26.180Z
Learning: For the MongoDB real-time updates implementation in components/log-viewer-webui/client/src/api/socket, a socket singleton pattern is used where a single shared socket connection is maintained rather than creating multiple connections. The socket lifecycle is managed centrally, with unsubscription handling in the useCursor React hook's cleanup function.
components/log-viewer-webui/client/src/api/socket/MongoSocketCollection.ts (1)
Learnt from: davemarco
PR: y-scope/clp#892
File: components/log-viewer-webui/client/src/api/socket/MongoCollectionSocket.ts:27-31
Timestamp: 2025-05-09T19:15:26.180Z
Learning: For the MongoDB real-time updates implementation in components/log-viewer-webui/client/src/api/socket, a socket singleton pattern is used where a single shared socket connection is maintained rather than creating multiple connections. The socket lifecycle is managed centrally, with unsubscription handling in the useCursor React hook's cleanup function.
🪛 Biome (1.9.4)
components/log-viewer-webui/client/src/pages/SearchPage/SearchControls/search-requests.ts

[error] 92-92: This let declares some variables that are only assigned once.

'searchJobId' is never reassigned.

'aggregationJobId' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)

components/log-viewer-webui/server/src/plugins/MongoSocketIoServer/index.ts

[error] 323-324: Template literals are preferred over string concatenation.

Unsafe fix: Use a template literal.

(lint/style/useTemplate)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: build (macos-latest)
  • GitHub Check: lint-check (macos-latest)
  • GitHub Check: lint-check (ubuntu-latest)
🔇 Additional comments (9)
components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/useSearchResults.ts (1)

1-1: Renamed import – looks good

The switch to MongoSocketCollection keeps naming consistent with the rest of the refactor. No issues spotted here.

components/log-viewer-webui/server/src/plugins/MongoSocketIoServer/index.ts (1)

323-324: Single template literal & full stop for consistency

-            this.#fastify.log.debug(`Collection:${queryParams.collectionName}` +
-            " deallocated from server.");
+            this.#fastify.log.debug(
+                `Collection:${queryParams.collectionName} deallocated from server.`,
+            );
🧰 Tools
🪛 Biome (1.9.4)

[error] 323-324: Template literals are preferred over string concatenation.

Unsafe fix: Use a template literal.

(lint/style/useTemplate)

components/log-viewer-webui/client/src/pages/SearchPage/SearchState/useResultsMetadata.ts (1)

3-3: Import rename aligns with API change – good

components/log-viewer-webui/client/src/api/socket/useCursor.tsx (2)

8-8: Import rename looks correct

No functional impact – matches other files.


23-24: Generic type preserved – all good

components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTimeline/useAggregationResults.ts (2)

1-1: Import rename looks correct.

The switch to MongoSocketCollection keeps the naming consistent with the broader refactor. 👍


27-28: Instantiation aligns with the new class name.

No functional issues spotted.

components/log-viewer-webui/client/src/api/socket/MongoSocketCursor.ts (1)

114-114: Nice unsubscribe trace.

Helps correlate server-side unsubscription events.

components/log-viewer-webui/client/src/api/socket/MongoSocketCollection.ts (1)

39-44: Return type correctly updated to new cursor class.

No issues—matches the refactor and preserves the singleton socket usage documented earlier.

Comment on lines +23 to +27
console.log(
`Subscribing to updates to search results with job ID: ${searchJobId}`
);

const collection = new MongoSocketCollection(searchJobId.toString());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Use console.debug instead of console.log for parity with the new logging policy

All other new client-side logs were moved to console.debug; this lone console.log will stick out and re-introduce noise when log levels are filtered.

-            console.log(
+            console.debug(
                 `Subscribing to updates to search results with job ID: ${searchJobId}`
             );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
console.log(
`Subscribing to updates to search results with job ID: ${searchJobId}`
);
const collection = new MongoSocketCollection(searchJobId.toString());
console.debug(
`Subscribing to updates to search results with job ID: ${searchJobId}`
);
const collection = new MongoSocketCollection(searchJobId.toString());
🤖 Prompt for AI Agents
In
components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/useSearchResults.ts
between lines 23 and 27, replace the console.log call with console.debug to
align with the new logging policy and reduce noise when filtering log levels.
This change ensures consistent use of debug-level logging for client-side logs.

Comment on lines +25 to 33
const collection = new MongoSocketCollection(
settings.MongoDbSearchResultsMetadataCollectionName
);

console.log(
`Subscribing to updates for results metadata for search job ID: ${searchJobId}`
);

return collection.find({_id: searchJobId.toString()}, {limit: 1});

@coderabbitai coderabbitai Bot Jun 10, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Switch to console.debug for uniform log level

Same rationale as in useSearchResults.ts.

-            console.log(
+            console.debug(
                 `Subscribing to updates for results metadata for search job ID: ${searchJobId}`
             );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const collection = new MongoSocketCollection(
settings.MongoDbSearchResultsMetadataCollectionName
);
console.log(
`Subscribing to updates for results metadata for search job ID: ${searchJobId}`
);
return collection.find({_id: searchJobId.toString()}, {limit: 1});
const collection = new MongoSocketCollection(
settings.MongoDbSearchResultsMetadataCollectionName
);
console.debug(
`Subscribing to updates for results metadata for search job ID: ${searchJobId}`
);
return collection.find({_id: searchJobId.toString()}, {limit: 1});
🤖 Prompt for AI Agents
In
components/log-viewer-webui/client/src/pages/SearchPage/SearchState/useResultsMetadata.ts
between lines 25 and 33, replace the console.log statement with console.debug to
maintain consistent log levels across the codebase, matching the approach used
in useSearchResults.ts. This change ensures debug-level messages are uniformly
handled.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

no

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@davemarco Understood—keeping the console.log as-is.

Comment on lines +123 to 124
console.debug("Query cancelled successfully");
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Nit: add context to cancellation log

Including IDs helps when multiple tabs/users are active.

-        console.debug("Query cancelled successfully");
+        console.debug(`Query ${payload.searchJobId} cancelled successfully`);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
console.debug("Query cancelled successfully");
})
console.debug(`Query ${payload.searchJobId} cancelled successfully`);
})
🤖 Prompt for AI Agents
In
components/log-viewer-webui/client/src/pages/SearchPage/SearchControls/search-requests.ts
at lines 123-124, the console.debug log for query cancellation lacks context.
Modify the log message to include relevant identifiers such as query IDs or
user/session IDs to help distinguish cancellations when multiple tabs or users
are active.

Comment on lines 96 to 99
console.debug("Search job created - ",
"Search job ID:", searchJobId,
"Aggregation job ID:", aggregationJobId);
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Optional: collapse multi-argument console.debug into a template for readability
Not critical, just easier to copy-paste from logs.

-            console.debug("Search job created - ",
-                "Search job ID:", searchJobId,
-                "Aggregation job ID:", aggregationJobId);
+            console.debug(
+                `Search job created - Search job ID: ${searchJobId}, Aggregation job ID: ${aggregationJobId}`,
+            );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
console.debug("Search job created - ",
"Search job ID:", searchJobId,
"Aggregation job ID:", aggregationJobId);
})
console.debug(
`Search job created - Search job ID: ${searchJobId}, Aggregation job ID: ${aggregationJobId}`,
);
})
🤖 Prompt for AI Agents
In
components/log-viewer-webui/client/src/pages/SearchPage/SearchControls/search-requests.ts
around lines 96 to 99, the console.debug call uses multiple arguments which can
reduce readability and make copying logs harder. Refactor this to use a single
template literal string that includes the searchJobId and aggregationJobId
variables inline for clearer, more readable output.

Comment on lines +12 to +18
* Custom hook which returns a real-time reactive array of documents from a `MongoSocketCursor`.
*
* @template T The document type returned by the cursor.
* @param query Function which returns a `MongoCursorSocket` instance or null.
* @param query Function which returns a `MongoSocketCursor` instance or null.
* @param dependencies Array of dependencies for the query.
* @return
* - If `query` returns a `MongoCursorSocket` instance, then hook returns null while
* - If `query` returns a `MongoSocketCursor` instance, then hook returns null while

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Updated JSDoc – spellcheck minor typo

The word “recieved” in the comment below is still misspelled.

-            // recieved the queryID from the server, making it impossible to unsubscribe
+            // received the queryID from the server, making it impossible to unsubscribe

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In components/log-viewer-webui/client/src/api/socket/useCursor.tsx around lines
12 to 18, correct the spelling of the word "recieved" to "received" in the JSDoc
comment to fix the minor typo.

Comment on lines +23 to +27
console.log(
`Subscribing to updates to aggregation results with job ID: ${aggregationJobId}`
);

const collection = new MongoSocketCollection(aggregationJobId.toString());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Use console.debug for consistency with new logging policy.

All other updated modules migrated from console.log/console.info to console.debug to reduce noise in production builds. These two lines revert to console.log, breaking that consistency.

-            console.log(
+            console.debug(
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
console.log(
`Subscribing to updates to aggregation results with job ID: ${aggregationJobId}`
);
const collection = new MongoSocketCollection(aggregationJobId.toString());
console.debug(
`Subscribing to updates to aggregation results with job ID: ${aggregationJobId}`
);
const collection = new MongoSocketCollection(aggregationJobId.toString());
🤖 Prompt for AI Agents
In
components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTimeline/useAggregationResults.ts
between lines 23 and 27, replace the console.log statement with console.debug to
maintain consistency with the new logging policy and reduce noise in production
builds.

Comment on lines +55 to +58
console.debug(
`Subscribing to query: ${JSON.stringify(this.#query)} ` +
`on collection:${this.#collectionName}`
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Good adoption of console.debug, but drop string concatenation.

Since you’re already using template literals, the + concatenation is unnecessary and slightly harder to scan.

-        console.debug(
-            `Subscribing to query: ${JSON.stringify(this.#query)} ` +
-            `on collection:${this.#collectionName}`
-        );
+        console.debug(
+            `Subscribing to query: ${JSON.stringify(this.#query)} on collection: ${this.#collectionName}`,
+        );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
console.debug(
`Subscribing to query: ${JSON.stringify(this.#query)} ` +
`on collection:${this.#collectionName}`
);
console.debug(
`Subscribing to query: ${JSON.stringify(this.#query)} on collection: ${this.#collectionName}`,
);
🤖 Prompt for AI Agents
In components/log-viewer-webui/client/src/api/socket/MongoSocketCursor.ts around
lines 55 to 58, remove the string concatenation operator (+) within the
console.debug call. Instead, combine the entire message into a single template
literal for better readability and cleaner code.

Comment on lines +88 to +91
console.debug(
`Successfully subscribed to query: ${JSON.stringify(this.#query)} ` +
`on collection:${this.#collectionName} with MongoSocketIoQueryID:${this.#queryId}`
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Same minor formatting nit as above.

-        console.debug(
-            `Successfully subscribed to query: ${JSON.stringify(this.#query)} ` +
-            `on collection:${this.#collectionName} with MongoSocketIoQueryID:${this.#queryId}`
-        );
+        console.debug(
+            `Successfully subscribed to query: ${JSON.stringify(this.#query)} on collection: ${this.#collectionName} with MongoSocketIoQueryID: ${this.#queryId}`,
+        );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
console.debug(
`Successfully subscribed to query: ${JSON.stringify(this.#query)} ` +
`on collection:${this.#collectionName} with MongoSocketIoQueryID:${this.#queryId}`
);
console.debug(
`Successfully subscribed to query: ${JSON.stringify(this.#query)} on collection: ${this.#collectionName} with MongoSocketIoQueryID: ${this.#queryId}`,
);
🤖 Prompt for AI Agents
In components/log-viewer-webui/client/src/api/socket/MongoSocketCursor.ts around
lines 88 to 91, the console.debug statement has a minor formatting issue with
string concatenation. Refactor the code to use a single template literal instead
of concatenating two strings with the + operator for cleaner and more consistent
formatting.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🔭 Outside diff range comments (1)
components/log-viewer-webui/server/src/plugins/MongoSocketIoServer/index.ts (1)

229-233: 🧹 Nitpick (assertive)

Collapse string concatenation in debug statement

Template literals alone suffice.

-        this.#fastify.log.debug(
-            `Socket:${socket.id} requested query:${JSON.stringify(query)} ` +
-            `with options:${JSON.stringify(options)} to collection:${collectionName}`
-        );
+        this.#fastify.log.debug(
+            `Socket:${socket.id} requested query: ${JSON.stringify(query)} with options: ${JSON.stringify(options)} to collection: ${collectionName}`,
+        );
♻️ Duplicate comments (3)
components/log-viewer-webui/client/src/api/socket/MongoSocketCursor.ts (2)

55-59: 🧹 Nitpick (assertive)

Use a single template literal instead of + concatenation

The same nitpick was raised before; concatenation is still present. One template literal is clearer and eliminates the extra whitespace bookkeeping.

-        console.debug(
-            `Subscribing to query: ${JSON.stringify(this.#query)} ` +
-            `with options:${JSON.stringify(this.#options)} ` +
-            `on collection:${this.#collectionName}`
-        );
+        console.debug(
+            `Subscribing to query: ${JSON.stringify(this.#query)} with options: ${JSON.stringify(this.#options)} on collection: ${this.#collectionName}`,
+        );

90-94: 🧹 Nitpick (assertive)

Same concatenation nitpick applies here

Please collapse into one template literal for consistency with other debug statements.

-        console.debug(
-            `Successfully subscribed to query: ${JSON.stringify(this.#query)} ` +
-            `with options:${JSON.stringify(this.#options)} ` +
-            `on collection:${this.#collectionName} ` +
-            `MongoSocketIoQueryID:${this.#queryId}`
-        );
+        console.debug(
+            `Successfully subscribed to query: ${JSON.stringify(this.#query)} with options: ${JSON.stringify(this.#options)} on collection: ${this.#collectionName} MongoSocketIoQueryID: ${this.#queryId}`,
+        );
components/log-viewer-webui/server/src/plugins/MongoSocketIoServer/index.ts (1)

255-259: 🧹 Nitpick (assertive)

Downgrade to debug for log-level consistency (repeat comment)

All other subscription-flow logs were moved to debug; keeping this at info will re-introduce noise.

-        this.#fastify.log.info(
+        this.#fastify.log.debug(
             `Socket:${socket.id} subscribed to query:${JSON.stringify(query)} ` +
             `with options:${JSON.stringify(options)} ` +
             `on collection:${collectionName} with ID:${queryId}`
         );
📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 84726c5 and 0964a8e.

📒 Files selected for processing (2)
  • components/log-viewer-webui/client/src/api/socket/MongoSocketCursor.ts (4 hunks)
  • components/log-viewer-webui/server/src/plugins/MongoSocketIoServer/index.ts (7 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}`: - Prefer `false == ` rather than `!`.

**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}: - Prefer false == <expression> rather than !<expression>.

  • components/log-viewer-webui/client/src/api/socket/MongoSocketCursor.ts
  • components/log-viewer-webui/server/src/plugins/MongoSocketIoServer/index.ts
🧠 Learnings (1)
components/log-viewer-webui/client/src/api/socket/MongoSocketCursor.ts (1)
Learnt from: davemarco
PR: y-scope/clp#892
File: components/log-viewer-webui/client/src/api/socket/MongoCollectionSocket.ts:27-31
Timestamp: 2025-05-09T19:15:26.180Z
Learning: For the MongoDB real-time updates implementation in components/log-viewer-webui/client/src/api/socket, a socket singleton pattern is used where a single shared socket connection is maintained rather than creating multiple connections. The socket lifecycle is managed centrally, with unsubscription handling in the useCursor React hook's cleanup function.
🪛 Biome (1.9.4)
components/log-viewer-webui/server/src/plugins/MongoSocketIoServer/index.ts

[error] 324-325: Template literals are preferred over string concatenation.

Unsafe fix: Use a template literal.

(lint/style/useTemplate)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: lint-check (ubuntu-latest)
  • GitHub Check: lint-check (macos-latest)

}

console.log(`Unsubscribed to queryID:${this.#queryId}.`);
console.debug(`Unsubscribed from MongoSocketIoQueryID:${this.#queryId}.`);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Minor readability tweak

Add a space after the colon to align with the other log messages.

-        console.debug(`Unsubscribed from MongoSocketIoQueryID:${this.#queryId}.`);
+        console.debug(`Unsubscribed from MongoSocketIoQueryID: ${this.#queryId}.`);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
console.debug(`Unsubscribed from MongoSocketIoQueryID:${this.#queryId}.`);
console.debug(`Unsubscribed from MongoSocketIoQueryID: ${this.#queryId}.`);
🤖 Prompt for AI Agents
In components/log-viewer-webui/client/src/api/socket/MongoSocketCursor.ts at
line 117, the debug log message lacks a space after the colon in
"MongoSocketIoQueryID:". Add a space after the colon so the message reads
"MongoSocketIoQueryID: " to improve readability and maintain consistency with
other log messages.

Comment thread components/log-viewer-webui/server/src/plugins/MongoSocketIoServer/index.ts Outdated
@davemarco davemarco requested a review from junhaoliao June 10, 2025 21:29

@junhaoliao junhaoliao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

some changes in this PR are not directly related to logging (e.g., the MongoSocketCollection renaming) While I agree the proposed names are more accurate, can we split those changes into a separate PR?

Comment thread components/log-viewer-webui/server/src/plugins/MongoSocketIoServer/index.ts Outdated
Comment thread components/log-viewer-webui/server/src/plugins/MongoSocketIoServer/index.ts Outdated
Comment thread components/log-viewer-webui/server/src/plugins/MongoSocketIoServer/index.ts Outdated
davemarco and others added 3 commits June 11, 2025 12:47
…rver/index.ts

Co-authored-by: Junhao Liao <junhao@junhao.ca>
…rver/index.ts

Co-authored-by: Junhao Liao <junhao@junhao.ca>
…rver/index.ts

Co-authored-by: Junhao Liao <junhao@junhao.ca>
@davemarco

davemarco commented Jun 11, 2025

Copy link
Copy Markdown
Contributor Author

How do you feel about changing title to refactor(new-webui): Improve logging for easier debugging; Improve names of Mongo SocketIO lib classes.

I feel the change is small, and this PR has convential commit refactor? anyways let me know

@davemarco davemarco requested a review from junhaoliao June 11, 2025 16:50

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

♻️ Duplicate comments (1)
components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/useSearchResults.ts (1)

26-29: Replace console.log with console.debug for logging-level consistency
All new client-side logs were migrated to console.debug; keeping a lone console.log re-introduces noise when filtering log levels.

-            console.log(
+            console.debug(
                 `Subscribing to updates to search results with job ID: ${searchJobId}`
             );
📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 74d2cfe and 0ead028.

📒 Files selected for processing (2)
  • components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/useSearchResults.ts (3 hunks)
  • components/log-viewer-webui/server/src/plugins/MongoSocketIoServer/index.ts (7 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}`: - Prefer `false == ` rather than `!`.

**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}: - Prefer false == <expression> rather than !<expression>.

  • components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/useSearchResults.ts
  • components/log-viewer-webui/server/src/plugins/MongoSocketIoServer/index.ts
🪛 Biome (1.9.4)
components/log-viewer-webui/server/src/plugins/MongoSocketIoServer/index.ts

[error] 323-324: Template literals are preferred over string concatenation.

Unsafe fix: Use a template literal.

(lint/style/useTemplate)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: lint-check (ubuntu-latest)
  • GitHub Check: lint-check (macos-latest)
  • GitHub Check: build (macos-latest)
🔇 Additional comments (5)
components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/useSearchResults.ts (1)

45-46: LGTM – correct class rename applied
Instantiation reflects the new MongoSocketCollection class. No further action required.

components/log-viewer-webui/server/src/plugins/MongoSocketIoServer/index.ts (4)

204-206: 👍 Switched to debug – matches reduced verbosity goal
Moving the collection-initialisation log to debug aligns with the overall logging-level refactor.


229-233: Detailed subscription request logged at debug – looks good
The richer context (query/options) will aid troubleshooting without polluting higher log levels.


342-343: Unsubscription request logged at debug – consistent with subscribe flow
No issues found.


295-296: 🧹 Nitpick (assertive)

Use template literal to satisfy linter & improve readability

-            this.#fastify.log.error(`Query:${queryId} not found in query map`);
+            this.#fastify.log.error(`Query:${queryId} not found in query map`);

(Only exemplar; no functional change, but keeps style uniform and clears Biome’s useTemplate warning.)

Likely an incorrect or invalid review comment.

Comment on lines +255 to +259
this.#fastify.log.info(
`Socket:${socket.id} subscribed to query:${JSON.stringify(query)} ` +
`with options:${JSON.stringify(options)} ` +
`on collection:${collectionName} with ID:${queryId}`
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Consider downgrading this final “subscribed” message to debug
Earlier discussion left it at info, but now both the request (229-233) and most watcher lifecycle logs are debug. Re-evaluating could further tame noise.

🤖 Prompt for AI Agents
In components/log-viewer-webui/server/src/plugins/MongoSocketIoServer/index.ts
around lines 255 to 259, the log message indicating a socket subscription is
currently at info level, which is inconsistent with earlier request and watcher
lifecycle logs set at debug level. Change the log level from info to debug for
this message to reduce log noise and maintain consistency.

Comment on lines +323 to 324
this.#fastify.log.debug(`Collection:${queryParams.collectionName}` +
" deallocated from server.");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Swap string concatenation for template literal

-            this.#fastify.log.debug(`Collection:${queryParams.collectionName}` +
-            " deallocated from server.");
+            this.#fastify.log.debug(
+                `Collection:${queryParams.collectionName} deallocated from server.`
+            );

This removes the lint error (useTemplate) and is easier to read.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
this.#fastify.log.debug(`Collection:${queryParams.collectionName}` +
" deallocated from server.");
this.#fastify.log.debug(
`Collection:${queryParams.collectionName} deallocated from server.`
);
🧰 Tools
🪛 Biome (1.9.4)

[error] 323-324: Template literals are preferred over string concatenation.

Unsafe fix: Use a template literal.

(lint/style/useTemplate)

🤖 Prompt for AI Agents
In components/log-viewer-webui/server/src/plugins/MongoSocketIoServer/index.ts
at lines 323-324, replace the string concatenation used in the debug log
statement with a single template literal. This means combining the entire
message inside backticks and embedding the variable directly using ${}, which
will remove the lint error and improve readability.

@davemarco davemarco changed the title refactor(new-webui): Improve logging for easier debugging. refactor(new-webui): Improve logging for easier debugging; Improve names of Mongo SocketIO library classes. Jun 11, 2025
@davemarco davemarco merged commit 4cb1276 into y-scope:main Jun 11, 2025
7 checks passed
junhaoliao pushed a commit to junhaoliao/clp that referenced this pull request May 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants