Module: Karafka::Web::Ui::Helpers::TopicsHelper
- Included in:
- Base
- Defined in:
- lib/karafka/web/ui/helpers/topics_helper.rb
Overview
Helper module for formatting Kafka topic and partition information in various contexts within the Karafka Web UI.
This module provides consistent formatting for topic-partition assignments across different display contexts like inline text, labels, and identifiers.
Constant Summary collapse
- DEFAULT_LIMIT =
Default limit for displaying partitions before truncation
5
Instance Method Summary collapse
-
#topics_assignment_label(topic, partitions, limit: DEFAULT_LIMIT) ⇒ String
Formats topic and partitions for human-readable labels and headers.
-
#topics_assignment_text(topic, partitions, limit: DEFAULT_LIMIT) ⇒ String
Formats topic and partitions for inline text display in views.
-
#topics_partition_identifier(topic, partition) ⇒ String
Creates a specific identifier for topic-partition combinations.
Instance Method Details
#topics_assignment_label(topic, partitions, limit: DEFAULT_LIMIT) ⇒ String
Formats topic and partitions for human-readable labels and headers.
This method provides more descriptive formatting suitable for page titles, section headers, and other contexts where additional context is helpful.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/karafka/web/ui/helpers/topics_helper.rb', line 90 def topics_assignment_label(topic, partitions, limit: DEFAULT_LIMIT) partitions = Array(partitions) sorted_partitions = partitions.map(&:to_i).sort if topics_consecutive?(sorted_partitions) "#{topic}-[#{sorted_partitions.first}-#{sorted_partitions.last}] " \ "(#{partitions.size} partitions total)" elsif sorted_partitions.size > limit displayed = sorted_partitions.first(limit) remaining = sorted_partitions.size - limit "#{topic}-[#{displayed.join(',')}] (+#{remaining} more)" else "#{topic}-[#{sorted_partitions.join(',')}]" end end |
#topics_assignment_text(topic, partitions, limit: DEFAULT_LIMIT) ⇒ String
Formats topic and partitions for inline text display in views.
This method is optimized for compact display in assignments, logs, and other inline contexts where space is limited.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/karafka/web/ui/helpers/topics_helper.rb', line 47 def topics_assignment_text(topic, partitions, limit: DEFAULT_LIMIT) partitions = Array(partitions) if partitions.empty? topic elsif partitions.size == 1 "#{topic}-[#{partitions.first}]" else sorted_partitions = partitions.map(&:to_i).sort # Check for consecutive first (best representation) if topics_consecutive?(sorted_partitions) && sorted_partitions.size > 2 "#{topic}-[#{sorted_partitions.first}-#{sorted_partitions.last}]" # Apply limit if specified and partitions exceed it elsif limit && sorted_partitions.size > limit displayed_partitions = sorted_partitions.first(limit) "#{topic}-[#{displayed_partitions.join(',')}...]" else "#{topic}-[#{sorted_partitions.join(',')}]" end end end |
#topics_partition_identifier(topic, partition) ⇒ String
Creates a specific identifier for topic-partition combinations.
This method generates consistent identifiers used in metrics collection, cache keys, and other contexts requiring unique topic-partition identification.
122 123 124 |
# File 'lib/karafka/web/ui/helpers/topics_helper.rb', line 122 def topics_partition_identifier(topic, partition) "#{topic}-#{partition}" end |