Skip to content

temporal-ruby: Emit accurate Ruby worker slot metrics - #4

Open
kstewartfigma wants to merge 3 commits into
masterfrom
kstewart/ruby-worker-slot-metrics
Open

kstewartfigma wants to merge 3 commits into
masterfrom
kstewart/ruby-worker-slot-metrics

Conversation

@kstewartfigma

@kstewartfigma kstewartfigma commented Aug 26, 2026 •

Copy link
Copy Markdown

Why

Ruby Temporal worker processes currently emit thread_pool.available_threads into the same DogStatsD metric context. With multiple worker processes sharing a pod or host, the last gauge write wins, so the metric does not represent fleet slot saturation.

What changed

  • preserve the existing thread_pool.available_threads metric for compatibility
  • add Temporal-standard worker_task_slots_available and worker_task_slots_used gauges
  • tag the new gauges with namespace, task_queue, worker_type, and a unique worker_id so concurrent processes cannot overwrite one another
  • report an initial snapshot and refresh it every 10 seconds, including while idle
  • stop the reporter before enqueueing shutdown sentinels so shutdown does not appear as real slot use

Validation

November 17 refresh:

  • Full unit suite: 652 examples, 0 failures; the optional official-SDK case is covered separately (2 examples, 0 failures).
  • Added regression coverage for shutdown before the reporter starts and for two worker pools sharing a custom connection identity. Each regression fails against the original implementation.
  • Fixed the shutdown lost wakeup and made worker IDs unique per memoized pool without changing connection identity.
  • The refreshed GitHub Actions workflow runs Ruby 3.4, unit/coexistence coverage, and legacy/conflict-policy server examples. Current-head results are visible in the PR checks.
  • Fresh-context independent reviews using gpt-6.1-sol at high effort found the shutdown race and confirmed both corrections. Live DogStatsD aggregation and production rollout were not exercised.

@kstewartfigma
kstewartfigma marked this pull request as ready for review November 17, 2026 23:48
@kstewartfigma kstewartfigma changed the title temporal: Emit accurate Ruby worker slot metrics temporal-ruby: Emit accurate Ruby worker slot metrics Nov 17, 2026
@kstewartfigma
kstewartfigma requested review from a team and ebarajas and removed request for a team November 17, 2026 23:48

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

Stale Bugbot comment from a previous run.

Comment thread lib/temporal/thread_pool.rb Resolved

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit c381a0f. Configure here.

Comment thread lib/temporal/activity/poller.rb Resolved

@yfang-figma yfang-figma 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.

Since we only run 1 thread per worker process, I am wondering if we really need these metrics, and whether we can just live with the worker utilization and the current_activity/workflow metrics?

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants