Class: Karafka::Web::Pro::Ui::Controllers::Explorer::SearchController

Inherits:
Ui::Controllers::ClusterController show all
Defined in:
lib/karafka/web/pro/ui/controllers/explorer/search_controller.rb

Overview

Handles the search requests We present this as a part of explorer scope but we use a separate controller not to mix data exploring with searching.

Constant Summary

Constants inherited from Ui::Controllers::BaseController

Ui::Controllers::BaseController::Models

Instance Attribute Summary

Attributes inherited from Ui::Controllers::BaseController

#params, #session

Instance Method Summary collapse

Methods inherited from Ui::Controllers::ClusterController

#brokers, #replication

Methods inherited from Ui::Controllers::BaseController

#cache, #initialize

Methods included from Ui::Controllers::Requests::Hookable

included, #run_after_hooks, #run_before_hooks

Constructor Details

This class inherits a constructor from Karafka::Web::Ui::Controllers::BaseController

Instance Method Details

#index(topic_id) ⇒ Object

Note:

In theory search can be used to detect pieces of information within messages. Since we allow for custom search strategies, this is not an issue because users that need to provide only granular search can do so.

Runs the search if search parameters are provided If no parameters provided, displays the search modal and info to provide search data. If invalid search parameters provided, modal contains errors

Parameters:

  • topic_id (String)

    topic we’re interested in



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/karafka/web/pro/ui/controllers/explorer/search_controller.rb', line 49

def index(topic_id)
  @topic_id = topic_id
  @partitions_count = Models::ClusterInfo.partitions_count(topic_id)
  # Select only matchers that should be available in the context of the current topic
  available_matchers = Web.config.ui.search.matchers
  @matchers = available_matchers.select { |match| match.active?(@topic_id) }
  @search_criteria = !@params.current_search.empty?
  @current_search = Lib::Search::Normalizer.call(@params.current_search)
  # Needed when rendering found messages rows. We should always filter the messages
  # details with the visibility filter
  @visibility_filter = ::Karafka::Web.config.ui.policies.messages
  @limits = ::Karafka::Web.config.ui.search.limits.sort

  # If there is search form filled, we validate it to make sure there are no errors
  @errors = if @search_criteria
    Lib::Search::Contracts::Form.new.call(@current_search).errors
  else
    {}
  end

  # If all good we run the search
  if @search_criteria && @errors.empty?
    found, @search_details = Lib::Search::Runner.new(
      @topic_id,
      @partitions_count,
      @current_search
    ).call

    @messages, last_page = Paginators::Arrays.call(
      found,
      @params.current_page
    )

    paginate(@params.current_page, !last_page)
  end

  render
end