Skip to content

fix(bidengine): increment reservation counter metrics#409

Open
neyy91 wants to merge 1 commit into
akash-network:mainfrom
neyy91:fix/reservation-counter-inc
Open

fix(bidengine): increment reservation counter metrics#409
neyy91 wants to merge 1 commit into
akash-network:mainfrom
neyy91:fix/reservation-counter-inc

Conversation

@neyy91

@neyy91 neyy91 commented Jun 21, 2026

Copy link
Copy Markdown

What

Four reservationCounter.WithLabelValues(...) calls in bidengine/order.go were missing a terminal .Inc(), so the returned counter was discarded and the metric was never recorded.

Why

Every other counter in this file (orderCompleteCounter, shouldBidCounter, bidCounter) calls .Inc(); these four (reservation open/close × success/fail) were the exception. As a result the reservation metrics stayed flat at zero, so operators had no visibility into reservation success/failure rates.

Testing

Added Test_ReservationCounterIncrements: runs a full reserve + unreserve cycle and asserts the open-success and close-success counters each advance by one. Fails without the .Inc() calls. (go mod tidy registered prometheus/.../testutil's indirect dep kylelemons/godebug; go.sum unchanged.)

The reservation success/fail counters called WithLabelValues without a
terminal .Inc(), so the returned counter was discarded and the metric
was never recorded. Every other counter in this file calls .Inc(); these
four were the exception, leaving reservation open/close metrics flat.
@neyy91 neyy91 requested a review from a team as a code owner June 21, 2026 19:08
@coderabbitai

coderabbitai Bot commented Jun 21, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

Three missing .Inc() calls on labeled reservationCounter Prometheus counters are added in bidengine/order.go: on reservation failure, on unreserve error, and on unreserve success. A new test Test_ReservationCounterIncrements verifies both open-success and close-success counters each increment by 1 through a full reserve/unreserve cycle. An indirect dependency github.com/kylelemons/godebug v1.1.0 is added.

Changes

Reservation Metrics Fix

Layer / File(s) Summary
Add missing .Inc() to reservationCounter paths
bidengine/order.go
Adds .Inc() to the labeled reservationCounter in the clusterch result handler on reservation failure (open/fail path) and in both the error and success branches of the unreserve cleanup block (close/fail and close/success paths).
Counter increment test and indirect dependency
bidengine/order_metrics_test.go, go.mod
Adds Test_ReservationCounterIncrements, which snapshots open-success and close-success counter values, drives a reserve then shutdown/unreserve workflow via makeOrderForTest, asserts Reserve/Unreserve mock calls, and checks each counter incremented by exactly 1. Adds github.com/kylelemons/godebug v1.1.0 as an indirect dependency.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐇 Hop hop, the counter missed its call,
.Inc() was absent, no tally at all!
Now failure and close both bump up the score,
Prometheus sees what it couldn't before.
The rabbit checks metrics — they're right, hip hooray! 🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding missing .Inc() calls to fix reservation counter metrics in bidengine.
Description check ✅ Passed The description clearly explains what was fixed, why it matters, and how it was tested, all directly related to the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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 unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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 `@bidengine/order_metrics_test.go`:
- Line 34: The Unreserve method in the cluster interface takes only one argument
(orderID), but the AssertCalled assertion on the scaffold.cluster mock is
passing two arguments: scaffold.orderID and mock.Anything. Remove the
mock.Anything argument from the AssertCalled invocation so that it only includes
the method name "Unreserve" and the single expected argument scaffold.orderID,
matching the actual method signature.
🪄 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: 492025d5-4d1f-4a79-9dab-c18d8b42efab

📥 Commits

Reviewing files that changed from the base of the PR and between 0e0fd8a and fa0386a.

📒 Files selected for processing (3)
  • bidengine/order.go
  • bidengine/order_metrics_test.go
  • go.mod


// Shutting down triggers the unreserve path.
order.lc.Shutdown(nil)
scaffold.cluster.AssertCalled(t, "Unreserve", scaffold.orderID, mock.Anything)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Run the new metrics test to verify it detects the assertion mismatch

cd bidengine
go test -v -run Test_ReservationCounterIncrements

Repository: akash-network/provider

Length of output: 152


🏁 Script executed:

# Find and examine the cluster service interface to verify Unreserve signature
fd -t f service.go | grep cluster | head -5

Repository: akash-network/provider

Length of output: 117


🏁 Script executed:

# Search for Unreserve method signature
rg "Unreserve" -A 2 -B 2 --type-list

Repository: akash-network/provider

Length of output: 456


🏁 Script executed:

# Examine the test file at line 34 specifically
fd -t f order_metrics_test.go -x wc -l {}

Repository: akash-network/provider

Length of output: 103


🏁 Script executed:

# Search for Unreserve method definition in cluster service
rg "Unreserve" -A 1 cluster/service.go

Repository: akash-network/provider

Length of output: 296


🏁 Script executed:

# Examine the test file around line 34 to see the exact assertion
cat -n bidengine/order_metrics_test.go | sed -n '30,40p'

Repository: akash-network/provider

Length of output: 603


🏁 Script executed:

# Check the actual call to Unreserve in order.go around line 481
rg "Unreserve" -B 2 -A 2 bidengine/order.go | head -20

Repository: akash-network/provider

Length of output: 343


Remove extraneous mock.Anything argument from Unreserve assertion.

The Unreserve method takes only one argument (orderID), but this assertion expects two arguments. According to the cluster interface signature (cluster/service.go), Unreserve(mtypes.OrderID) error has a single parameter, and the production call site in order.go invokes it as o.cluster.Unreserve(reservation.OrderID()). The extra mock.Anything will cause this assertion to fail.

🔧 Proposed fix
-	scaffold.cluster.AssertCalled(t, "Unreserve", scaffold.orderID, mock.Anything)
+	scaffold.cluster.AssertCalled(t, "Unreserve", scaffold.orderID)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
scaffold.cluster.AssertCalled(t, "Unreserve", scaffold.orderID, mock.Anything)
scaffold.cluster.AssertCalled(t, "Unreserve", scaffold.orderID)
🤖 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 `@bidengine/order_metrics_test.go` at line 34, The Unreserve method in the
cluster interface takes only one argument (orderID), but the AssertCalled
assertion on the scaffold.cluster mock is passing two arguments:
scaffold.orderID and mock.Anything. Remove the mock.Anything argument from the
AssertCalled invocation so that it only includes the method name "Unreserve" and
the single expected argument scaffold.orderID, matching the actual method
signature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant