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

feat!: Add support for viewing auto-generated keys in Structured IR files. #192

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

davemarco
Copy link
Contributor

@davemarco davemarco commented Feb 27, 2025

Description

Adds support to view autogenerated keys in Structured IR files. Moreover, these keys
can be queried using @ in format string.

Marked as breaking change since will potentially break existing format strings with @ specifier.

Support for filtering with autogenerated keys will come later and is not yet supported.

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.
  • Docs will come later in another PR

Validation performed

Did basic validation with file Zhihao provided that it could be opened and formatted.

Summary by CodeRabbit

  • New Features

    • Improved log formatting now clearly distinguishes between auto-generated and user-generated elements, enhancing readability and robustness.
  • Chores

    • Updated and reorganised project dependencies to ensure enhanced stability and consistency.

Copy link

coderabbitai bot commented Feb 27, 2025

Walkthrough

This pull request updates several dependencies in the package.json file and enhances the IR decoding and log formatting processes. Modifications introduce structured IR namespace keys into the ClpIrDecoder and YscopeFormatter classes, requiring updates to their constructors, methods, and associated utilities. Additionally, the PR adds new TypeScript types and functions, revises import paths, and adjusts error handling in utility modules.

Changes

File(s) Change Summary
package.json Updated dependency versions: bumped clp-ffi-js from ^0.3.4 to ^0.4.0 and re-added html-webpack-plugin and mini-css-extract-plugin under devDependencies (versions unchanged).
src/services/decoders/ClpIrDecoder/index.ts
src/services/decoders/ClpIrDecoder/utils.ts
Modified ClpIrDecoder to include a new #structuredIrNamespaceKeys property; updated constructor signature and creation method to handle structured IR namespace keys; introduced new enum (CLP_IR_STREAM_TYPE), interface (StructuredIrNamespaceKeys), and helper function getStructuredIrNamespaceKeys.
src/services/formatters/YscopeFormatter/FieldFormatters/RoundFormatter.ts
src/services/formatters/YscopeFormatter/index.ts
src/services/formatters/YscopeFormatter/utils.ts
Revised import paths; updated YscopeFormatter to include a new #structuredIrNamespaceKeys property and modified its formatLogEvent and placeholder-splitting process; replaced jsonValueToString with enhanced functions (getFieldsByNamespace and parseKey) and updated associated error handling and return types.
src/typings/formatters.ts Added new types: ParsedFieldName, updated YscopeFieldPlaceholder to use parsedFieldName, and included an optional structuredIrNamespaceKeys property in YscopeFormatterOptionsType; introduced constant AUTO_GENERATED_KEY_PREFIX.
src/utils/js.ts Added new function jsonValueToString (converts JSON values to strings) and updated the export statement to include this function alongside getNestedJsonValue.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant ClpIrDecoder
    participant Utils
    participant YscopeFormatter

    Client->>ClpIrDecoder: create(module, decoderOptions)
    ClpIrDecoder->>Utils: getStructuredIrNamespaceKeys(module)
    Utils-->>ClpIrDecoder: structuredIrNamespaceKeys
    ClpIrDecoder->>YscopeFormatter: new YscopeFormatter(options, structuredIrNamespaceKeys)
    Client->>YscopeFormatter: formatLogEvent(logEvent)
    YscopeFormatter->>Utils: splitFieldPlaceholder(placeholder, structuredIrNamespaceKeys)
    Utils-->>YscopeFormatter: ParsedFieldName
    YscopeFormatter->>Utils: getFieldsByNamespace(logEvent, structuredIrNamespaceKeys, ParsedFieldName)
    Utils-->>YscopeFormatter: formatted field value
    YscopeFormatter-->>Client: formatted log event
Loading

Possibly related PRs

✨ Finishing Touches
  • 📝 Generate Docstrings

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 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.

@davemarco davemarco changed the title feat: Add support to view auto-generated keys in Structured IR files. feat!: Add support to view auto-generated keys in Structured IR files. Feb 27, 2025
@davemarco davemarco requested a review from junhaoliao February 27, 2025 02:39
@davemarco davemarco marked this pull request as ready for review February 27, 2025 02:39
@davemarco davemarco changed the title feat!: Add support to view auto-generated keys in Structured IR files. feat!: Add support for viewing auto-generated keys in Structured IR files. Feb 27, 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

