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)


74
75
76
77
78
79
80
# File 'lib/karafka/web/pro/ui/controllers/topics/distributions_controller.rb', line 74

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



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/karafka/web/pro/ui/controllers/topics/distributions_controller.rb', line 56

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)


83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/karafka/web/pro/ui/controllers/topics/distributions_controller.rb', line 83

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, 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