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

.fetch(cached: true) ⇒ Rdkafka::Metadata

Gets us all the cluster metadata info

Parameters:

  • cached (Boolean) (defaults to: true)

    should we use cached data (true by default)

Returns:

  • (Rdkafka::Metadata)

    cluster metadata info



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/karafka/web/ui/models/cluster_info.rb', line 15

def fetch(cached: true)
  cache = ::Karafka::Web.config.ui.cache

  cluster_info = cache.read(:cluster_info)

  if cluster_info.nil? || !cached
    cluster_info = cache.write(:cluster_info, Lib::Admin.cluster_info)
  end

  cluster_info
end

.partitions_count(topic_name, cached: true) ⇒ Integer

Returns number of partitions in a given topic.

Parameters:

  • topic_name (String)

    name of the topic we are looking for

  • cached (Boolean) (defaults to: true)

    should we use cached data (true by default)

Returns:

  • (Integer)

    number of partitions in a given topic



51
52
53
# File 'lib/karafka/web/ui/models/cluster_info.rb', line 51

def partitions_count(topic_name, cached: true)
  topic(topic_name, cached: cached).partition_count
end

.topic(topic_name, cached: true) ⇒ Ui::Models::Topic

Fetches us details about particular topic

Parameters:

  • topic_name (String)

    name of the topic we are looking for

  • cached (Boolean) (defaults to: true)

    should we use cached data (true by default)

Returns:



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

def topic(topic_name, cached: true)
  topics(cached: cached)
    .find { |topic_data| topic_data.topic_name == topic_name }
    .tap { |topic| topic || raise(Web::Errors::Ui::NotFoundError, topic_name) }
end

.topics(cached: true) ⇒ Array<Ui::Models::Topic>

Returns us all the info about available topics from the cluster

Parameters:

  • cached (Boolean) (defaults to: true)

    should we use cached data (true by default)

Returns:



31
32
33
34
35
# File 'lib/karafka/web/ui/models/cluster_info.rb', line 31

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