Module: Karafka::Web::Ui::Helpers::PartitionsHelper
- Included in:
- Base
- Defined in:
- lib/karafka/web/ui/helpers/partitions_helper.rb
Overview
Kafka partition presentation helpers: replica/ISR broker ids, LSO risk state and offset/lag labels
Instance Method Summary collapse
-
#lag_with_label(lag) ⇒ String
Lag if correct or
N/Awith labeled explanation. -
#lso_risk_state_badge(details) ⇒ String
Background classes for row marking.
-
#lso_risk_state_bg(details) ⇒ String
Background classes for row marking.
-
#normalized_metric(value) ⇒ String
Normalizes the metric value for display.
-
#offset_with_label(topic_name, partition_id, offset, explore: false) ⇒ String
Offset if correct or
N/Awith labeled explanation for offsets that are less than 0. -
#partition_in_sync_brokers(partition, link: false) ⇒ String
Renders the in-sync (ISR) broker ids for a partition as badges, with the leader emphasized.
-
#partition_replica_brokers(partition, link: false) ⇒ String
Renders the assigned replica broker ids for a partition as badges.
Instance Method Details
#lag_with_label(lag) ⇒ String
Returns lag if correct or N/A with labeled explanation.
99 100 101 102 103 104 105 106 |
# File 'lib/karafka/web/ui/helpers/partitions_helper.rb', line 99 def lag_with_label(lag) if lag.negative? title = "Not available until first offset commit" %(<span class="badge badge-secondary" title="#{title}">N/A</span>) else lag.to_s end end |
#lso_risk_state_badge(details) ⇒ String
Returns background classes for row marking.
83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/karafka/web/ui/helpers/partitions_helper.rb', line 83 def lso_risk_state_badge(details) case details.lso_risk_state when :active "" when :at_risk "badge-warning" when :stopped "badge-error" else raise ::Karafka::Errors::UnsupportedCaseError end end |
#lso_risk_state_bg(details) ⇒ String
Returns background classes for row marking.
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/karafka/web/ui/helpers/partitions_helper.rb', line 67 def lso_risk_state_bg(details) case details.lso_risk_state when :active "" when :at_risk "bg-warning bg-opacity-25" when :stopped "bg-error bg-opacity-25" else raise ::Karafka::Errors::UnsupportedCaseError end end |
#normalized_metric(value) ⇒ String
Normalizes the metric value for display. Negative values coming from statistics usually mean, that the value is not (yet) available.
132 133 134 |
# File 'lib/karafka/web/ui/helpers/partitions_helper.rb', line 132 def normalized_metric(value) value.negative? ? "N/A" : value.to_s end |
#offset_with_label(topic_name, partition_id, offset, explore: false) ⇒ String
Returns offset if correct or N/A with labeled explanation for offsets
that are less than 0. Offset with less than 0 indicates, that the offset was not
yet committed and there is no value we know of.
115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/karafka/web/ui/helpers/partitions_helper.rb', line 115 def offset_with_label(topic_name, partition_id, offset, explore: false) if offset.negative? title = "Not available until first offset commit" %(<span class="badge badge-secondary" title="#{title}">N/A</span>) elsif explore path = explorer_topics_path(topic_name, partition_id, offset) %(<a href="#{path}">#{offset}</a>) else offset.to_s end end |
#partition_in_sync_brokers(partition, link: false) ⇒ String
Renders the in-sync (ISR) broker ids for a partition as badges, with the leader emphasized. An empty ISR set (fully under-replicated partition) renders a dash.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/karafka/web/ui/helpers/partitions_helper.rb', line 48 def partition_in_sync_brokers(partition, link: false) isrs = partition[:isrs] return %(<span class="text-muted">—</span>) if isrs.empty? leader = partition[:leader] badges = isrs.map do |broker_id| css = (broker_id == leader) ? "badge-primary" : "badge-success" broker_id_badge(broker_id, css, link: link) end.join(" ") "#{badges}#{broker_count_note(isrs.size, "in-sync")}" end |
#partition_replica_brokers(partition, link: false) ⇒ String
Renders the assigned replica broker ids for a partition as badges. The leader is emphasized and any replica that is not part of the in-sync set (ISR) is highlighted as a warning, turning the replication view into an at-a-glance health signal.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/karafka/web/ui/helpers/partitions_helper.rb', line 18 def partition_replica_brokers(partition, link: false) replicas = partition[:replicas] return %(<span class="text-muted">—</span>) if replicas.empty? leader = partition[:leader] isrs = partition[:isrs] badges = replicas.map do |broker_id| css = if broker_id == leader "badge-primary" elsif isrs.include?(broker_id) "badge-info" else "badge-warning" end broker_id_badge(broker_id, css, link: link) end.join(" ") "#{badges}#{broker_count_note(replicas.size, "replicas")}" end |