Class: Karafka::Web::Ui::Models::ClusterInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/karafka/web/ui/models/cluster_info.rb

Overview

Wraps around the Lib::Admin#cluster_info with caching and some additional aliases so we can reference relevant information easily

Class Method Summary collapse

Class Method Details

.fetchRdkafka::Metadata

Gets us all the cluster metadata info

Returns:

  • (Rdkafka::Metadata)

    cluster metadata info

[View source]

14
15
16
17
18
# File 'lib/karafka/web/ui/models/cluster_info.rb', line 14

def fetch
  Karafka::Web.config.ui.cache.fetch(:cluster_info) do
    Lib::Admin.cluster_info
  end
end

.partitions_count(topic_name) ⇒ Integer

Returns number of partitions in a given topic.

Parameters:

  • topic_name (String)

    name of the topic we are looking for

Returns:

  • (Integer)

    number of partitions in a given topic

[View source]

45
46
47
# File 'lib/karafka/web/ui/models/cluster_info.rb', line 45

def partitions_count(topic_name)
  topic(topic_name).partition_count
end

.topic(topic_name) ⇒ Ui::Models::Topic

Fetches us details about particular topic

Parameters:

  • topic_name (String)

    name of the topic we are looking for

Returns:

[View source]

33
34
35
36
37
38
39
40
41
# File 'lib/karafka/web/ui/models/cluster_info.rb', line 33

def topic(topic_name)
  Lib::Admin
    .topic_info(topic_name)
    .then { |topic| Topic.new(topic) }
rescue Rdkafka::RdkafkaError => e
  raise e unless e.code == :unknown_topic_or_part

  raise(Web::Errors::Ui::NotFoundError, topic_name)
end

.topicsArray<Ui::Models::Topic>

Returns us all the info about available topics from the cluster

Returns:

[View source]

23
24
25
26
27
# File 'lib/karafka/web/ui/models/cluster_info.rb', line 23

def topics
  fetch
    .topics
    .map { |topic| Topic.new(topic) }
end