Skip to content

fix(balanceworker): skip events that dont match meters#4279

Merged
GAlexIHU merged 2 commits into
mainfrom
fix/entitlement-recalc
May 4, 2026
Merged

fix(balanceworker): skip events that dont match meters#4279
GAlexIHU merged 2 commits into
mainfrom
fix/entitlement-recalc

Conversation

@GAlexIHU
Copy link
Copy Markdown
Contributor

@GAlexIHU GAlexIHU commented May 4, 2026

Overview

Events can be ingested that don't match any meters

Summary by CodeRabbit

  • Bug Fixes
    • Improved batch ingest efficiency: when a batched ingest event contains no meter identifiers, the system logs this and skips the lookup and entitlement recalculation steps, avoiding unnecessary work and reducing processing overhead.

@GAlexIHU GAlexIHU requested a review from a team as a code owner May 4, 2026 10:38
@GAlexIHU GAlexIHU added the release-note/bug-fix Release note: Bug Fixes label May 4, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 4, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0656fba9-bab1-4f66-8573-ba00655bd3a1

📥 Commits

Reviewing files that changed from the base of the PR and between 3432330 and ec1c5e8.

📒 Files selected for processing (1)
  • openmeter/entitlement/balanceworker/ingesthandler.go

📝 Walkthrough

Walkthrough

Added an early-return guard in handleBatchedIngestEvent: if event.MeterSlugs is empty the function logs an info and returns nil immediately, skipping entitlement lookups and any entitlement-recalculation publishing.

Changes

Early Return Guard for Empty Meter Slugs

Layer / File(s) Summary
Guard Clause
openmeter/entitlement/balanceworker/ingesthandler.go
handleBatchedIngestEvent now checks event.MeterSlugs at the start and returns nil early with an info log when it's empty, preventing downstream entitlement queries and publish logic from running.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding logic to skip events without matching meters in the balance worker.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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/entitlement-recalc

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
Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.

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

@GAlexIHU GAlexIHU enabled auto-merge (squash) May 4, 2026 10:39
tothandras
tothandras previously approved these changes May 4, 2026
Copy link
Copy Markdown
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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@openmeter/entitlement/balanceworker/ingesthandler.go`:
- Around line 21-25: The InfoContext log in the early-return branch currently
logs the entire event (event) which can include RawEvents; instead change the
log to trim the payload by logging only safe summary fields such as
event.Namespace, event.Subject (or subject identifier field), and the meter
count (len(event.MeterSlugs)); update the call to w.opts.Logger.InfoContext(ctx,
...) in the same block so it does not pass the full event object but these
minimal fields to avoid leaking raw payloads.
🪄 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

Run ID: cf392d18-b96e-476a-a8c6-1a3c00e08fac

📥 Commits

Reviewing files that changed from the base of the PR and between 3f41436 and 3432330.

📒 Files selected for processing (1)
  • openmeter/entitlement/balanceworker/ingesthandler.go

Comment thread openmeter/entitlement/balanceworker/ingesthandler.go
@GAlexIHU GAlexIHU dismissed stale reviews from gergely-kurucz-konghq and tothandras via ec1c5e8 May 4, 2026 10:48
@GAlexIHU GAlexIHU enabled auto-merge (squash) May 4, 2026 10:49
@GAlexIHU GAlexIHU merged commit 81a0f01 into main May 4, 2026
28 of 29 checks passed
@GAlexIHU GAlexIHU deleted the fix/entitlement-recalc branch May 4, 2026 10:55
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.

3 participants