🧹 Nitpick comments (2)
src/utils/js.ts (1)

30-35: Complete the JSDoc documentation.

The JSDoc documentation for the jsonValueToString function is missing descriptions for the @param input and @return tags.

 /**
  * Converts a JSON value to its string representation.
  *
- * @param input
- * @return
+ * @param input The JSON value to convert to a string
+ * @return The string representation of the input
  */
src/typings/formatters.ts (1)

23-24: Add documentation for the structuredIrNamespaceKeys property.

The JSDoc comment for YscopeFormatterOptionsType doesn't explain what the structuredIrNamespaceKeys property is for.

 * All three as may contain any character, except that colons (:), right braces (}),
 * and backslashes (\) must be escaped with a backslash.
- * @property [structuredIrNamespaceKeys]
+ * @property [structuredIrNamespaceKeys] Keys that delineate the auto-generated and 
+ * user-generated namespaces in structured IR log events.
 */
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8ddd27a and d2b1f71.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (8)
  • package.json (2 hunks)
  • src/services/decoders/ClpIrDecoder/index.ts (3 hunks)
  • src/services/decoders/ClpIrDecoder/utils.ts (1 hunks)
  • src/services/formatters/YscopeFormatter/FieldFormatters/RoundFormatter.ts (1 hunks)
  • src/services/formatters/YscopeFormatter/index.ts (6 hunks)
  • src/services/formatters/YscopeFormatter/utils.ts (7 hunks)
  • src/typings/formatters.ts (5 hunks)
  • src/utils/js.ts (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • src/services/formatters/YscopeFormatter/FieldFormatters/RoundFormatter.ts
  • package.json
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}`: - Prefer `false == ...

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

  • src/services/formatters/YscopeFormatter/index.ts
  • src/typings/formatters.ts
  • src/utils/js.ts
  • src/services/decoders/ClpIrDecoder/utils.ts
  • src/services/decoders/ClpIrDecoder/index.ts
  • src/services/formatters/YscopeFormatter/utils.ts
🧠 Learnings (1)
src/services/decoders/ClpIrDecoder/index.ts (1)
Learnt from: davemarco
PR: y-scope/yscope-log-viewer#123
File: src/services/decoders/ClpIrDecoder.ts:42-42
Timestamp: 2024-11-18T01:35:35.812Z
Learning: The interface `YscopeFormatterOptionsType` is defined in `src/typings/formatters.ts` and is used to type the options passed to `YscopeFormatter`, ensuring type safety in constructor calls like `new YscopeFormatter({ formatString: decoderOptions.formatString })`.
🪛 Biome (1.9.4)
src/services/decoders/ClpIrDecoder/utils.ts

[error] 14-14: Shouldn't redeclare 'StructuredIrNamespaceKeys'. Consider to delete it or rename it.

'StructuredIrNamespaceKeys' is defined here:

(lint/suspicious/noRedeclare)

🔇 Additional comments (23)
src/utils/js.ts (1)

36-41: LGTM! Function implementation looks good.

The implementation of jsonValueToString correctly handles both object and non-object types, including undefined values.

src/services/formatters/YscopeFormatter/index.ts (4)

29-29: LGTM! Property is correctly defined.

The new #structuredIrNamespaceKeys property is properly defined as a readonly private field with the correct type.


34-34: LGTM! Proper initialization with null coalescing.

The field is properly initialized from the options parameter with a null fallback.


59-63: LGTM! Updated function parameters.

The getFormattedField function call has been correctly updated to include the new structuredIrNamespaceKeys parameter.


93-94: LGTM! Updated parameter and destructuring.

The destructuring now correctly uses parsedFieldName instead of fieldNameKeys to match the updated interface.

src/typings/formatters.ts (2)

68-71: LGTM! Good type definition for ParsedFieldName.

The new type definition is well structured and has appropriate properties to handle auto-generated keys.


92-95: LGTM! Clear documentation for AUTO_GENERATED_KEY_PREFIX.

The constant is well documented, clearly explaining its purpose.

src/services/decoders/ClpIrDecoder/utils.ts (1)

26-41: LGTM! Well-implemented type checking and error handling.

The function properly validates that the keys are strings before returning them, with clear error messages if the validation fails.

src/services/decoders/ClpIrDecoder/index.ts (7)

4-4: New "Nullable" import added.
No issues identified. The import is consistent with the usage of Nullable in the file.


