Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/temporal/activity/poller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ def poll_loop
Temporal.metrics.timing(Temporal::MetricKeys::ACTIVITY_POLLER_TIME_SINCE_LAST_POLL, time_diff_ms, metrics_tags)
Temporal.logger.debug("Polling activity task queue", { namespace: namespace, task_queue: task_queue })

poll_time = Time.now
task = poll_for_task
poll_time_diff_ms = ((Time.now - poll_time) * 1000).round
Temporal.metrics.timing(Temporal::MetricKeys::ACTIVITY_POLLER_POLL_LATENCY, poll_time_diff_ms, metrics_tags)

last_poll_time = Time.now

Temporal.metrics.increment(
Expand Down
2 changes: 2 additions & 0 deletions lib/temporal/metric_keys.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ module Temporal
module MetricKeys
ACTIVITY_POLLER_TIME_SINCE_LAST_POLL = 'activity_poller.time_since_last_poll'.freeze
ACTIVITY_POLLER_POLL_COMPLETED = 'activity_poller.poll_completed'.freeze
ACTIVITY_POLLER_POLL_LATENCY = 'activity_poller.poll_latency'.freeze
ACTIVITY_TASK_QUEUE_TIME = 'activity_task.queue_time'.freeze
ACTIVITY_TASK_LATENCY = 'activity_task.latency'.freeze

WORKFLOW_POLLER_TIME_SINCE_LAST_POLL = 'workflow_poller.time_since_last_poll'.freeze
WORKFLOW_POLLER_POLL_COMPLETED = 'workflow_poller.poll_completed'.freeze
WORKFLOW_POLLER_POLL_LATENCY = 'workflow_poller.poll_latency'.freeze
WORKFLOW_TASK_QUEUE_TIME = 'workflow_task.queue_time'.freeze
WORKFLOW_TASK_LATENCY = 'workflow_task.latency'.freeze
WORKFLOW_TASK_EXECUTION_FAILED = 'workflow_task.execution_failed'.freeze
Expand Down
4 changes: 4 additions & 0 deletions lib/temporal/workflow/poller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ def poll_loop
Temporal.metrics.timing(Temporal::MetricKeys::WORKFLOW_POLLER_TIME_SINCE_LAST_POLL, time_diff_ms, metrics_tags)
Temporal.logger.debug("Polling workflow task queue", { namespace: namespace, task_queue: task_queue })

poll_time = Time.now
task = poll_for_task
poll_time_diff_ms = ((Time.now - poll_time) * 1000).round
Temporal.metrics.timing(Temporal::MetricKeys::WORKFLOW_POLLER_POLL_LATENCY, poll_time_diff_ms, metrics_tags)

last_poll_time = Time.now

Temporal.metrics.increment(
Expand Down
14 changes: 14 additions & 0 deletions spec/unit/lib/temporal/activity/poller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,20 @@ def poll(task, times: 1)
.at_least(:twice)
end

it 'reports poll latency' do
poll(nil, times: 2)

expect(Temporal.metrics)
.to have_received(:timing)
.with(
Temporal::MetricKeys::ACTIVITY_POLLER_POLL_LATENCY,
an_instance_of(Integer),
namespace: namespace,
task_queue: task_queue
)
.at_least(:twice)
end

it 'reports polling completed with received_task false' do
poll(nil, times: 2)

Expand Down
14 changes: 14 additions & 0 deletions spec/unit/lib/temporal/workflow/poller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,20 @@ def poll(task, times: 1)
.at_least(2).times
end

it 'reports poll latency' do
poll(nil)

expect(Temporal.metrics)
.to have_received(:timing)
.with(
Temporal::MetricKeys::WORKFLOW_POLLER_POLL_LATENCY,
an_instance_of(Integer),
namespace: namespace,
task_queue: task_queue
)
.at_least(2).times
end

it 'reports polling completed with received_task false' do
poll(nil)

Expand Down