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

Instance Method Details

#lag_with_label(lag) ⇒ String

Returns lag if correct or N/A with labeled explanation.

Parameters:

  • lag (Integer)

    lag

Returns:

  • (String)

    lag if correct or N/A with labeled explanation

See Also:



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.

Parameters:

Returns:

  • (String)

    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.

Parameters:

Returns:

  • (String)

    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.

Parameters:

  • value (Integer)

Returns:

  • (String)

    input value if not negative or N/A



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.

Parameters:

  • topic_name (String)

    name of the topic for explorer path

  • partition_id (Integer)

    partition for the explorer path

  • offset (Integer)

    offset

  • explore (Boolean) (defaults to: false)

    should we generate (when allowed) a link to message explorer

Returns:

  • (String)

    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.

Parameters:

  • partition (Hash, Ui::Models::Partition)

    partition metadata

  • link (Boolean) (defaults to: false)

    when true, each broker badge links to its broker details page (Pro-only; OSS has no per-broker view so it renders plain badges)

Returns:

  • (String)

    in-sync broker ids as badges with a count subtext



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">&mdash;</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.

Parameters:

  • partition (Hash, Ui::Models::Partition)

    partition metadata

  • link (Boolean) (defaults to: false)

    when true, each broker badge links to its broker details page (Pro-only; OSS has no per-broker view so it renders plain badges)

Returns:

  • (String)

    replica broker ids as badges with a count subtext



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">&mdash;</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