11-16: Updated import statements.
All new import lines correctly reference the necessary decoder and formatter types from the respective directories. No concerns about maintainability or correctness.


20-25: Imports from ClpIrDecoder utils.
These imports for CLP_IR_STREAM_TYPE, getStructuredIrNamespaceKeys, and StructuredIrNamespaceKeys appear valid and are used properly within the file. No issues found.


33-34: New field for storing structured IR namespace keys.
Defining #structuredIrNamespaceKeys as readonly ensures it remains immutable once set. This helps keep the class consistent.


37-50: Constructor updated to accept and store structured IR namespace keys.

  1. Storing structuredIrNamespaceKeys in a private field is a good approach for encapsulation.
  2. Initializing YscopeFormatter with the new keys is logically consistent.
  3. The check for an empty format string (if (0 === decoderOptions.formatString.length)) leads to postFormatPopup(); that flow remains intact, so no functional regressions are apparent.

77-81: Factory method updated to pass structured IR namespace keys.
Using getStructuredIrNamespaceKeys(module) cleanly provides the needed keys to the constructor. This ensures that the decoder can handle structured logs with the newly added keys.


105-109: setFormatterOptions updated to instantiate new formatter with namespace keys.
Re-instantiating the formatter here reinforces consistent behaviour with updated options. No issues from a performance or correctness standpoint, given the typical usage patterns.

src/services/formatters/YscopeFormatter/utils.ts (8)

3-20: Extended imports for auto-generated key constants and structured IR support.
All newly imported symbols (AUTO_GENERATED_KEY_PREFIX, ParsedFieldName, StructuredIrNamespaceKeys, etc.) match the usage in this file. No concerns regarding import paths or naming.


33-35: Revised JSDoc comments for removing backslashes.
Documentation accurately describes the purpose of removing escape characters. No issues found.


69-79: replaceDoubleBacklash for handling escaped backslashes.
The logic to replace double backslashes with a rare replacement character, then restore them later, is a clear approach. No performance caveats or errors identified.


83-111: New getFieldsByNamespace function.

  1. Correctly distinguishes auto-generated vs. user-generated namespaces using parsedFieldName.isAutoGenerated.
  2. Throws an error if the key is missing or if the fields are not valid JSON objects, which improves robustness.
  3. Complies with the coding guideline preferring false === <expression> rather than !<expression>.

125-139: Updated getFormattedField to handle structured IR namespace keys.

  1. When structuredIrNamespaceKeys is null, the code falls back to regular log event fields.
  2. Otherwise, it retrieves the correct namespace fields and calls getNestedJsonValue.
  3. Uses jsonValueToString or a formatter for final output. This is coherent with the overall formatting flow.

159-176: New parseKey function.

  1. Separates isAutoGenerated from user-defined keys by detecting AUTO_GENERATED_KEY_PREFIX.
  2. Removes the prefix and splits the remainder into parts.
  3. Good use of removeEscapeCharacters for each part.
    No concerns about correctness or performance.

178-229: Extended splitFieldPlaceholder to parse structured IR placeholders.

  1. Correctly calls parseKey to handle both auto-generated and user-defined placeholders.
  2. Enforces an error if auto-generated prefix is present without structuredIrNamespaceKeys.
  3. Properly handles optional formatter name and formatter options, removing escape characters.

234-234: Export of parseKey.
Ensures this helper function is available to other modules. No issues found.

@@ -0,0 +1,50 @@
import {MainModule} from "clp-ffi-js";

import {StructuredIrNamespaceKeys} from "../../../typings/decoders";
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Resolve interface redeclaration issue.

The StructuredIrNamespaceKeys interface is imported on line 3 and then redeclared on lines 14-17, causing a potential conflict.

Choose one of these solutions:

- import {StructuredIrNamespaceKeys} from "../../../typings/decoders";
+ // Import StructuredIrNamespaceKeys from typings or define it here, not both

OR move the interface definition to ../../../typings/decoders.ts and only import it:

 import {StructuredIrNamespaceKeys} from "../../../typings/decoders";

-/**
- * Keys that delineate the auto-generated and user-generated namespaces in structured IR log events.
- */
-interface StructuredIrNamespaceKeys {
-    auto: string;
-    user: string;
-}

Also applies to: 14-17

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.

1 participant