Class: Karafka::Web::Ui::Models::Partition

Inherits:
Lib::HashProxy show all
Defined in:
lib/karafka/web/ui/models/partition.rb

Overview

Single topic partition data representation model

Instance Method Summary collapse

Methods inherited from Lib::HashProxy

#method_missing, #respond_to_missing?, #to_h

Constructor Details

#initialize(*args) ⇒ Partition

Returns a new instance of Partition.

Parameters:

  • args (Object)

    anything hash proxy accepts



10
11
12
13
14
15
16
17
# File 'lib/karafka/web/ui/models/partition.rb', line 10

def initialize(*args)
  super

  # We initialize those here because we want to have them stored in the internal has
  # for sorting
  lag_hybrid
  lag_hybrid_d
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Karafka::Web::Ui::Lib::HashProxy

Instance Method Details

#lag_hybridInteger

Because lag_stored is not available until first marking, we fallback to the lag value that may be behind but is always available until stored lag is available.

Returns:

  • (Integer)

    hybrid log value



22
23
24
# File 'lib/karafka/web/ui/models/partition.rb', line 22

def lag_hybrid
  self[:lag_hybrid] ||= lag_stored.negative? ? lag : lag_stored
end

#lag_hybrid_dInteger

Returns hybrid log delta.

Returns:

  • (Integer)

    hybrid log delta



27
28
29
# File 'lib/karafka/web/ui/models/partition.rb', line 27

def lag_hybrid_d
  self[:lag_hybrid_d] ||= lag_stored.negative? ? lag_d : lag_stored_d
end

#lso_risk_stateSymbol

Note:

States descriptions: - :active all good. No hanging transactions, processing is ok - :at_risk - there may be hanging transactions but they do not affect processing before being stuck. This means, that the transaction still may be finished without affecting the processing, hence not having any impact. - :stopped - we have reached a hanging LSO and we cannot move forward despite more data being available. Unless the hanging transaction is killed or it finishes, we will not move forward.

Returns one of three states in which LSO can be in the correlation to given partition in the context of a consumer group.

Returns:

  • (Symbol)

    one of three states in which LSO can be in the correlation to given partition in the context of a consumer group.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/karafka/web/ui/models/partition.rb', line 42

def lso_risk_state
  # If last stable is falling behind the high watermark
  if ls_offset < hi_offset
    # But it is changing and moving fast enough, it does not mean it is stuck
    return :active if ls_offset_fd < ::Karafka::Web.config.ui.lso_threshold

    # If it is stuck but we still have work to do, this is not a tragic situation because
    # maybe it will unstuck before we reach it
    return :at_risk if (committed_offset || 0) < ls_offset

    # If it is not changing and falling behind high, it is stuck
    :stopped
  else
    :active
  end
end