Class: Karafka::Web::Processing::Consumers::Metrics

Inherits:
Object
  • Object
show all
Defined in:
lib/karafka/web/processing/consumers/metrics.rb

Overview

Fetches the current consumers historical metrics data

Class Method Summary collapse

Class Method Details

.current!Hash

Fetch the current metrics data that is expected to exist

Returns:

  • (Hash)

    latest (current) aggregated metrics state



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/karafka/web/processing/consumers/metrics.rb', line 13

def current!
  metrics_message = ::Karafka::Admin.read_topic(
    Karafka::Web.config.topics.consumers.metrics,
    0,
    # We need to take more in case there would be transactions running.
    # In theory we could take two but this compensates for any involuntary
    # revocations and cases where two producers would write to the same state
    5
  ).last

  return metrics_message.payload if metrics_message

  raise(::Karafka::Web::Errors::Processing::MissingConsumersMetricsError)
rescue Rdkafka::RdkafkaError => e
  raise(e) unless e.code == :unknown_partition

  raise(::Karafka::Web::Errors::Processing::MissingConsumersMetricsTopicError)
end