Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use cluster data for default replication #106

Merged
merged 1 commit into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
- [Improvement] Introduce cookie based sessions management for future usage.
- [Improvement] Introduce config validation.
- [Improvement] Provide flash messages support.
- [Improvement] Use replication factor of two by default (if not overridden) for Web UI topics when there is more than one broker.
- [Fix] Return 402 status instead of 500 on Pro features that are not available in OSS.
- [Fix] Fix a case where errors would not be visible without Rails due to the `String#first` usage.
- [Fix] Fix a case where live-poll would be disabled but would still update data.
Expand Down
33 changes: 27 additions & 6 deletions lib/karafka/web/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,24 @@ class Cli < Thor
method_option(
:replication_factor,
desc: 'Replication factor for created topics',
default: 1,
default: false,
check_default_type: false,
type: :numeric
)
# Installs Karafka Web. Creates all needed topics, populates the data and adds the needed
# code to `karafka.rb`.
def install
Karafka::Web::Installer.new.install(replication_factor: options[:replication_factor])
Karafka::Web::Installer.new.install(
replication_factor: compute_replication_factor(options[:replication_factor])
)
end

desc 'migrate', 'Creates necessary topics if not present and populates state data'
method_option(
:replication_factor,
desc: 'Replication factor for created topics',
default: 1,
default: false,
check_default_type: false,
type: :numeric
)
# Creates new topics (if any) and populates missing data.
Expand All @@ -37,27 +41,44 @@ def install
# 2. When upgrading Web-UI in-between versions that would require extra topics and/or extra
# states populated.
def migrate
Karafka::Web::Installer.new.migrate(replication_factor: options[:replication_factor])
Karafka::Web::Installer.new.migrate(
replication_factor: compute_replication_factor(options[:replication_factor])
)
end

desc 'reset', 'Resets the Web UI by removing all the Web topics and creating them again'
method_option(
:replication_factor,
desc: 'Replication factor for created topics',
default: 1,
default: false,
check_default_type: false,
type: :numeric
)
# Resets Karafka Web. Removes the topics, creates them again and populates the initial state
# again. This is useful in case the Web-UI metrics or anything else got corrupted.
def reset
Karafka::Web::Installer.new.reset(replication_factor: options[:replication_factor])
Karafka::Web::Installer.new.reset(
replication_factor: compute_replication_factor(options[:replication_factor])
)
end

desc 'uninstall', 'Removes all the Web UI topics and the enabled code'
# Uninstalls Karafka Web
def uninstall
Karafka::Web::Installer.new.uninstall
end

private

# Takes the CLI user provided replication factor but if not present, uses the brokers count
# to decide. For non-dev clusters (with one broker) we usually want to have replication of
# two, just to have some redundancy.
# @param cli_replication_factor [Integer, false] user requested replication factor or false
# if we are supposed to compute the factor automatically
# @return [Integer] replication factor for Karafka Web UI topics
def compute_replication_factor(cli_replication_factor)
cli_replication_factor || Ui::Models::ClusterInfo.fetch.brokers.size > 1 ? 2 : 1
end
end
end
end