Skip to content

fix: active entitlement validation blocking meter delete - #4835

Merged
chrisgacsal merged 2 commits into
mainfrom
fix/meter-delete
Aug 3, 2026
Merged

fix: active entitlement validation blocking meter delete#4835
chrisgacsal merged 2 commits into
mainfrom
fix/meter-delete

Conversation

@chrisgacsal

@chrisgacsal chrisgacsal commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Overview

Fix validation of active entitlements for meter delete where wrong boundary check prevented meter delete even if the entitlements referencing the meter via it feature were not considered "active" anymore.

Summary by CodeRabbit

  • Bug Fixes
    • Meter deletion checks now consider only active, non-deleted entitlements.
    • Expired, future-scheduled, deleted, or customer-deleted entitlements no longer incorrectly prevent meter deletion.

Greptile Summary

The PR corrects meter-deletion validation so only currently active entitlements belonging to non-deleted customers block deletion.

  • Adds canonical active-window and soft-deletion predicates to the entitlement lookup.
  • Adds coverage for active, expired, scheduled, deleted-entitlement, and deleted-customer cases.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains; the previously reported deleted-customer case is excluded by the new customer-edge predicate, which matches the canonical entitlement lifecycle query.

Important Files Changed

Filename Overview
openmeter/meter/adapter/manage.go Aligns the meter deletion guard with canonical entitlement and customer lifecycle predicates, resolving the previously reported deleted-customer issue.
openmeter/meter/adapter/adapter_test.go Adds focused lifecycle-state coverage for the entitlement check used by meter deletion.

Reviews (2): Last reviewed commit: "fix: include customer lookup" | Re-trigger Greptile

@chrisgacsal chrisgacsal self-assigned this Aug 3, 2026
@chrisgacsal
chrisgacsal requested a review from a team as a code owner August 3, 2026 07:52
@chrisgacsal chrisgacsal added the release-note/bug-fix Release note: Bug Fixes label Aug 3, 2026
tothandras
tothandras previously approved these changes Aug 3, 2026
Comment thread openmeter/meter/adapter/manage.go
@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

HasEntitlementForMeter now checks entitlement lifecycle state and customer deletion state. A table-driven integration test covers active, ended, future, deleted-customer, and deleted-entitlement cases.

Changes

Entitlement filtering

Layer / File(s) Summary
Filter entitlements by lifecycle state
openmeter/meter/adapter/manage.go
HasEntitlementForMeter reuses one timestamp and filters entitlements by deletion status, activation, expiration, namespace, meter relationship, and customer deletion status.
Validate entitlement lifecycle behavior
openmeter/meter/adapter/adapter_test.go
A frozen-time integration test verifies blocking for active entitlements and non-blocking behavior for ended, future, deleted-customer, and deleted-entitlement cases.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: galexihu, gergely-kurucz-konghq

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Title check ✅ Passed The title clearly and concisely describes the fix to active entitlement validation that affects meter deletion.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/meter-delete

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

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@openmeter/meter/adapter/adapter_test.go`:
- Around line 149-155: The entitlement deletion test fixture around
HasEntitlementForMeter currently exercises Customer.DeletedAt and an expired
ActiveTo, not Entitlement.DeletedAt. Add a separate otherwise-active entitlement
case with Entitlement.DeletedAt set to now and expect no entitlement, while
keeping the existing expired-entitlement scenario independent.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: e2e74c6f-a839-4263-bd14-226c525828e9

📥 Commits

Reviewing files that changed from the base of the PR and between d74dfce and 44556ed.

📒 Files selected for processing (2)
  • openmeter/meter/adapter/adapter_test.go
  • openmeter/meter/adapter/manage.go

Comment thread openmeter/meter/adapter/adapter_test.go

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
openmeter/meter/adapter/manage.go (1)

152-165: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

Add an isolated customer-deletion test.

The supplied test case at openmeter/meter/adapter/adapter_test.go:127-214 combines an ended entitlement with a deleted customer. It can pass because of the expiration filter even if HasCustomerWith is removed. Add an active, non-ended entitlement for a deleted customer and assert false. Keep a separate ended-entitlement case to verify both predicates independently.

Suggested test adjustment
-			name:            "ended entitlement for deleted customer",
+			name:       "ended entitlement",
 			activeFrom:      now.Add(-2 * time.Hour),
 			activeTo:        lo.ToPtr(now.Add(-time.Hour)),
-			customerDeleted: true,
 			want:            false,
 		},
+		{
+			name:            "active entitlement for deleted customer",
+			activeFrom:      now.Add(-time.Hour),
+			customerDeleted: true,
+			want:            false,
+		},
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@openmeter/meter/adapter/manage.go` around lines 152 - 165, Add an isolated
case in the entitlement query tests around the existing adapter test setup:
create an active, non-ended entitlement linked to a deleted customer and assert
the lookup returns false, ensuring this result depends on HasCustomerWith.
Retain a separate ended-entitlement case so expiration filtering and customer
deletion are verified independently.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@openmeter/meter/adapter/manage.go`:
- Around line 152-165: Add an isolated case in the entitlement query tests
around the existing adapter test setup: create an active, non-ended entitlement
linked to a deleted customer and assert the lookup returns false, ensuring this
result depends on HasCustomerWith. Retain a separate ended-entitlement case so
expiration filtering and customer deletion are verified independently.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 4cc61fed-eeca-4cf2-973a-aba6193d0bde

📥 Commits

Reviewing files that changed from the base of the PR and between 44556ed and c515373.

📒 Files selected for processing (2)
  • openmeter/meter/adapter/adapter_test.go
  • openmeter/meter/adapter/manage.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • openmeter/meter/adapter/adapter_test.go

@chrisgacsal
chrisgacsal requested a review from tothandras August 3, 2026 08:34
@chrisgacsal
chrisgacsal merged commit b079b6c into main Aug 3, 2026
27 checks passed
@chrisgacsal
chrisgacsal deleted the fix/meter-delete branch August 3, 2026 08:48
@coderabbitai coderabbitai Bot mentioned this pull request Aug 3, 2026
mark-vass-konghq added a commit that referenced this pull request Aug 3, 2026
fix: active entitlement validation blocking meter delete (#4835)

Co-authored-by: Robert Borbely <robert.borbely@konghq.com>

fix: meter delete in tx (#4838)

Co-authored-by: Alex Goth <64845621+GAlexIHU@users.noreply.github.com>
mark-vass-konghq added a commit that referenced this pull request Aug 3, 2026
fix: active entitlement validation blocking meter delete (#4835)

Co-authored-by: Robert Borbely <robert.borbely@konghq.com>

fix: meter delete in tx (#4838)

Co-authored-by: Alex Goth <64845621+GAlexIHU@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/bug-fix Release note: Bug Fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants