Skip to content

feat: add misc fields to filter #1321

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

Merged
merged 2 commits into from
May 22, 2025
Merged

Conversation

parmesant
Copy link
Contributor

@parmesant parmesant commented May 21, 2025

Fixes #XXXX.

Description


This PR has:

  • been tested to ensure log ingestion and log query works.
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added documentation for new or modified features or behaviors.

Summary by CodeRabbit

  • New Features
    • Improved support for flexible and extensible filter options, allowing additional custom fields to be included when filtering users.

Copy link
Contributor

coderabbitai bot commented May 21, 2025

Walkthrough

The Filter struct in src/users/filters.rs was updated to include a new optional field, other_fields, which uses Serde's flatten attribute. This change allows the struct to accept and store arbitrary additional JSON fields during deserialization.

Changes

File(s) Change Summary
src/users/filters.rs Added an optional other_fields field with Serde's flatten attribute to the Filter struct.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant FilterStruct

    Client->>FilterStruct: Send JSON with known and unknown fields
    FilterStruct-->>FilterStruct: Deserialize known fields normally
    FilterStruct-->>FilterStruct: Store extra fields in other_fields (if any)
    FilterStruct-->>Client: Struct holds all fields, including arbitrary extras
Loading

Poem

A filter now with room to grow,
Accepts new fields you wish to show.
With Serde’s magic, tucked inside,
Extra data need not hide!
Rabbits cheer this clever feat—
Flexible filters, oh so neat!
🐇✨

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 30th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.

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

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

🧹 Nitpick comments (2)
src/users/filters.rs (2)

44-46: Good approach for flexible extension!

Using #[serde(flatten)] to capture arbitrary fields is a robust pattern that allows the Filter struct to be extended without breaking existing code. This change enables storing additional metadata without requiring schema changes.

Consider enhancing the documentation to be more explicit about how this field works with Serde's flattening behavior:

-    /// all other fields are variable and can be added as needed
+    /// Additional arbitrary fields not defined in the struct.
+    /// The #[serde(flatten)] attribute causes Serde to collect any JSON fields
+    /// not matching other struct fields into this map during deserialization.
+    /// This allows extending the filter with custom metadata without schema changes.
     #[serde(flatten)]
     pub other_fields: Option<serde_json::Map<String, Value>>,

44-46: Consider adding tests for the flattened fields

To ensure that the new other_fields functionality works as expected, it would be beneficial to add tests.

Consider adding tests that verify:

  1. Deserialization of JSON with extra fields populates other_fields correctly
  2. Serialization of a Filter with populated other_fields includes those fields in the JSON output
  3. Migration functions preserve other_fields data
  4. Edge cases like empty objects, null fields, etc.

A simple test could look like:

#[test]
fn test_filter_with_other_fields() {
    let json = r#"{
        "stream_name": "test",
        "filter_name": "test_filter",
        "query": {
            "filter_type": "filter"
        },
        "custom_field": "custom_value",
        "metadata": {
            "nested": "value"
        }
    }"#;
    
    let filter: Filter = serde_json::from_str(json).unwrap();
    
    // Verify standard fields
    assert_eq!(filter.stream_name, "test");
    assert_eq!(filter.filter_name, "test_filter");
    
    // Verify other_fields
    let other_fields = filter.other_fields.unwrap();
    assert_eq!(other_fields.get("custom_field").unwrap().as_str().unwrap(), "custom_value");
    assert!(other_fields.get("metadata").unwrap().is_object());
    
    // Verify roundtrip serialization
    let serialized = serde_json::to_string(&filter).unwrap();
    let deserialized: serde_json::Value = serde_json::from_str(&serialized).unwrap();
    assert_eq!(deserialized.get("custom_field").unwrap().as_str().unwrap(), "custom_value");
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 429fe00 and 5fb2356.

📒 Files selected for processing (1)
  • src/users/filters.rs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: Build Default x86_64-pc-windows-msvc
  • GitHub Check: Build Default aarch64-apple-darwin
  • GitHub Check: Build Default x86_64-apple-darwin
  • GitHub Check: Build Kafka aarch64-apple-darwin
  • GitHub Check: Build Default aarch64-unknown-linux-gnu
  • GitHub Check: Quest Smoke and Load Tests for Standalone deployments
  • GitHub Check: Build Kafka x86_64-unknown-linux-gnu
  • GitHub Check: Build Default x86_64-unknown-linux-gnu
  • GitHub Check: Quest Smoke and Load Tests for Distributed deployments
  • GitHub Check: coverage
🔇 Additional comments (1)
src/users/filters.rs (1)

44-46:

❓ Verification inconclusive

Verify handling of flattened fields

While this change is well-implemented, it's important to verify how these additional fields behave through the full lifecycle.

Consider how these arbitrary fields are handled in these scenarios:

  1. When filters are saved to storage
  2. When filters are loaded from storage
  3. When filters are migrated between versions
  4. When filters are accessed through APIs

🏁 Script executed:

#!/bin/bash
# Check if we have any handling of other_fields in the codebase
echo "Checking references to other_fields:"
rg "other_fields" --type rust

echo -e "\nChecking serialization/deserialization of Filter struct:"
rg "serde_json::(from|to)_(slice|string|value)" -A 2 -B 2 --type rust | rg -A 2 -B 2 "Filter"

Length of output: 764


🏁 Script executed:

#!/bin/bash
# Locate the Filter struct definition and its implementation to inspect serialization/deserialization
echo "Extracting struct Filter definition and impl blocks:"
rg --context 10 "struct Filter" -n src/users/filters.rs
rg --context 10 "impl Filter" -n src/users/filters.rs

Length of output: 4071


🏁 Script executed:

#!/bin/bash
# Checking retrieval of raw filters and saving/migration logic
echo "Looking for get_all_saved_filters usage:"
rg -n "get_all_saved_filters" -C 3 src/users/filters.rs

echo -e "\nInspecting save/migration logic in Filters impl:"
rg -n "filter_path" -C 5 src/users/filters.rs
rg -n "save" -C 3 src/users/filters.rs
rg -n "put" -C 3 src/users/filters.rs

echo -e "\nChecking migration helper functions:"
rg -n "migration::" -C 3 src/users/filters.rs
rg -n "to_bytes" -C 3 src/users/filters.rs

Length of output: 3496


🏁 Script executed:

#!/bin/bash
# Extract full load method for Filters
rg -C50 "pub async fn load" -n src/users/filters.rs

Length of output: 3988


Verify persistence of other_fields across storage, migration, and API layers

We’ve confirmed that #[serde(flatten)] pub other_fields is only referenced in the Filter struct and populated during Filters::load (via serde_json::from_value). Migration code uses to_bytes(&Value) and re-writes v1→v2 filters—so unknown fields will round-trip there—but we didn’t find any method in this module that serializes a Filter instance back to storage outside of migration.

Please ensure:

  • Filters::load / migration
    migrate_v1_v2 preserves all extra JSON fields in its output.
    to_bytes(&filter_value) includes other_fields when re-saving migrated filters.

  • New‐filter persistence
    • Locate where new or updated Filter instances are serialized (e.g. via serde_json::to_vec or to_bytes) and saved (e.g. put_object) after API calls or service operations.
    • Confirm that other_fields is included in that serialization.

  • API input/output
    • Check any REST/gRPC handlers that accept or return Filter JSON to ensure they allow arbitrary fields on input and echo them back on output.

  • Cross‐version migrations
    • If you add future schema changes, update migration functions to carry through unknown fields in the JSON map.

@nitisht nitisht merged commit 2ff1421 into parseablehq:main May 22, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants