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

docs(clp-json): Update list of characters that requires escaping in queries. #617

Merged
merged 3 commits into from
Dec 2, 2024

Conversation

gibber9809
Copy link
Contributor

@gibber9809 gibber9809 commented Dec 2, 2024

Description

Update docs for JSON search to clarify what characters need to be escaped and when.

Validation performed

Validated that markdown renders as expected.

Summary by CodeRabbit

  • Documentation
    • Revised the CLP JSON search syntax documentation for improved clarity on escaping characters and wildcards.
    • Enhanced cautionary notes regarding the interpretation of spaces in queries and anticipated changes to search behaviour.
    • Clarified the syntax for querying array values and highlighted differences with KQL.

Copy link
Contributor

coderabbitai bot commented Dec 2, 2024

Walkthrough

The documentation for the CLP JSON search syntax has been revised to enhance clarity regarding the rules for querying JSON logs. Key updates include refined escape character rules, expanded wildcard handling, and clarified numeric comparison operators. The documentation specifies the interpretation of queries with spaces, limitations on partial key queries, and differences with KQL, providing users with a clearer understanding of how to construct effective queries.

Changes

File Change Summary
docs/src/user-guide/reference-json-search-syntax.md Updated escape character rules, expanded wildcard handling, clarified numeric comparisons, and improved guidance on querying array values and differences with KQL.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Documentation
    participant CLP

    User->>Documentation: Request for search syntax
    Documentation->>User: Provide updated search syntax rules
    User->>CLP: Construct query based on rules
    CLP-->>User: Return search results
Loading

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

Copy link
Contributor

@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: 0

🧹 Outside diff range and nitpick comments (3)
docs/src/user-guide/reference-json-search-syntax.md (3)

36-40: Consider adding examples to illustrate escaping rules

The escaping rules are clear but would benefit from concrete examples showing both correct and incorrect usage. This would help users better understand when and how to apply these rules.

Consider adding examples like:

 Keys or values with the following literal characters must escape the characters using a `\`
 (backslash): `\`, `"`.
+
+For example:
+```
+# Correct
+path\\"to\\file: value    # Escaping quotes and backslashes
+
+# Incorrect
+path"to\file: value       # Unescaped quotes and backslashes
+```
+
 Unquoted keys or values must also escape the following characters: `(`, `)`, `:`, `<`, `>`, `{`,
 `}`. The unquoted keywords `and`, `or`, and `not` can also be escaped with a `\`.
+
+For example:
+```
+# Correct
+response\:code: 200       # Escaping colon in unquoted key
+"response:code": 200      # Alternative: using quotes instead of escaping
+
+# Incorrect
+response:code: 200        # Unescaped colon in unquoted key
+```

42-46: Clarify the relationship between different escaping contexts

While the rules for escaping wildcards and nested key indicators are accurate, it would be helpful to explicitly state how these rules interact with the general escaping rules mentioned above.

Consider adding a clarifying note:

 Values containing `?` and `*` can escape these characters with a `\` to differentiate them from the
 `?` and `*` characters used to specify arbitrary single character match and wildcard match.

 Keys containing `.` can escape the `.` with `\` to differentiate from the special `.` character that
 indicates nested keys.
+
+Note: These escaping rules for special characters (`?`, `*`, `.`) apply in addition to the general
+escaping rules mentioned above. For example, a key containing both quotes and dots would need both
+characters escaped:
+```
+my\.quoted\"key: value    # Escaping both the dot and the quote
+```

36-46: Overall documentation improvements look good

The changes effectively clarify the character escaping rules in JSON search, which aligns well with the PR objectives. The documentation now provides clear guidance on which characters need escaping and in what contexts.

Consider adding a small table of contents or summary at the start of the escaping rules section to help users quickly find specific escaping rules they're looking for.

Add a summary like:

+### Character Escaping Rules
+
+Quick reference:
+- Always escape: `\` and `"`
+- Escape when unquoted: `(`, `)`, `:`, `<`, `>`, `{`, `}`
+- Special characters:
+  - Wildcards (`?`, `*`): Escape to use literally in values
+  - Dot (`.`): Escape to use literally in keys
+
 Keys or values with the following literal characters must escape the characters using a `\`
 (backslash): `\`, `"`.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 88d83bf and ee70056.

📒 Files selected for processing (1)
  • docs/src/user-guide/reference-json-search-syntax.md (1 hunks)

Copy link
Contributor

@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: 0

🧹 Outside diff range and nitpick comments (2)
docs/src/user-guide/reference-json-search-syntax.md (2)

167-193: Consider adding examples for better clarity.

While the escaping rules are well-organized, adding examples would make them more accessible. Consider adding a subsection with examples like:

#### Examples of character escaping

**In keys:**
```json
{
  "my\\.key": "value",         // Escaped dot in key
  "my\"quoted\"key": "value"   // Escaped quotes in key
}

In values:

{
  "key": "value with \\",      // Escaped backslash
  "key": "value with \"quote"  // Escaped quote
}

In unquoted contexts:

key\:value                     // Escaped colon when unquoted

<details>
<summary>🧰 Tools</summary>

<details>
<summary>🪛 Markdownlint (0.35.0)</summary>

183-183: Expected: asterisk; Actual: underscore
Emphasis style

(MD049, emphasis-style)

---

183-183: Expected: asterisk; Actual: underscore
Emphasis style

(MD049, emphasis-style)

</details>

</details>

---

`183-184`: **Fix markdown emphasis style.**

For consistency with the rest of the document, use asterisks instead of underscores for emphasis.

```diff
-_Unquoted_ keys or values containing the following literal characters must also escape the
+*Unquoted* keys or values containing the following literal characters must also escape the
🧰 Tools
🪛 Markdownlint (0.35.0)

183-183: Expected: asterisk; Actual: underscore
Emphasis style

(MD049, emphasis-style)


183-183: Expected: asterisk; Actual: underscore
Emphasis style

(MD049, emphasis-style)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 58a7251 and 0967dc8.

📒 Files selected for processing (1)
  • docs/src/user-guide/reference-json-search-syntax.md (2 hunks)
🧰 Additional context used
🪛 Markdownlint (0.35.0)
docs/src/user-guide/reference-json-search-syntax.md

183-183: Expected: asterisk; Actual: underscore
Emphasis style

(MD049, emphasis-style)


183-183: Expected: asterisk; Actual: underscore
Emphasis style

(MD049, emphasis-style)

🔇 Additional comments (1)
docs/src/user-guide/reference-json-search-syntax.md (1)

42-47: LGTM! Well-placed introductory note.

The note effectively alerts users about special character handling and provides a clear reference to the detailed section.

Copy link
Member

@kirkrodrigues kirkrodrigues left a comment

Choose a reason for hiding this comment

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

For the PR title, how about:

docs(clp-json): Update list of characters that requires escaping in queries.

@gibber9809 gibber9809 changed the title chore(clp-package): Update docs for escaping characters in JSON search. docs(clp-json): Update list of characters that requires escaping in queries. Dec 2, 2024
@kirkrodrigues kirkrodrigues merged commit 9439d30 into y-scope:main Dec 2, 2024
6 checks passed
jackluo923 pushed a commit to jackluo923/clp that referenced this pull request Dec 4, 2024
…ueries. (y-scope#617)

Co-authored-by: Kirk Rodrigues <2454684+kirkrodrigues@users.noreply.github.com>
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