Skip to content

feat(pkg): add IsEmpty method to filters and update list events param… #2508

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tothandras
Copy link
Contributor

@tothandras tothandras commented Mar 22, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced validation logic to ensure that filters must contain valid, non-empty values when applied simultaneously.
  • New Features

    • Introduced a mechanism to verify if a filter is empty, improving filtering consistency.
  • Tests

    • Added comprehensive tests to validate filter detection under various conditions.

@tothandras tothandras added the release-note/misc Miscellaneous changes label Mar 22, 2025
@tothandras tothandras requested a review from a team as a code owner March 22, 2025 23:16
Copy link

coderabbitai bot commented Mar 22, 2025

📝 Walkthrough

Walkthrough

The changes enhance input validation and filtering functionality. In the event service, the Validate method of the parameters now enforces that time-related filters (Time and IngestedAt) are non-empty when provided. In the filter package, a new IsEmpty() method has been added to the Filter interface and its various implementations (string, integer, float, time, and boolean types). Complementary tests were also added to ensure these methods behave as expected under different scenarios.

Changes

File(s) Change Summary
openmeter/.../service.go Updated the Validate method in ListEventsV2Params to enforce non-empty checks on the Time and IngestedAt filters when both are provided.
pkg/filter/... Added the IsEmpty() method to the Filter interface and its implementations (FilterString, FilterInteger, FilterFloat, FilterTime, FilterBoolean) along with corresponding tests.
✨ 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.
    • 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.

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

🧹 Nitpick comments (1)
openmeter/meterevent/service.go (1)

182-182: Enhanced validation logic for filter combinations

The additional checks for !p.Time.IsEmpty() and !p.IngestedAt.IsEmpty() improve the validation by ensuring that both filters contain valid, non-empty values if they are to be used together.

Consider updating the error message to more accurately reflect the condition being checked, as it now allows both filters to be set if at least one is empty:

-        errs = append(errs, errors.New("time and ingested_at cannot both be set"))
+        errs = append(errs, errors.New("time and ingested_at cannot both be set with non-empty values"))
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 38192cf and 3ede40c.

📒 Files selected for processing (3)
  • openmeter/meterevent/service.go (1 hunks)
  • pkg/filter/filter.go (6 hunks)
  • pkg/filter/filter_test.go (1 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
pkg/filter/filter_test.go (1)
pkg/filter/filter.go (5)
  • FilterString (32-47)
  • FilterInteger (161-170)
  • FilterFloat (270-279)
  • FilterBoolean (481-483)
  • FilterTime (378-385)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: CI
  • GitHub Check: Analyze (go)
🔇 Additional comments (11)
pkg/filter/filter.go (6)

19-20: Well-designed interface extension

Adding the IsEmpty() method to the Filter interface is a clean way to enhance filtering capabilities across all implementation types.


115-118: Thorough implementation for FilterString

The implementation correctly checks all possible filter fields in the FilterString struct to determine if the filter is empty.


236-239: Consistent implementation for FilterInteger

The implementation follows the same pattern as FilterString, checking all fields to ensure consistency.


344-347: Consistent implementation for FilterFloat

The implementation properly checks all fields in the FilterFloat struct.


451-454: Proper implementation for FilterTime

The method correctly identifies if a FilterTime instance has any configured filter criteria.


496-499: Simple implementation for FilterBoolean

The implementation is appropriately simple for FilterBoolean as it only has one field to check.

pkg/filter/filter_test.go (5)

1511-1632: Comprehensive tests for FilterString.IsEmpty

The test cases thoroughly cover all possible scenarios for the FilterString type, testing each field individually to ensure the IsEmpty method works correctly.


1634-1713: Thorough testing for FilterInteger.IsEmpty

The test cases comprehensively validate the IsEmpty functionality for FilterInteger type, covering empty filters and all possible field combinations.


1715-1794: Comprehensive tests for FilterFloat.IsEmpty

All relevant cases for FilterFloat are tested, maintaining consistency with the test approach for other filter types.


1796-1829: Complete test coverage for FilterBoolean.IsEmpty

The tests appropriately cover both true and false values for the FilterBoolean type's Eq field.


1831-1898: Well-structured tests for FilterTime.IsEmpty

The test cases provide good coverage for all possible field combinations in FilterTime, ensuring the IsEmpty method works as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note/misc Miscellaneous changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants