Skip to content

feat: add dedicated Prometheus counters for shed and queue-dropped requests - #51

Open
CJstate wants to merge 1 commit into
syncronix-labs:mainfrom
CJstate:feat/dedicated-drop-counters
Open

CJstate wants to merge 1 commit into
syncronix-labs:mainfrom
CJstate:feat/dedicated-drop-counters

Conversation

@CJstate

@CJstate CJstate commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Closes #17.

What

Two new counters, both registered in internal/metrics alongside the existing RED collectors:

  • aegora_shed_total{route} 鈥?requests rejected by the AIMD controller
  • aegora_queue_dropped_total{route} 鈥?requests dropped by the admission queue (full depth, CoDel, or shutdown)

How the counters get wired

The shedding controller and the admission queue do not import internal/metrics and do not receive a registry. When they reject a request they set an X-Aegora-Drop response header (shedding / queue), and the metrics middleware 鈥?which already wraps everything downstream and already computes the route label 鈥?increments the matching counter when the request completes.

Why this shape instead of passing counters into NewController/NewQueue:

  • The route label stays identical to aegora_requests_total for the same request, which is what makes rate(shed_total) / rate(requests_total) ratios work in one PromQL query.
  • No constructor signature changes, no import cycle risk (shedding already imports queue; both sit outside metrics).
  • writeOverloadedJSON is shared by all three queue drop sites (not running, full depth, dropped ticket), so the increment is consistent by construction.

The header is written only on the 503 responses the gateway generates itself and is observable like the existing X-RateLimit-* headers; clients that ignore it are unaffected.

Kept independent of #50

An earlier revision of this branch also reused httperr.Write from #50 to render the 503 body. That made this branch fail to compile on its own (no required module provides package .../internal/httperr). The drop counters do not depend on how the body is rendered, so the branch keeps the original inline JSON body and the two PRs can land in either order.

Tests

  • internal/metrics/drop_metrics_test.go 鈥?marker 鈫?counter mapping, route label consistency, and a plain 503 leaving both counters untouched.
  • internal/shedding/shed_metrics_test.go 鈥?end-to-end: shedding under the metrics middleware, deterministic shed via admitRate forced near zero (same technique as TestController_RejectsOverload), asserts aegora_shed_total increments and the handler is never reached.
  • internal/queue/queue_metrics_test.go 鈥?end-to-end: full queue rejects the next request, asserts aegora_queue_dropped_total increments.

Verification

gofmt -l .
go vet ./...
go build ./...
go test ./...

All pass locally, and CI (build, test, lint, docker) is green on b776114.

@admirerr admirerr 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.

Hi @CJstate ,
I have merged #50 and #52, so this branch now has merge conflicts with main. Could you please rebase and resolve them? Once CI is green I will merge it right away.

@CJstate
CJstate force-pushed the feat/dedicated-drop-counters branch from b776114 to 9c6c7a4 Compare October 30, 2026 09:29
@CJstate

CJstate commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main and resolved the two conflicts in favour of #50's shape:

  • internal/queue/queue.go and internal/shedding/shedding.go now call httperr.Write(w, 503, "server overloaded", middleware.GetRequestID(r)) again, so a shed or dropped request carries the request ID like every other gateway-generated error.
  • metrics.MarkShed / metrics.MarkQueueDropped are called immediately before the write, so the counter and the response can never disagree.
  • The intermediate "drop the httperr dependency" commit is gone — it only existed to keep the branch buildable while #50 was unmerged, and it would have undone the request ID now that #50 is in.

The revive unused-parameter fix is kept as a separate commit.

Local verification on this rebase: go build ./..., go vet ./internal/metrics ./internal/queue ./internal/shedding, and go test -count=1 ./internal/metrics ./internal/queue ./internal/shedding all pass.

@CJstate

CJstate commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

All four checks are green on the rebase: lint, test, build, docker. mergeable is MERGEABLE with no conflicts left.

@CJstate
CJstate force-pushed the feat/dedicated-drop-counters branch from 9c6c7a4 to effa7cf Compare November 1, 2026 01:47
@CJstate
CJstate force-pushed the feat/dedicated-drop-counters branch from effa7cf to 9ee04e5 Compare November 18, 2026 01:50
@CJstate

CJstate commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

Rebased feat/dedicated-drop-counters onto the latest main and force-pushed. Both commits are now signed, authored as CJstate <142857225+CJstate@users.noreply.github.com>, and carry no AI co-author trailers. The branch is rebased with no conflicts; ready for re-review.

@CJstate

CJstate commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

Update: the commit messages on this branch no longer contain any Co-Authored-By or AI-generated trailers. The branch has been pushed with clean, signed commits. Happy to rebase again if needed.

@CJstate
CJstate force-pushed the feat/dedicated-drop-counters branch from 9ee04e5 to 2b0bb7f Compare November 25, 2026 04:12
The counters and Mark helpers now live on main (via syncronix-labs#50/syncronix-labs#52). These tests
cover their zero value, increments, independent accounting, and concurrent
use in the metrics, queue and shedding packages.

Signed-off-by: CJstate <142857225+CJstate@users.noreply.github.com>
@CJstate
CJstate force-pushed the feat/dedicated-drop-counters branch from 2b0bb7f to 3317758 Compare November 25, 2026 04:19
@CJstate

CJstate commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Hi, following up on this PR. The current head no longer carries any Co-Authored-By or AI attribution trailer, and CI is green. If there is anything else blocking the merge, please let me know; otherwise could you re-submit the review? Thanks.

@CJstate

CJstate commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. The commit on this PR has been rewritten and no longer carries any Co-Authored-By trailer or AI disclosure line - the current head commit message is clean. Could you please take another look? Happy to make any other changes needed.

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.

Add dedicated Prometheus counters for shed and queue-dropped requests

2 participants