Class: Karafka::Web::Ui::Models::Status::Context
- Inherits:
-
Object
- Object
- Karafka::Web::Ui::Models::Status::Context
- Defined in:
- lib/karafka/web/ui/models/status/context.rb
Overview
Shared context container for status checks.
This class holds cached data that is shared across multiple status checks. Instead of each check fetching data independently, they share this context to avoid redundant Kafka calls and ensure consistency.
The context provides:
-
Memoized accessors for expensive data (cluster info, state, metrics)
-
Helper methods for topic name configuration
-
Computed topic details based on cluster info
Instance Attribute Summary collapse
-
#cluster_info ⇒ Object?
Cluster metadata from Kafka.
-
#connection_time ⇒ Float?
Time in milliseconds to connect to Kafka.
-
#current_metrics ⇒ Hash?
Current consumers metrics from Kafka.
-
#current_state ⇒ Hash?
Current consumers state from Kafka.
-
#processes ⇒ Array?
List of active processes.
-
#subscriptions ⇒ Array?
List of topic subscriptions.
Instance Method Summary collapse
-
#clear_topics_details_cache ⇒ Object
Clears the memoized topics_details cache.
-
#initialize ⇒ Context
constructor
Initialize all instance variables upfront so every instance has the same object shape, avoiding Ruby’s ‘:performance` “shape variations” warning.
-
#topics_consumers_commands ⇒ String
Returns the consumers commands topic name from configuration.
-
#topics_consumers_metrics ⇒ String
Returns the consumers metrics topic name from configuration.
-
#topics_consumers_reports ⇒ String
Returns the consumers reports topic name from configuration.
-
#topics_consumers_states ⇒ String
Returns the consumers states topic name from configuration.
-
#topics_details ⇒ Hash
Computes and returns details about all Web UI topics.
-
#topics_errors ⇒ String
Returns the errors topic name from configuration.
Constructor Details
#initialize ⇒ Context
Initialize all instance variables upfront so every instance has the same object shape, avoiding Ruby’s ‘:performance` “shape variations” warning.
33 34 35 36 37 38 39 40 41 |
# File 'lib/karafka/web/ui/models/status/context.rb', line 33 def initialize @cluster_info = nil @connection_time = nil @current_state = nil @current_metrics = nil @processes = nil @subscriptions = nil @topics_details = nil end |
Instance Attribute Details
#cluster_info ⇒ Object?
Returns cluster metadata from Kafka.
44 45 46 |
# File 'lib/karafka/web/ui/models/status/context.rb', line 44 def cluster_info @cluster_info end |
#connection_time ⇒ Float?
Returns time in milliseconds to connect to Kafka.
47 48 49 |
# File 'lib/karafka/web/ui/models/status/context.rb', line 47 def connection_time @connection_time end |
#current_metrics ⇒ Hash?
Returns current consumers metrics from Kafka.
53 54 55 |
# File 'lib/karafka/web/ui/models/status/context.rb', line 53 def current_metrics @current_metrics end |
#current_state ⇒ Hash?
Returns current consumers state from Kafka.
50 51 52 |
# File 'lib/karafka/web/ui/models/status/context.rb', line 50 def current_state @current_state end |
#processes ⇒ Array?
Returns list of active processes.
56 57 58 |
# File 'lib/karafka/web/ui/models/status/context.rb', line 56 def processes @processes end |
#subscriptions ⇒ Array?
Returns list of topic subscriptions.
59 60 61 |
# File 'lib/karafka/web/ui/models/status/context.rb', line 59 def subscriptions @subscriptions end |
Instance Method Details
#clear_topics_details_cache ⇒ Object
Clears the memoized topics_details cache.
Call this if cluster_info is updated and you need fresh topic details.
114 115 116 |
# File 'lib/karafka/web/ui/models/status/context.rb', line 114 def clear_topics_details_cache @topics_details = nil end |
#topics_consumers_commands ⇒ String
Returns the consumers commands topic name from configuration.
92 93 94 |
# File 'lib/karafka/web/ui/models/status/context.rb', line 92 def topics_consumers_commands ::Karafka::Web.config.topics.consumers.commands.name.to_s end |
#topics_consumers_metrics ⇒ String
Returns the consumers metrics topic name from configuration.
78 79 80 |
# File 'lib/karafka/web/ui/models/status/context.rb', line 78 def topics_consumers_metrics ::Karafka::Web.config.topics.consumers.metrics.name.to_s end |
#topics_consumers_reports ⇒ String
Returns the consumers reports topic name from configuration.
71 72 73 |
# File 'lib/karafka/web/ui/models/status/context.rb', line 71 def topics_consumers_reports ::Karafka::Web.config.topics.consumers.reports.name.to_s end |
#topics_consumers_states ⇒ String
Returns the consumers states topic name from configuration.
64 65 66 |
# File 'lib/karafka/web/ui/models/status/context.rb', line 64 def topics_consumers_states ::Karafka::Web.config.topics.consumers.states.name.to_s end |
#topics_details ⇒ Hash
Computes and returns details about all Web UI topics.
For each topic, returns whether it exists, its partition count, and replication factor. Uses cluster_info to determine actual values.
107 108 109 |
# File 'lib/karafka/web/ui/models/status/context.rb', line 107 def topics_details @topics_details ||= compute_topics_details end |