Conversation
Signed-off-by: zyguan <zhongyangguan@gmail.com>
📝 WalkthroughWalkthroughThese changes introduce worker activity tracking to the thread pool via a new Changes
Sequence DiagramsequenceDiagram
participant Pool as Thread Pool
participant Worker as Worker Thread
participant Local as Local<T>
participant Activity as WorkerActivity
participant Metric as Prometheus Counter
Pool->>Worker: Spawn worker thread
Worker->>Local: Initialize with activity field
Worker->>Local: on_worker_start()
Local->>Activity: Record start time
Activity->>Metric: Begin tracking (if enabled)
loop For Each Task
Worker->>Local: Execute task
Local->>Activity: Monitor execution
Worker->>Local: on_task_complete()
Local->>Activity: Check elapsed time
alt Periodic checkpoint triggered
Activity->>Activity: Flush accumulated time
Activity->>Metric: Update counter with active seconds
end
end
Worker->>Local: Drain remaining futures
Worker->>Local: on_worker_end()
Local->>Activity: Final flush
Activity->>Metric: Commit final active seconds
Local->>Local: Clear activity state
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 🧹 Recent nitpick comments
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. 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. Comment |
There was a problem hiding this comment.
Pull request overview
Adds a new Prometheus counter metric to track how long worker threads are “active” (i.e., not parked), enabling better visibility into thread-pool utilization.
Changes:
- Introduces
yatp_worker_active_seconds_total(WORKER_ACTIVE_SECONDS) labeled by pool name. - Tracks worker active time via per-worker local counters and flushes on park/end (with periodic checkpoints while busy).
- Adds a unit test validating the metric is incremented.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
src/metrics.rs |
Defines the new WORKER_ACTIVE_SECONDS CounterVec metric. |
src/pool/builder.rs |
Wires a per-pool labeled counter into each worker via LocalCounter. |
src/pool/spawn.rs |
Implements WorkerActivity tracking and hooks into park/unpark and worker lifecycle. |
src/pool/worker.rs |
Calls lifecycle hooks (on_worker_start, on_task_complete, on_worker_end) from the worker loop. |
src/pool/tests.rs |
Adds a test ensuring the active-seconds metric increases after running work. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Adds a new Prometheus metric
yatp_worker_active_seconds_totalto observe how much time worker threads spend being active.Summary by CodeRabbit
New Features
Tests