Class: Karafka::Web::Pro::Ui::Controllers::Topics::DistributionsController

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

Overview

Controller responsible for checking the data distribution in topics

Constant Summary

Constants inherited from Ui::Controllers::BaseController

Ui::Controllers::BaseController::Models

Instance Attribute Summary

Attributes inherited from Ui::Controllers::BaseController

#params, #session

Instance Method Summary collapse

Methods inherited from Ui::Controllers::BaseController

#cache, #initialize

Methods included from Ui::Controllers::Requests::Hookable

included, #run_after_hooks, #run_before_hooks

Constructor Details

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

Instance Method Details

#edit(topic_name) ⇒ Object

Parameters:

  • topic_name (String)


49
50
51
52
53
54
55
# File 'lib/karafka/web/pro/ui/controllers/topics/distributions_controller.rb', line 49

def edit(topic_name)
  features.topics_management!

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

  render
end

#show(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



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/karafka/web/pro/ui/controllers/topics/distributions_controller.rb', line 31

def show(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

#update(topic_name) ⇒ Object

Parameters:

  • topic_name (String)


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/karafka/web/pro/ui/controllers/topics/distributions_controller.rb', line 58

def update(topic_name)
  edit(topic_name)

  partition_count = params.int(:partition_count)

  begin
    Karafka::Admin.create_partitions(
      topic_name,
      partition_count
    )
  rescue Rdkafka::RdkafkaError => e
    @form_error = e
  rescue Rdkafka::Config::ConfigError => e
    @form_error = e
  end

  return edit(topic_name) if @form_error

  redirect(
    "topics/#{topic_name}/distribution",
    success: format_flash(
      'Topic ? repartitioning to ? partitions successfully started',
      topic_name,
      partition_count
    )
  )
end