Skip to content

Commit

Permalink
feat(prometheus): add postal_message_queue_latency metric
Browse files Browse the repository at this point in the history
  • Loading branch information
adamcooke committed Mar 17, 2024
1 parent 4fcb9e9 commit ee8d829
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/lib/message_dequeuer/initial_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
module MessageDequeuer
class InitialProcessor < Base

include HasPrometheusMetrics

attr_accessor :send_result

def process
logger.tagged(original_queued_message: @queued_message.id) do
logger.info "starting message unqueue"
begin
catch_stops do
increment_dequeue_metric
check_message_exists
check_message_is_ready
find_other_messages_for_batch
Expand All @@ -28,6 +31,13 @@ def process

private

def increment_dequeue_metric
time_in_queue = Time.now.to_f - @queued_message.created_at.to_f
log "queue latency is #{time_in_queue}s"
observe_prometheus_histogram :postal_message_queue_latency,
time_in_queue
end

def check_message_exists
return if @queued_message.message

Expand Down
3 changes: 3 additions & 0 deletions app/lib/worker/process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ def setup_prometheus
register_prometheus_histogram :postal_worker_task_runtime,
docstring: "The time taken to process tasks",
labels: [:task]

register_prometheus_histogram :postal_message_queue_latency,
docstring: "The length of time between a message being queued and being dequeued"
end

end
Expand Down

0 comments on commit ee8d829

Please sign in to comment.