Class: Karafka::Web::Pro::Ui::Controllers::TopicsController

Inherits:
BaseController show all
Defined in:
lib/karafka/web/pro/ui/controllers/topics_controller.rb

Overview

Topics management controller Allows for exploration of settings and replication details

Constant Summary

Constants inherited from Ui::Controllers::BaseController

Ui::Controllers::BaseController::Models

Instance Method Summary collapse

Methods inherited from Ui::Controllers::BaseController

#initialize

Constructor Details

This class inherits a constructor from Karafka::Web::Ui::Controllers::BaseController

Instance Method Details

#config(topic_name) ⇒ Object

Displays requested topic config details

Parameters:

  • topic_name (String)

    topic we’re interested in



54
55
56
57
58
59
60
# File 'lib/karafka/web/pro/ui/controllers/topics_controller.rb', line 54

def config(topic_name)
  @topic = Models::Topic.find(topic_name)

  @configs = refine(@topic.configs)

  render
end

#distribution(topic_name) ⇒ Object

Note:

Because computing distribution is fairly expensive, we paginate this. While because of that results may not be exact, this allows us to support topics with many partitions.

Displays the messages distribution across various partitions

Parameters:

  • topic_name (String)

    topic we’re interested in



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/karafka/web/pro/ui/controllers/topics_controller.rb', line 80

def distribution(topic_name)
  @topic = Models::Topic.find(topic_name)

  @active_partitions, _materialized_page, @limited = Paginators::Partitions.call(
    @topic.partition_count, @params.current_page
  )

  @aggregated, distribution = @topic.distribution(@active_partitions)

  @distribution = refine(distribution)

  next_page = @active_partitions.last < @topic.partition_count - 1
  paginate(@params.current_page, next_page)

  render
end

#indexObject

Lists available topics in the cluster



41
42
43
44
45
46
47
48
49
# File 'lib/karafka/web/pro/ui/controllers/topics_controller.rb', line 41

def index
  @topics = Models::Topic.all.sort_by(&:topic_name)

  unless ::Karafka::Web.config.ui.visibility.internal_topics
    @topics.delete_if { |topic| topic[:topic_name].start_with?('__') }
  end

  render
end

#offsets(topic_name) ⇒ Object

Displays high and low offsets for given topic

Parameters:

  • topic_name (String)

    topic we’re interested in



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/karafka/web/pro/ui/controllers/topics_controller.rb', line 100

def offsets(topic_name)
  @topic = Models::Topic.find(topic_name)

  @active_partitions, _materialized_page, @limited = Paginators::Partitions.call(
    @topic.partition_count, @params.current_page
  )

  offsets = @active_partitions.map do |partition_id|
    part_offsets = Admin.read_watermark_offsets(topic_name, partition_id)

    {
      partition_id: partition_id,
      low: part_offsets.first,
      high: part_offsets.last,
      diff: part_offsets.last - part_offsets.first
    }
  end

  @offsets = refine(offsets)

  next_page = @active_partitions.last < @topic.partition_count - 1
  paginate(@params.current_page, next_page)

  render
end

#replication(topic_name) ⇒ Object

Displays requested topic replication details

Parameters:

  • topic_name (String)

    topic we’re interested in



65
66
67
68
69
70
71
# File 'lib/karafka/web/pro/ui/controllers/topics_controller.rb', line 65

def replication(topic_name)
  @topic = Models::Topic.find(topic_name)

  @partitions = refine(@topic[:partitions])

  render
end