Class: Conductor::Worker::Telemetry::PrometheusBackend

Inherits:
Object
  • Object
show all
Defined in:
lib/conductor/worker/telemetry/prometheus_backend.rb

Overview

PrometheusBackend - Prometheus backend for the canonical SDK metric catalog.

Pre-registers every metric from the harmonization spec with its canonical label set and bucket configuration. Uses camelCase domain labels (taskType, workflowType) per the canonical convention.

Constant Summary collapse

TIME_BUCKETS =
[0.001, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10].freeze
SIZE_BUCKETS =
[100, 1000, 10_000, 100_000, 1_000_000, 10_000_000].freeze
COUNTER_LABELS =
{
  'task_poll_total' => %i[taskType],
  'task_execution_started_total' => %i[taskType],
  'task_poll_error_total' => %i[taskType exception],
  'task_execute_error_total' => %i[taskType exception],
  'task_update_error_total' => %i[taskType exception],
  'task_paused_total' => %i[taskType],
  'thread_uncaught_exceptions_total' => %i[exception],
  'workflow_start_error_total' => %i[workflowType exception]
}.freeze
HISTOGRAM_LABELS =
{
  'task_poll_time_seconds' => %i[taskType status],
  'task_execute_time_seconds' => %i[taskType status],
  'task_update_time_seconds' => %i[taskType status],
  'http_api_client_request_seconds' => %i[method uri status],
  'task_result_size_bytes' => %i[taskType],
  'workflow_input_size_bytes' => %i[workflowType version]
}.freeze
GAUGE_LABELS =
{
  'active_workers' => %i[taskType]
}.freeze
HISTOGRAM_BUCKETS =
{
  'task_result_size_bytes' => SIZE_BUCKETS,
  'workflow_input_size_bytes' => SIZE_BUCKETS
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(registry: nil) ⇒ PrometheusBackend

Returns a new instance of PrometheusBackend.



44
45
46
47
48
49
50
51
# File 'lib/conductor/worker/telemetry/prometheus_backend.rb', line 44

def initialize(registry: nil)
  load_prometheus_client
  @registry = registry || Prometheus::Client.registry
  @counters = {}
  @histograms = {}
  @gauges = {}
  setup_metrics
end

Instance Attribute Details

#registryObject (readonly)

Returns the value of attribute registry.



68
69
70
# File 'lib/conductor/worker/telemetry/prometheus_backend.rb', line 68

def registry
  @registry
end

Instance Method Details

#increment(name, labels: {}, value: 1) ⇒ Object



53
54
55
56
# File 'lib/conductor/worker/telemetry/prometheus_backend.rb', line 53

def increment(name, labels: {}, value: 1)
  metric = get_or_create_counter(name)
  metric.increment(labels: normalize_labels(name, labels, COUNTER_LABELS), by: value)
end

#observe(name, value, labels: {}) ⇒ Object



58
59
60
61
# File 'lib/conductor/worker/telemetry/prometheus_backend.rb', line 58

def observe(name, value, labels: {})
  metric = get_or_create_histogram(name)
  metric.observe(value, labels: normalize_labels(name, labels, HISTOGRAM_LABELS))
end

#set(name, value, labels: {}) ⇒ Object



63
64
65
66
# File 'lib/conductor/worker/telemetry/prometheus_backend.rb', line 63

def set(name, value, labels: {})
  metric = get_or_create_gauge(name)
  metric.set(value, labels: normalize_labels(name, labels, GAUGE_LABELS))
end