Skip to content

refactor(notification): support compatible Rule configuration storage - #5485

Merged
gergely-kurucz-konghq merged 1 commit into
mainfrom
feat/notification-phase1-rules
Nov 11, 2026
Merged

gergely-kurucz-konghq merged 1 commit into
mainfrom
feat/notification-phase1-rules

Conversation

@chrisgacsal

@chrisgacsal chrisgacsal commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

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

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

RetriggerView in GreptileConfidence 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]
Loading

Reviews (4) · Last reviewed commit: "refactor(notification): support compatib..." · Reviewed by Greptile

@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

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/**
Run configuration

Commits

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.

Changes: Notification Rule Config Compatibility

Layer / File(s) Summary
Rule storage contract
openmeter/ent/schema/notification.go
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.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Feature

Sequence Diagram(s)

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: Passed 4

Check name Status Explanation
Title check Passed The title clearly describes the main change: compatible Rule configuration storage in the notification system.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed 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.

Share

Recent review info

Run configuration

Commits

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.

@chrisgacsal chrisgacsal added the kind/refactor Code refactor, cleanup or minor improvement label Nov 10, 2026
@chrisgacsal
chrisgacsal force-pushed the feat/notification-phase1-rules branch from 995e977 to 33ebab5 Compare November 10, 2026 14:50
@chrisgacsal
chrisgacsal marked this pull request as ready for review November 10, 2026 15:19
@chrisgacsal
chrisgacsal requested a review from a team as a code owner November 10, 2026 15:19
@chrisgacsal
chrisgacsal added this pull request to stack #5488 November 10, 2026 17:30
@chrisgacsal
chrisgacsal removed this pull request from stack #5488 November 11, 2026 09:21
@chrisgacsal
chrisgacsal added this pull request to stack #5490 November 11, 2026 09:47
Base automatically changed from feat/notification-phase1-channels to main November 11, 2026 13:09
@gergely-kurucz-konghq
gergely-kurucz-konghq force-pushed the feat/notification-phase1-rules branch from 72a94b0 to 559bb4f Compare November 11, 2026 13:09
@gergely-kurucz-konghq
gergely-kurucz-konghq merged commit e5b9ba3 into main Nov 11, 2026
37 of 39 checks passed
@gergely-kurucz-konghq
gergely-kurucz-konghq deleted the feat/notification-phase1-rules branch November 11, 2026 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/refactor Code refactor, cleanup or minor improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants