-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide search capabilities in the Explorer (#341)
- Loading branch information
Showing
60 changed files
with
2,667 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
open3 | ||
zlib | ||
securerandom | ||
cgi | ||
uri | ||
].each { |lib| require lib } | ||
|
||
module Karafka | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# frozen_string_literal: true | ||
|
||
# This Karafka component is a Pro component under a commercial license. | ||
# This Karafka component is NOT licensed under LGPL. | ||
# | ||
# All of the commercial components are present in the lib/karafka/pro directory of this | ||
# repository and their usage requires commercial license agreement. | ||
# | ||
# Karafka has also commercial-friendly license, commercial support and commercial components. | ||
# | ||
# By sending a pull request to the pro components, you are agreeing to transfer the copyright of | ||
# your code to Maciej Mensfeld. | ||
|
||
module Karafka | ||
module Web | ||
module Pro | ||
module Ui | ||
module Controllers | ||
# 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. | ||
class SearchController < Web::Ui::Controllers::ClusterController | ||
# 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 | ||
# | ||
# @param topic_id [String] topic we're interested in | ||
# @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. | ||
def index(topic_id) | ||
@topic_id = topic_id | ||
@partitions_count = Models::ClusterInfo.partitions_count(topic_id) | ||
@matchers = Web.config.ui.search.matchers | ||
@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.visibility.filter | ||
@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 | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# frozen_string_literal: true | ||
|
||
# This Karafka component is a Pro component under a commercial license. | ||
# This Karafka component is NOT licensed under LGPL. | ||
# | ||
# All of the commercial components are present in the lib/karafka/pro directory of this | ||
# repository and their usage requires commercial license agreement. | ||
# | ||
# Karafka has also commercial-friendly license, commercial support and commercial components. | ||
# | ||
# By sending a pull request to the pro components, you are agreeing to transfer the copyright of | ||
# your code to Maciej Mensfeld. | ||
|
||
module Karafka | ||
module Web | ||
module Pro | ||
module Ui | ||
module Lib | ||
# All code needed to support the search functionality | ||
# It's not in models because it does not provide "data" per se but rather fetches it | ||
# from a Kafka. | ||
module Search | ||
class << self | ||
# Validates that the UI search config is correct | ||
# | ||
# @param config [Karafka::Core::Configurable::Node] web config | ||
def post_setup(config) | ||
Search::Contracts::Config.new.validate!(config.to_h) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# frozen_string_literal: true | ||
|
||
# This Karafka component is a Pro component under a commercial license. | ||
# This Karafka component is NOT licensed under LGPL. | ||
# | ||
# All of the commercial components are present in the lib/karafka/pro directory of this | ||
# repository and their usage requires commercial license agreement. | ||
# | ||
# Karafka has also commercial-friendly license, commercial support and commercial components. | ||
# | ||
# By sending a pull request to the pro components, you are agreeing to transfer the copyright of | ||
# your code to Maciej Mensfeld. | ||
|
||
module Karafka | ||
module Web | ||
module Pro | ||
module Ui | ||
module Lib | ||
module Search | ||
# Extra configuration for pro UI | ||
class Config | ||
extend ::Karafka::Core::Configurable | ||
|
||
# Matches for messages | ||
setting :matchers, default: [ | ||
Matchers::RawPayloadIncludes, | ||
Matchers::RawKeyIncludes, | ||
Matchers::RawHeaderIncludes | ||
] | ||
|
||
# How long should we at most search before stopping (in ms) | ||
# This prevents us from having a search that would basically hang the browser and | ||
# never finish | ||
setting :timeout, default: 30_000 | ||
|
||
# Search limits as the search runs in Puma | ||
# Too big value will make the scan really slow | ||
# We do not put a max limit here because those values are used in a select in | ||
# the Web UI. | ||
setting :limits, default: [ | ||
1_000, | ||
10_000, | ||
100_000 | ||
] | ||
|
||
configure | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.