You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
refactor(notification): support compatible Rule configuration storage - #5485
Move notification Rule type and configuration handling into the adapter. This is the second PR in the Channel → Rule → Event stack.
Why
Rule readers need to support the future flat configuration format while old backends continue to require the legacy envelope.
How
Retain the supported, unversioned Rule types and validate them on write.
Decode the legacy envelope and type-specific flat config, including Rules read through Events. Keep writing the legacy representation and preserve Channel assignments.
Verify both formats and malformed data against PostgreSQL. The existing text and JSONB columns support this change without SQL DDL.
Summary by CodeRabbit
Bug Fixes
Notification rules now read both legacy and flat configuration formats, while preserving stored configuration during reads.
Invalid or malformed rule configurations now return clear errors when rules or related events are retrieved or saved.
Rule creation and updates continue to validate configurations and store them in the legacy format.
Documentation
Added guidance on rule type and configuration compatibility, including the formats supported during migration.
Confidence Score: 5/5
The PR appears safe to merge; no actionable new issues were found.
Summary
Moves Rule config encoding and decoding from the Ent schema into the notification adapter.
Rules read flat configs while keeping legacy writes.
No actionable new issues were found. Tests were inspected, not run.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
A[Rule write] --> B[Validate config]
B --> C[Encode legacy envelope]
C --> D[(Existing JSONB column)]
D --> E[Try legacy envelope]
E -->|Not accepted| F[Try strict flat config]
E -->|Accepted| G[Rule]
F -->|Accepted| G
F -->|Not accepted| H[Return decode error]
G --> I[Nested Event reads]
Reviewing files that changed from the base of the PR and between 72a94b0 and 559bb4f.
Files ignored due to path filters: 8
openmeter/ent/db/migrate/schema.go is excluded by !**/ent/db/**
openmeter/ent/db/mutation.go is excluded by !**/ent/db/**
openmeter/ent/db/notificationrule.go is excluded by !**/ent/db/**
openmeter/ent/db/notificationrule/notificationrule.go is excluded by !**/ent/db/**
openmeter/ent/db/notificationrule/where.go is excluded by !**/ent/db/**
openmeter/ent/db/notificationrule_create.go is excluded by !**/ent/db/**
openmeter/ent/db/notificationrule_update.go is excluded by !**/ent/db/**
openmeter/ent/db/runtime.go is excluded by !**/ent/db/**
You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.
Use the checkbox below for a quick retry:
Trigger review
No actionable comments were generated in the recent review.
Walkthrough
Notification rule configuration now uses raw JSON storage. The adapter accepts legacy-envelope and flat configurations on reads, validates configurations before writes, and continues to write the legacy envelope format.
The type field uses a string schema while retaining its Go type and immutability. The config field uses json.RawMessage and the generic JSON scanner, replacing the custom scanner.
Configuration conversion and persistence openmeter/notification/adapter/rule.go, openmeter/notification/adapter/rule_test.go
Writes validate configurations and store them in the legacy {type, data} envelope. Reads accept matching legacy envelopes or flat JSON objects with unknown fields rejected. Tests cover event types, supported formats, format precedence, and write validation.
Read mapping and compatibility coverage openmeter/notification/adapter/entitymapping.go, openmeter/notification/adapter/event_test.go, openmeter/notification/adapter/rule_test.go, openmeter/notification/README.md
Database mapping decodes rule configuration and adds namespace and rule ID context to errors. Tests cover malformed configuration across rule and event reads. The README documents storage compatibility and read behavior.
sequenceDiagram
participant Caller
participant RuleAdapter
participant Database
Caller->>RuleAdapter: GetRule or GetEvent
RuleAdapter->>Database: Load rule entity
Database-->>RuleAdapter: Entity with raw configuration
RuleAdapter->>RuleAdapter: RuleFromDBEntity decodes configuration
RuleAdapter-->>Caller: Rule or event, or decode error
Loading
Suggested labels:release-note/feature
Suggested reviewers:galexihu, borosr
Merge Risk: Minimal · previous review 33eba
The change lets notification rule readers accept both the legacy and the flat configuration formats while writes keep the legacy format. No actionable merge-blocking risk was found.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title clearly describes the main change: compatible Rule configuration storage in the notification system.
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Finishing Touches
Generate docstrings
Commit to this branch
Create a new PR
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
Reviewing files that changed from the base of the PR and between b70d6b2 and 33ebab5.
Files ignored due to path filters: 8
openmeter/ent/db/migrate/schema.go is excluded by !**/ent/db/**
openmeter/ent/db/mutation.go is excluded by !**/ent/db/**
openmeter/ent/db/notificationrule.go is excluded by !**/ent/db/**
openmeter/ent/db/notificationrule/notificationrule.go is excluded by !**/ent/db/**
openmeter/ent/db/notificationrule/where.go is excluded by !**/ent/db/**
openmeter/ent/db/notificationrule_create.go is excluded by !**/ent/db/**
openmeter/ent/db/notificationrule_update.go is excluded by !**/ent/db/**
openmeter/ent/db/runtime.go is excluded by !**/ent/db/**
Files selected for processing: 6
openmeter/ent/schema/notification.go
openmeter/notification/README.md
openmeter/notification/adapter/entitymapping.go
openmeter/notification/adapter/event_test.go
openmeter/notification/adapter/rule.go
openmeter/notification/adapter/rule_test.go
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kind/refactorCode refactor, cleanup or minor improvement
2 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Move notification Rule type and configuration handling into the adapter. This is the second PR in the Channel → Rule → Event stack.
Why
Rule readers need to support the future flat configuration format while old backends continue to require the legacy envelope.
How
Summary by CodeRabbit
Bug Fixes
Documentation


Confidence Score: 5/5
The PR appears safe to merge; no actionable new issues were found.Summary
Moves Rule config encoding and decoding from the Ent schema into the notification adapter.
No actionable new issues were found. Tests were inspected, not run.
Diagram
%%{init: {'theme': 'neutral'}}%% flowchart LR A[Rule write] --> B[Validate config] B --> C[Encode legacy envelope] C --> D[(Existing JSONB column)] D --> E[Try legacy envelope] E -->|Not accepted| F[Try strict flat config] E -->|Accepted| G[Rule] F -->|Accepted| G F -->|Not accepted| H[Return decode error] G --> I[Nested Event reads]Reviews (4) · Last reviewed commit: "refactor(notification): support compatib..." · Reviewed by Greptile