Class: Journaled::Outbox::MetricEmitter

Inherits:
Object
  • Object
show all
Defined in:
lib/journaled/outbox/metric_emitter.rb

Overview

Handles metric emission for the Worker and Kinesis senders

This class provides utility methods for collecting and emitting metrics.

Class Method Summary collapse

Class Method Details

.emit_batch_metrics(stats, worker_id:) ⇒ Object

Emit batch processing metrics



14
15
16
17
18
19
20
21
# File 'lib/journaled/outbox/metric_emitter.rb', line 14

def emit_batch_metrics(stats, worker_id:)
  total_events = stats[:succeeded] + stats[:failed_permanently] + stats[:failed_transiently]

  emit_metric('journaled.outbox_event.processed', value: total_events, worker_id:)
  emit_metric('journaled.outbox_event.sent', value: stats[:succeeded], worker_id:)
  emit_metric('journaled.outbox_event.failed', value: stats[:failed_permanently], worker_id:)
  emit_metric('journaled.outbox_event.errored', value: stats[:failed_transiently], worker_id:)
end

.emit_kinesis_failure(event:, error_code:) ⇒ Object

Emit a metric notification for a Kinesis send failure



47
48
49
50
51
52
53
54
55
# File 'lib/journaled/outbox/metric_emitter.rb', line 47

def emit_kinesis_failure(event:, error_code:)
  emit_metric(
    'journaled.kinesis.send_failure',
    partition_key: event.partition_key,
    error_code:,
    stream_name: event.stream_name,
    event_type: event.event_type,
  )
end

.emit_queue_metrics(worker_id:) ⇒ Object

Collect and emit queue metrics

This calculates various queue statistics and emits individual metrics for each.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/journaled/outbox/metric_emitter.rb', line 27

def emit_queue_metrics(worker_id:)
  metrics = calculate_queue_metrics

  emit_metric('journaled.worker.queue_total_count', value: metrics[:total_count], worker_id:)
  emit_metric('journaled.worker.queue_workable_count', value: metrics[:workable_count], worker_id:)
  emit_metric('journaled.worker.queue_failed_count', value: metrics[:failed_count], worker_id:)
  emit_metric('journaled.worker.queue_oldest_age_seconds', value: metrics[:oldest_age_seconds], worker_id:)

  Rails.logger.info(
    "Queue metrics: total=#{metrics[:total_count]}, " \
    "workable=#{metrics[:workable_count]}, " \
    "failed=#{metrics[:failed_count]}, " \
    "oldest_age=#{metrics[:oldest_age_seconds].round(2)}s",
  )
end