-
Notifications
You must be signed in to change notification settings - Fork 14
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
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThis pull request updates several dependencies in the Changes
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
Possibly related PRs
✨ Finishing Touches
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 thestructuredIrNamespaceKeys
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
⛔ 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}
: - Preferfalse == <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, includingundefined
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 newstructuredIrNamespaceKeys
parameter.
93-94
: LGTM! Updated parameter and destructuring.The destructuring now correctly uses
parsedFieldName
instead offieldNameKeys
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 ofNullable
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 forCLP_IR_STREAM_TYPE
,getStructuredIrNamespaceKeys
, andStructuredIrNamespaceKeys
appear valid and are used properly within the file. No issues found.
33-34
: New field for storing structured IR namespace keys.
Defining#structuredIrNamespaceKeys
asreadonly
ensures it remains immutable once set. This helps keep the class consistent.
37-50
: Constructor updated to accept and store structured IR namespace keys.
- Storing
structuredIrNamespaceKeys
in a private field is a good approach for encapsulation.- Initializing
YscopeFormatter
with the new keys is logically consistent.- The check for an empty format string (
if (0 === decoderOptions.formatString.length)
) leads topostFormatPopup()
; that flow remains intact, so no functional regressions are apparent.
77-81
: Factory method updated to pass structured IR namespace keys.
UsinggetStructuredIrNamespaceKeys(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
: NewgetFieldsByNamespace
function.
- Correctly distinguishes auto-generated vs. user-generated namespaces using
parsedFieldName.isAutoGenerated
.- Throws an error if the key is missing or if the fields are not valid JSON objects, which improves robustness.
- Complies with the coding guideline preferring
false === <expression>
rather than!<expression>
.
125-139
: UpdatedgetFormattedField
to handle structured IR namespace keys.
- When
structuredIrNamespaceKeys
is null, the code falls back to regular log event fields.- Otherwise, it retrieves the correct namespace fields and calls
getNestedJsonValue
.- Uses
jsonValueToString
or a formatter for final output. This is coherent with the overall formatting flow.
159-176
: NewparseKey
function.
- Separates
isAutoGenerated
from user-defined keys by detectingAUTO_GENERATED_KEY_PREFIX
.- Removes the prefix and splits the remainder into parts.
- Good use of
removeEscapeCharacters
for each part.
No concerns about correctness or performance.
178-229
: ExtendedsplitFieldPlaceholder
to parse structured IR placeholders.
- Correctly calls
parseKey
to handle both auto-generated and user-defined placeholders.- Enforces an error if auto-generated prefix is present without
structuredIrNamespaceKeys
.- Properly handles optional formatter name and formatter options, removing escape characters.
234-234
: Export ofparseKey
.
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"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
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
breaking change.
Validation performed
Did basic validation with file Zhihao provided that it could be opened and formatted.
Summary by CodeRabbit
New Features
Chores