Class: Karafka::Web::Ui::Models::Status::Checks::Connection

Inherits:
Base
  • Object
show all
Defined in:
lib/karafka/web/ui/models/status/checks/connection.rb

Overview

Checks if we can connect to Kafka and measures connection latency.

Some users try to work with Kafka over the internet with high latency, which can make the connection unstable. This check measures connection time and warns when it’s too high.

Connection times:

  • < 1 second: success

  • 1-1000 seconds: warning (high latency)

  • > 1000 seconds or failure: failure

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

depends_on, independent!, independent?, #initialize

Constructor Details

This class inherits a constructor from Karafka::Web::Ui::Models::Status::Checks::Base

Class Method Details

.halted_detailsHash

Returns the default details for halted state.

Returns:

  • (Hash)

    the default details for halted state



24
25
26
# File 'lib/karafka/web/ui/models/status/checks/connection.rb', line 24

def halted_details
  { time: nil }
end

Instance Method Details

#callStatus::Step

Executes the connection check.

Attempts to connect to Kafka and measures the connection time. Caches the result in the context for subsequent checks.

Returns:



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/karafka/web/ui/models/status/checks/connection.rb', line 35

def call
  connect unless context.connection_time

  level = if context.connection_time < 1_000
    :success
  elsif context.connection_time < 1_000_000
    :warning
  else
    :failure
  end

  step(level, { time: context.connection_time })
end