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

Support empty rebalance reason #272

Merged
merged 3 commits into from
Feb 6, 2024
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 @@ -2,6 +2,7 @@

## 0.8.2 (Unreleased)
- [Enhancement] Defer scheduler background thread creation until needed allowing for forks.
- [Fix] Rebalance reason can be empty on a SG when no network.

## 0.8.1 (2024-02-01)
- [Enhancement] Introduce "Lags" health view.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class SubscriptionGroup < Web::Contracts::Base
required(:stateage) { |val| val.is_a?(Integer) && val >= 0 }
required(:rebalance_age) { |val| val.is_a?(Integer) && val >= 0 }
required(:rebalance_cnt) { |val| val.is_a?(Integer) && val >= 0 }
required(:rebalance_reason) { |val| val.is_a?(String) && !val.empty? }
required(:rebalance_reason) { |val| val.is_a?(String) }
required(:poll_age) { |val| val.is_a?(Numeric) && val >= 0 }
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,13 @@

<span class="text-end mt-3">
<small>
Last rebalance reason: <%= subscription_group.rebalance_reason %>
Last rebalance reason:

<% if subscription_group.rebalance_reason.empty? %>
Unknown
<% else %>
<%= subscription_group.rebalance_reason %>
<% end %>
</small>
</span>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,27 @@
it { expect(contract.call(subscription_group)).not_to be_success }
end

context 'when rebalance_reason in state is missing' do
before { subscription_group[:state].delete(:rebalance_reason) }

it { expect(contract.call(subscription_group)).not_to be_success }
end

context 'when rebalance_reason is not a string' do
before { subscription_group[:state][:rebalance_reason] = rand }

it { expect(contract.call(subscription_group)).not_to be_success }
end

context 'when rebalance_reason is empty' do
before { subscription_group[:state][:rebalance_reason] = '' }

it { expect(contract.call(subscription_group)).to be_success }
end

%i[
state
join_state
rebalance_reason
].each do |key|
context "when #{key} in state is missing" do
before { subscription_group[:state].delete(key) }
Expand Down
24 changes: 24 additions & 0 deletions spec/lib/karafka/web/ui/pro/controllers/consumers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,30 @@
end
end

context 'when subscription has an unknown rebalance reason' do
before do
topics_config.consumers.reports = reports_topic

report = Fixtures.consumers_reports_json(symbolize_names: true)

sg = report[:consumer_groups][:example_app6_app][:subscription_groups][:c4ca4238a0b9_0]
sg[:state][:rebalance_reason] = ''

produce(reports_topic, report.to_json)

get 'consumers/1/subscriptions'
end

it do
expect(response).to be_ok
expect(body).to include('Rebalance count:')
expect(body).to include('Unknown')
expect(body).to include('This process does not consume any')
expect(body).not_to include(pagination)
expect(body).not_to include(support_message)
end
end

context 'when subscriptions exist and was reported in a transactional fashion' do
before do
topics_config.consumers.states = states_topic
Expand Down