-
-
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.
Data transfers tracking + migrations (#209)
- Loading branch information
Showing
71 changed files
with
7,564 additions
and
804 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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# frozen_string_literal: true | ||
|
||
module Karafka | ||
module Web | ||
# Web UI Zeitwerk Inflector that allows us to have time prefixed files with migrations, similar | ||
# to how Rails does that. | ||
class Inflector < Zeitwerk::GemInflector | ||
# Checks if given path is a migration one | ||
MIGRATION_ABSPATH_REGEXP = /migrations\/[0-9]+_(.*)/ | ||
|
||
# Checks if it is a migration file | ||
MIGRATION_BASENAME_REGEXP = /\A[0-9]+_(.*)/ | ||
|
||
private_constant :MIGRATION_ABSPATH_REGEXP, :MIGRATION_BASENAME_REGEXP | ||
|
||
# @param [String] basename of the file to be loaded | ||
# @param abspath [String] absolute path of the file to be loaded | ||
# @return [String] Constant name to be used for given file | ||
def camelize(basename, abspath) | ||
# If not migration directory with proper migration files, use defaults | ||
return super unless abspath.match?(MIGRATION_ABSPATH_REGEXP) | ||
# If base name is not of a proper name in migrations, use defaults | ||
return super unless basename.match?(MIGRATION_BASENAME_REGEXP) | ||
|
||
super( | ||
# Extract only the name without the timestamp | ||
basename.match(MIGRATION_BASENAME_REGEXP).to_a.last, | ||
abspath | ||
) | ||
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
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 | ||
|
||
module Karafka | ||
module Web | ||
module Management | ||
# Namespace for all the commands related to management of the Web-UI in the context of | ||
# Karafka. It includes things like installing, creating needed topics, etc. | ||
module Actions | ||
# Base class for all the commands that we use to manage | ||
class Base | ||
include ::Karafka::Helpers::Colorize | ||
|
||
private | ||
|
||
# @return [String] green colored word "successfully" | ||
def successfully | ||
green('successfully') | ||
end | ||
|
||
# @return [String] green colored word "already" | ||
def already | ||
green('already') | ||
end | ||
|
||
# @return [Array<String>] topics available in the cluster | ||
def existing_topics_names | ||
@existing_topics_names ||= ::Karafka::Admin | ||
.cluster_info | ||
.topics | ||
.map { |topic| topic[:topic_name] } | ||
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,33 @@ | ||
# frozen_string_literal: true | ||
|
||
module Karafka | ||
module Web | ||
module Management | ||
module Actions | ||
# Cleans the boot file from Karafka Web-UI details. | ||
class CleanBootFile < Base | ||
# Web-UI enabled code | ||
ENABLER_CODE = ExtendBootFile::ENABLER_CODE | ||
|
||
private_constant :ENABLER_CODE | ||
|
||
# Removes the Web-UI boot file data | ||
def call | ||
karafka_rb = File.readlines(Karafka.boot_file) | ||
|
||
if karafka_rb.any? { |line| line.include?(ENABLER_CODE) } | ||
puts 'Updating the Karafka boot file...' | ||
karafka_rb.delete_if { |line| line.include?(ENABLER_CODE) } | ||
|
||
File.write(Karafka.boot_file, karafka_rb.join) | ||
puts "Karafka boot file #{successfully} updated." | ||
puts 'Make sure to remove configuration and other customizations as well.' | ||
else | ||
puts 'Karafka Web UI components not found in the boot file.' | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
77 changes: 77 additions & 0 deletions
77
lib/karafka/web/management/actions/create_initial_states.rb
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,77 @@ | ||
# frozen_string_literal: true | ||
|
||
module Karafka | ||
module Web | ||
module Management | ||
module Actions | ||
# Creates the records needed for the Web-UI to operate. | ||
# It creates "almost" empty states because the rest is handled via migrations | ||
class CreateInitialStates < Base | ||
# Whole default empty state | ||
# This will be further migrated by the migrator | ||
DEFAULT_STATE = { | ||
schema_version: '0.0.0' | ||
}.freeze | ||
|
||
# Default metrics state | ||
DEFAULT_METRICS = { | ||
schema_version: '0.0.0' | ||
}.freeze | ||
|
||
# Creates the initial states for the Web-UI if needed (if they don't exist) | ||
def call | ||
if exists?(Karafka::Web.config.topics.consumers.states) | ||
exists('consumers state') | ||
else | ||
creating('consumers state') | ||
::Karafka::Web.producer.produce_sync( | ||
topic: Karafka::Web.config.topics.consumers.states, | ||
key: Karafka::Web.config.topics.consumers.states, | ||
payload: DEFAULT_STATE.to_json | ||
) | ||
created('consumers state') | ||
end | ||
|
||
if exists?(Karafka::Web.config.topics.consumers.metrics) | ||
exists('consumers metrics') | ||
else | ||
creating('consumers metrics') | ||
::Karafka::Web.producer.produce_sync( | ||
topic: Karafka::Web.config.topics.consumers.metrics, | ||
key: Karafka::Web.config.topics.consumers.metrics, | ||
payload: DEFAULT_METRICS.to_json | ||
) | ||
created('consumers metrics') | ||
end | ||
end | ||
|
||
private | ||
|
||
# @param topic [String] topic name | ||
# @return [Boolean] true if there is already an initial record in a given topic | ||
def exists?(topic) | ||
!::Karafka::Admin.read_topic(topic, 0, 5).last.nil? | ||
end | ||
|
||
# @param type [String] type of state | ||
# @return [String] exists message | ||
def exists(type) | ||
puts "Initial #{type} #{already} exists." | ||
end | ||
|
||
# @param type [String] type of state | ||
# @return [String] message that the state is being created | ||
def creating(type) | ||
puts "Creating #{type} initial record..." | ||
end | ||
|
||
# @param type [String] type of state | ||
# @return [String] message that the state was created | ||
def created(type) | ||
puts "Initial #{type} record #{successfully} created." | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.