Skip to content

Conversation

hoophalab
Copy link
Contributor

@hoophalab hoophalab commented Jun 23, 2025

Description

The current decode_range() method returns log events as arrays of 4 elements: [message, timestamp, log_level, log_event_num]. This approach has several significant drawbacks:

Current issues

  1. Poor Developer Experience: The array-based format requires developers to memorize or constantly reference documentation to understand what each index represents. This creates unnecessary cognitive overhead and increases the likelihood of bugs.

  2. Limited Scalability: Adding new fields (e.g., Return time zone information for Unstructured IR log events. #79 ) to log events requires updating all consuming code to handle new array indices, making the API brittle and hard to evolve.

  3. Readability: Code using the current API is less self-documenting and harder to maintain.

Change

Replace the array-based return format with structured objects that provide named properties for each log event field. This would transform:

// Current (poor readability)
const event = results[0];
const message = event[0];
const timestamp = event[1];
const logLevel = event[2];
const logEventNum = event[3];

Into:

// Proposed (self-documenting)
const event = results[0];
const message = event.message;
const timestamp = event.timestamp;
const logLevel = event.logLevel;
const logEventNum= event.logEventNum;

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

Test the new ffi in log viewer in this branch.

Summary by CodeRabbit

  • Refactor
    • Updated the format of decoded log events in the JavaScript interface from arrays to objects with named properties for improved clarity.
    • Decoded results can now explicitly be null, enhancing type clarity in the JavaScript environment.

@hoophalab hoophalab requested a review from a team as a code owner June 23, 2025 16:29
Copy link

coderabbitai bot commented Jun 23, 2025

Walkthrough

The changes update the JavaScript interop for decoded log events in the StreamReader component. Instead of returning arrays of values, the code now returns objects with named properties for each log event, and the type signature is updated accordingly in the Emscripten binding to reflect this new structure and allow for null values.

Changes

File(s) Change Summary
src/clp_ffi_js/ir/StreamReader.cpp Updated Emscripten binding registration for decoded results to use an array of objects (with named properties) or null, instead of an array of tuples.
src/clp_ffi_js/ir/StreamReader.hpp Modified generic_decode_range to push log events as objects with named properties instead of arrays; updated documentation and argument order in EM_ASM accordingly.

Sequence Diagram(s)

sequenceDiagram
    participant JS as JavaScript
    participant StreamReader as StreamReader (C++)
    JS->>StreamReader: generic_decode_range()
    StreamReader-->>JS: Array of {logEventNum, logLevel, message, timestamp} objects or null
Loading

Possibly related issues

Possibly related PRs

Suggested reviewers

  • junhaoliao

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0eba286 and c1894c7.

📒 Files selected for processing (1)
  • src/clp_ffi_js/ir/StreamReader.hpp (2 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>.

  • src/clp_ffi_js/ir/StreamReader.hpp
🧠 Learnings (1)
src/clp_ffi_js/ir/StreamReader.hpp (1)
Learnt from: junhaoliao
PR: y-scope/clp-ffi-js#26
File: src/clp_ffi_js/ir/IrStreamReader.cpp:58-59
Timestamp: 2024-11-04T19:35:32.602Z
Learning: In the `IrStreamReader::filter_log_events` method in `src/clp_ffi_js/ir/IrStreamReader.cpp`, the wrapper code is typed with TypeScript, ensuring that non-array inputs for `log_level_filter` would fail static checks, so additional runtime error handling is unnecessary.
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: lint (ubuntu-latest)
✨ 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.

@hoophalab hoophalab changed the title Change return type to an object (fixes #97). refactor: Change return type to an object (fixes #97). Jun 23, 2025
@hoophalab hoophalab changed the title refactor: Change return type to an object (fixes #97). refactor: Change decode_range() return type to an object (fixes #97). Jun 23, 2025
Copy link
Member

@junhaoliao junhaoliao left a comment

Choose a reason for hiding this comment

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

changes lgtm with some nits

for the PR title, how about:

refactor(StreamReader): Change `decode_range()` to return an array of objects (fixes #97).

@hoophalab hoophalab changed the title refactor: Change decode_range() return type to an object (fixes #97). refactor(StreamReader): Change decode_range() to return an array of objects (fixes #97). Jun 24, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
src/clp_ffi_js/ir/StreamReader.hpp (1)

266-279: Align emitted object keys with registered TS type & docs

EM_ASM still pushes logEventNumber, causing the same runtime/type
mismatch noted above. Adopt the canonical names and keep alphabetical
ordering for readability:

-    EM_ASM(
-        {
-            Emval.toValue($0).push({
-                "logEventNumber": $1,
-                "logLevel": $2,
-                "message": UTF8ToString($3),
-                "timestamp": $4,
-            });
-        },
+    EM_ASM(
+        {
+            Emval.toValue($0).push({
+                "logEventNum": $1,
+                "logLevel":   $2,
+                "message":    UTF8ToString($3),
+                "timestamp":  $4,
+            });
+        },
         results.as_handle(),
-        log_event_idx + 1,
+        log_event_idx + 1,   // logEventNum
         log_level,
-        log_event_to_string(log_event).c_str(),
-        timestamp
+        log_event_to_string(log_event).c_str(),
+        timestamp
     );

This resolves the contract break introduced by the rename.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d85aeb7 and 887b0f1.

📒 Files selected for processing (2)
  • src/clp_ffi_js/ir/StreamReader.cpp (1 hunks)
  • src/clp_ffi_js/ir/StreamReader.hpp (2 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>.

  • src/clp_ffi_js/ir/StreamReader.hpp
  • src/clp_ffi_js/ir/StreamReader.cpp
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: lint (ubuntu-latest)
🔇 Additional comments (1)
src/clp_ffi_js/ir/StreamReader.cpp (1)

74-75: Type string now correct – good alignment with new structure

The registered JS type matches the agreed property names and allows
null; no issues here.

@hoophalab
Copy link
Contributor Author

@junhaoliao ready for another pass

* - The log event's timestamp as milliseconds since the Unix epoch
* - The log event's log level as an integer that indexes into `cLogLevelNames`
* - The log event's number (1-indexed) in the stream
* @return An object representing the decoded log events. Each decoded event includes:
Copy link
Member

Choose a reason for hiding this comment

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

#98 (comment)
copying from above since the new comment was made from outdated code

@hoophalab to be precise, instead of returning an array of arrays, now we're returning an array of objects, so i do think it's worth mentioning "array" in the return docstring.

to make this more clear, maybe we can improve it as:

@return An array of objects, where each object represents a decoded log event with the following properties:
...

Copy link
Contributor Author

@hoophalab hoophalab Jun 24, 2025

Choose a reason for hiding this comment

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

Sorry, I didn't read it carefully. It's now ready for another pass. @junhaoliao

@hoophalab hoophalab merged commit ad30546 into y-scope:main Jun 25, 2025
3 checks passed
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