Skip to content

Conversation

@fahimfaisaal
Copy link
Member

@fahimfaisaal fahimfaisaal commented Jan 31, 2026

  • Added metrics state inside worker to track tasks
  • Included new method NumPending with worker to provide the number of pending tasks
  • Added Prometheus example to demonstrate how to integrate varmq

@coderabbitai
Copy link

coderabbitai bot commented Jan 31, 2026

Walkthrough

Adds a Metrics abstraction and wires per-job metrics (submitted, completed, successful, failed) across workers and queues; extends Worker with Metrics() and NumPending(); updates constructors to record success/failure; provides tests, a Prometheus example, and enables the race detector for tests.

Changes

Cohort / File(s) Summary
Metrics core
metrics.go, metrics_test.go
New exported Metrics interface and internal metrics implementation with atomic counters, increments, Reset, and concurrent-safety tests.
Worker surface & behavior
worker.go, main.go, worker_test.go, main_test.go
Add metrics Metrics field; implement Metrics() Metrics and NumPending() int on Worker; refactor constructors to capture worker instance and increment success/failure/completed metrics; add tests for NumPending and error-worker success.
Queue instrumentation
queue.go, persistent.go, persistent_priority.go, priority.go
Call q.w.Metrics().incSubmitted() after successful Enqueue (Add/AddAll) across queue variants to account submissions.
Examples & modules
examples/prometheus/main.go, examples/prometheus/go.mod
Add Prometheus example demonstrating metric registration and /metrics endpoint; new module file for the example with local replace.
Build/test
Makefile, go.mod
Enable -race flag in test target; bump github.com/stretchr/testify to v1.11.1.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Queue
    participant Worker
    participant Metrics
    participant JobProcessor

    Client->>Queue: Add(job)
    Queue->>Metrics: incSubmitted()
    Metrics->>Metrics: submitted++ 

    Queue->>Worker: notify / wake

    Worker->>JobProcessor: dequeue & execute
    JobProcessor->>JobProcessor: run job
    alt success
        JobProcessor->>Metrics: incSuccessful()
        Metrics->>Metrics: successful++
    else failure
        JobProcessor->>Metrics: incFailed()
        Metrics->>Metrics: failed++
    end
    JobProcessor->>Metrics: incCompleted()
    Metrics->>Metrics: completed++
    
    Client->>Worker: Metrics()
    Worker-->>Client: Metrics instance
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

🐰 I counted hops from queue to beeps and bells,
Submitted, done, and failed — where each counter dwells.
Workers hum softly, metrics shining bright,
Prometheus listens through day and night.
A rabbit's small cheer for observability delight!

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is incomplete relative to the template. It lacks the required sections (Type of Change, Changes Made, Testing, Performance Impact, Checklist, Related Issues) and instead provides only a brief bullet-point summary without structural organization. Fill in all required template sections: explicitly mark Type of Change as 'New feature', detail the specific changes made, confirm tests pass and describe new tests added, assess performance impact, and complete the checklist items. Include any related issue numbers.
Docstring Coverage ⚠️ Warning Docstring coverage is 53.85% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: implementing a metrics feature to track workers. It is concise, specific, and clearly summarizes the primary objective of the changeset.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/add-metrics

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.

@codecov
Copy link

codecov bot commented Jan 31, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@fahimfaisaal fahimfaisaal marked this pull request as ready for review February 1, 2026 04:54
…the worker interface, implementation, and usage.
@fahimfaisaal fahimfaisaal merged commit 2631f08 into main Feb 1, 2026
3 of 4 checks passed
@fahimfaisaal fahimfaisaal deleted the feat/add-metrics branch February 1, 2026 05:03
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.

2 participants