karafka-web 0.1.1 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4883680e156d1147dddceb19b1a8ed0977c1930a4dbdb5bffab7adf836d2a95f
4
- data.tar.gz: 21cc44c9390cc2b098bd6261cb999f5143a560d5d774dda786c6b294e865e5f2
3
+ metadata.gz: 3a70fc5cb35d0e6e60a348e3efe91113b54d0c62310b7c3af4e7584aa70cfb70
4
+ data.tar.gz: 43a96b7e7a4622721dbc6ba144852335aecbfe907049bc47ab563ea07f40eb54
5
5
  SHA512:
6
- metadata.gz: 59e16f47b0085db2a0e4b91ec76c8a3b6d51dbdf806840e1ac9179777f587340fba046a8c4f33df879e519e34d0737be201a736d595fbf330c9e2f5e2e4eb1fd
7
- data.tar.gz: a3896ace699760b73c2674bb4155d9255309b371e52485e9ebc3757ab18ac5fa1708f266831b463d112b0c3630886114a560cecdc0f505950a8bd58d266efbcf
6
+ metadata.gz: db0b153569ca93f1164a851216e0f224acc56e6a7533a35a86a44f6f2f8bffc1630e5ccf7c2e53a14455206401c45b59b1728eb266c59360be8f952794d3011b
7
+ data.tar.gz: 794c77edb27f7f9a397c3de891b146f9020653b84bad46e1f1b537a1d547ffc793211e7bd5ffb0f426c0b8fa9b6359230bb3fe3ee8fa5ec668cb0e1d39782d5a
checksums.yaml.gz.sig CHANGED
Binary file
@@ -13,6 +13,41 @@ env:
13
13
  BUNDLE_JOBS: 4
14
14
 
15
15
  jobs:
16
+ specs:
17
+ runs-on: ubuntu-latest
18
+ needs: diffend
19
+ strategy:
20
+ fail-fast: false
21
+ matrix:
22
+ ruby:
23
+ - '3.2'
24
+ - '3.1'
25
+ - '3.0'
26
+ - '2.7'
27
+ include:
28
+ - ruby: '3.2'
29
+ coverage: 'true'
30
+ steps:
31
+ - uses: actions/checkout@v3
32
+ - name: Install package dependencies
33
+ run: "[ -e $APT_DEPS ] || sudo apt-get install -y --no-install-recommends $APT_DEPS"
34
+ - name: Set up Ruby
35
+ uses: ruby/setup-ruby@v1
36
+ with:
37
+ ruby-version: ${{matrix.ruby}}
38
+ - name: Install latest bundler
39
+ run: |
40
+ gem install bundler --no-document
41
+ bundle config set without 'tools benchmarks docs'
42
+ - name: Bundle install
43
+ run: |
44
+ bundle config set without development
45
+ bundle install --jobs 4 --retry 3
46
+ - name: Run all tests
47
+ env:
48
+ GITHUB_COVERAGE: ${{matrix.coverage}}
49
+ run: bundle exec rspec
50
+
16
51
  diffend:
17
52
  runs-on: ubuntu-latest
18
53
  strategy:
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.2.0
1
+ 3.2.1
data/CHANGELOG.md CHANGED
@@ -1,9 +1,20 @@
1
1
  # Karafka Web changelog
2
2
 
3
+ ## 0.1.3 (2023-02-14)
4
+ - Skip topics creation if web topics already exist (do not raise error)
5
+ - Support ability to provide replication factor in the install command
6
+ - Provide ability to reset the state with a `reset` command. It will remove and re-create the topics.
7
+ - Provide ability to uninstall the web via the CLI `uninstall` command
8
+ - Remove the `Karafka::Web.bootstrap!` method as the install should happen via `bundle exec karafka-web install`
9
+
10
+ ## 0.1.2 (2023-02-10)
11
+ - Provide more comprehensive info when lag stored and stored offset are not available.
12
+ - Setup rspec scaffold.
13
+
3
14
  ## 0.1.1 (2023-01-30)
4
15
  - Rename `Karafka::Web.bootstrap_topics!` to `Karafka::Web.bootstrap!` and expand it with the zero state injection.
5
16
  - Require Karafka `2.0.28` due to some instrumentation fixes.
6
17
  - Provide an auto-installer under the `bundle exec karafka-web install` command.
7
18
 
8
19
  ## 0.1.0
9
- - Initial code of the Web and Web Pro
20
+ - Initial code of the Web and Web Pro.
data/Gemfile CHANGED
@@ -5,3 +5,9 @@ source 'https://rubygems.org'
5
5
  plugin 'diffend'
6
6
 
7
7
  gemspec
8
+
9
+ group :test do
10
+ gem 'byebug'
11
+ gem 'rspec'
12
+ gem 'simplecov'
13
+ end
data/Gemfile.lock CHANGED
@@ -1,24 +1,28 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- karafka-web (0.1.1)
4
+ karafka-web (0.1.3)
5
5
  erubi (~> 1.4)
6
6
  karafka (>= 2.0.29, < 3.0.0)
7
+ karafka-core (>= 2.0.10, < 3.0.0)
7
8
  roda (~> 3.63)
8
9
  tilt (~> 2.0)
9
10
 
10
11
  GEM
11
12
  remote: https://rubygems.org/
12
13
  specs:
14
+ byebug (11.1.3)
13
15
  concurrent-ruby (1.2.0)
16
+ diff-lcs (1.5.0)
17
+ docile (1.4.0)
14
18
  erubi (1.12.0)
15
19
  ffi (1.15.5)
16
- karafka (2.0.29)
20
+ karafka (2.0.30)
17
21
  karafka-core (>= 2.0.9, < 3.0.0)
18
22
  thor (>= 0.20)
19
23
  waterdrop (>= 2.4.10, < 3.0.0)
20
24
  zeitwerk (~> 2.3)
21
- karafka-core (2.0.9)
25
+ karafka-core (2.0.10)
22
26
  concurrent-ruby (>= 1.1)
23
27
  karafka-rdkafka (>= 0.12)
24
28
  karafka-rdkafka (0.12.0)
@@ -33,20 +37,43 @@ GEM
33
37
  rake (13.0.6)
34
38
  roda (3.64.0)
35
39
  rack
40
+ rspec (3.12.0)
41
+ rspec-core (~> 3.12.0)
42
+ rspec-expectations (~> 3.12.0)
43
+ rspec-mocks (~> 3.12.0)
44
+ rspec-core (3.12.1)
45
+ rspec-support (~> 3.12.0)
46
+ rspec-expectations (3.12.2)
47
+ diff-lcs (>= 1.2.0, < 2.0)
48
+ rspec-support (~> 3.12.0)
49
+ rspec-mocks (3.12.3)
50
+ diff-lcs (>= 1.2.0, < 2.0)
51
+ rspec-support (~> 3.12.0)
52
+ rspec-support (3.12.0)
53
+ simplecov (0.22.0)
54
+ docile (~> 1.1)
55
+ simplecov-html (~> 0.11)
56
+ simplecov_json_formatter (~> 0.1)
57
+ simplecov-html (0.12.3)
58
+ simplecov_json_formatter (0.1.4)
36
59
  thor (1.2.1)
37
60
  tilt (2.0.11)
38
61
  waterdrop (2.4.10)
39
62
  karafka-core (>= 2.0.9, < 3.0.0)
40
63
  zeitwerk (~> 2.3)
41
64
  webrick (1.8.1)
42
- zeitwerk (2.6.6)
65
+ zeitwerk (2.6.7)
43
66
 
44
67
  PLATFORMS
68
+ arm64-darwin-21
45
69
  x86_64-linux
46
70
 
47
71
  DEPENDENCIES
72
+ byebug
48
73
  karafka-web!
49
74
  rackup (~> 0.2)
75
+ rspec
76
+ simplecov
50
77
 
51
78
  BUNDLED WITH
52
- 2.4.5
79
+ 2.4.6
data/bin/karafka-web CHANGED
@@ -4,30 +4,5 @@ require 'karafka'
4
4
  require 'karafka/web'
5
5
 
6
6
  ::Karafka::Cli::Base.load
7
- include ::Karafka::Helpers::Colorize
8
7
 
9
- case ARGV[0]
10
- when 'install'
11
- puts
12
- puts 'Installing Karafka Web UI...'
13
- puts
14
- puts 'Creating necessary topics and populating state data...'
15
- Karafka::Web.bootstrap!
16
- puts 'Updating the Karafka boot file...'
17
-
18
- enabler = 'Karafka::Web.enable!'
19
-
20
- if File.read(Karafka.boot_file).include?(enabler)
21
- puts "Web UI #{green('already')} installed."
22
- else
23
- File.open(Karafka.boot_file, 'a') do |f|
24
- f << "\n#{enabler}\n"
25
- end
26
- end
27
-
28
- puts
29
- puts("Installation #{green('completed')}. Have fun!")
30
- puts
31
- else
32
- raise NotImplementedError, "#{ARGV[0]} is not supported"
33
- end
8
+ ::Karafka::Web::Cli.start
data/karafka-web.gemspec CHANGED
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
18
18
 
19
19
  spec.add_dependency 'erubi', '~> 1.4'
20
20
  spec.add_dependency 'karafka', '>= 2.0.29', '< 3.0.0'
21
+ spec.add_dependency 'karafka-core', '>= 2.0.10', '< 3.0.0'
21
22
  spec.add_dependency 'roda', '~> 3.63'
22
23
  spec.add_dependency 'tilt', '~> 2.0'
23
24
 
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Karafka
4
+ module Web
5
+ # Karafka itself depends on Thor, so we can use it
6
+ class Cli < Thor
7
+ include ::Karafka::Helpers::Colorize
8
+
9
+ # Code that is needed in the `karafka.rb` to connect Web UI to Karafka
10
+ ENABLER_CODE = 'Karafka::Web.enable!'
11
+
12
+ private_constant :ENABLER_CODE
13
+
14
+ package_name 'Karafka Web'
15
+
16
+ desc 'install', 'Installs the Web UI'
17
+ method_option(
18
+ :replication_factor,
19
+ desc: 'Replication factor for created topics',
20
+ default: 1,
21
+ type: :numeric
22
+ )
23
+ # Installs Karafka Web
24
+ def install
25
+ puts
26
+ puts 'Installing Karafka Web UI...'
27
+ puts
28
+ puts 'Creating necessary topics and populating state data...'
29
+
30
+ Karafka::Web::Installer.new.bootstrap!(replication_factor: options[:replication_factor])
31
+
32
+ puts 'Updating the Karafka boot file...'
33
+
34
+ if File.read(Karafka.boot_file).include?(ENABLER_CODE)
35
+ puts "Web UI #{green('already')} installed."
36
+ else
37
+ File.open(Karafka.boot_file, 'a') do |f|
38
+ f << "\n#{ENABLER_CODE}\n"
39
+ end
40
+ end
41
+
42
+ puts
43
+ puts("Installation #{green('completed')}. Have fun!")
44
+ puts
45
+ end
46
+
47
+ desc 'reset', 'Resets the Web UI by removing all the Web topics and creating them again'
48
+ # Resets Karafka Web
49
+ def reset
50
+ puts
51
+ puts 'Resetting Karafka Web UI...'
52
+ Karafka::Web::Installer.new.reset!
53
+ puts
54
+ puts("Resetting #{green('completed')}. Have fun!")
55
+ puts
56
+ end
57
+
58
+ desc 'uninstall', 'Removes all the Web UI topics and the enabled code'
59
+ # Uninstalls Karafka Web
60
+ def uninstall
61
+ puts
62
+ puts 'Uninstalling Karafka Web UI...'
63
+ Karafka::Web::Installer.new.uninstall!
64
+
65
+ puts 'Updating the Karafka boot file...'
66
+
67
+ karafka_rb = File.readlines(Karafka.boot_file)
68
+ if karafka_rb.any? { |line| line.include?(ENABLER_CODE) }
69
+ karafka_rb.delete_if { |line| line.include?(ENABLER_CODE) }
70
+
71
+ File.write(Karafka.boot_file, karafka_rb.join)
72
+ end
73
+
74
+ puts
75
+ puts("Uninstalling #{green('completed')}. Goodbye!")
76
+ puts
77
+ end
78
+ end
79
+ end
80
+ end
@@ -13,6 +13,30 @@ module Karafka
13
13
  bootstrap_state!
14
14
  end
15
15
 
16
+ # Removes all the Karafka topics and creates them again with the same replication factor
17
+ def reset!
18
+ states_topic = ::Karafka::Web.config.topics.consumers.states
19
+ replication_factor = ::Karafka::Admin
20
+ .cluster_info
21
+ .topics
22
+ .find { |topic| topic[:topic_name] == states_topic }
23
+ .fetch(:partitions)
24
+ .first
25
+ .fetch(:replica_count)
26
+
27
+ uninstall!
28
+ bootstrap!(replication_factor: replication_factor)
29
+ end
30
+
31
+ # Removes all the Karafka Web topics
32
+ def uninstall!
33
+ [
34
+ ::Karafka::Web.config.topics.consumers.states,
35
+ ::Karafka::Web.config.topics.consumers.reports,
36
+ ::Karafka::Web.config.topics.errors
37
+ ].each { |topic_name| ::Karafka::Admin.delete_topic(topic_name) }
38
+ end
39
+
16
40
  # Adds the extra needed consumer group, topics and routes for Web UI to be able to operate
17
41
  def enable!
18
42
  ::Karafka::App.routes.draw do
@@ -61,36 +85,49 @@ module Karafka
61
85
  #
62
86
  # @param replication_factor [Integer]
63
87
  def bootstrap_topics!(replication_factor = 1)
64
- # This topic needs to have one partition
65
- ::Karafka::Admin.create_topic(
66
- ::Karafka::Web.config.topics.consumers.states,
67
- 1,
68
- replication_factor,
69
- # We care only about the most recent state, previous are irrelevant
70
- { 'cleanup.policy': 'compact' }
71
- )
88
+ existing_topics = ::Karafka::Admin.cluster_info.topics.map { |topic| topic[:topic_name] }
72
89
 
73
- # This topic needs to have one partition
74
- ::Karafka::Admin.create_topic(
75
- ::Karafka::Web.config.topics.consumers.reports,
76
- 1,
77
- replication_factor,
78
- # We do not need to to store this data for longer than 7 days as this data is only used
79
- # to materialize the end states
80
- # On the other hand we do not want to have it really short-living because in case of a
81
- # consumer crash, we may want to use this info to catch up and backfill the state
82
- { 'retention.ms': 7 * 24 * 60 * 60 * 1_000 }
83
- )
90
+ consumers_states_topic = ::Karafka::Web.config.topics.consumers.states
91
+ consumers_reports_topic = ::Karafka::Web.config.topics.consumers.reports
92
+ errors_topic = ::Karafka::Web.config.topics.errors
84
93
 
85
- # All the errors will be dispatched here
86
- # This topic can have multiple partitions but we go with one by default. A single Ruby
87
- # process should not crash that often and if there is an expectation of a higher volume
88
- # of errors, this can be changed by the end user
89
- ::Karafka::Admin.create_topic(
90
- ::Karafka::Web.config.topics.errors,
91
- 1,
92
- replication_factor
93
- )
94
+ # Create only if needed
95
+ unless existing_topics.include?(consumers_states_topic)
96
+ # This topic needs to have one partition
97
+ ::Karafka::Admin.create_topic(
98
+ consumers_states_topic,
99
+ 1,
100
+ replication_factor,
101
+ # We care only about the most recent state, previous are irrelevant
102
+ { 'cleanup.policy': 'compact' }
103
+ )
104
+ end
105
+
106
+ unless existing_topics.include?(consumers_reports_topic)
107
+ # This topic needs to have one partition
108
+ ::Karafka::Admin.create_topic(
109
+ consumers_reports_topic,
110
+ 1,
111
+ replication_factor,
112
+ # We do not need to to store this data for longer than 7 days as this data is only used
113
+ # to materialize the end states
114
+ # On the other hand we do not want to have it really short-living because in case of a
115
+ # consumer crash, we may want to use this info to catch up and backfill the state
116
+ { 'retention.ms': 7 * 24 * 60 * 60 * 1_000 }
117
+ )
118
+ end
119
+
120
+ unless existing_topics.include?(errors_topic)
121
+ # All the errors will be dispatched here
122
+ # This topic can have multiple partitions but we go with one by default. A single Ruby
123
+ # process should not crash that often and if there is an expectation of a higher volume
124
+ # of errors, this can be changed by the end user
125
+ ::Karafka::Admin.create_topic(
126
+ errors_topic,
127
+ 1,
128
+ replication_factor
129
+ )
130
+ end
94
131
 
95
132
  bootstrap_state!
96
133
  end
@@ -5,7 +5,15 @@
5
5
  <td>
6
6
  <%= partition_id %>
7
7
  </td>
8
- <td><%= details[:lag_stored] %></td>
8
+ <td>
9
+ <% if details[:lag_stored].to_i < 0 %>
10
+ <span class="badge bg-secondary" title="Not available until first offset commit">
11
+ N/A
12
+ </span>
13
+ <% else %>
14
+ <%= details[:lag_stored] %>
15
+ <% end %>
16
+ </td>
9
17
  <td>
10
18
  <span class="badge <%= lag_trend_bg(details[:lag_stored_d]) %>">
11
19
  <%= details[:lag_stored_d] %>
@@ -15,7 +23,13 @@
15
23
  <%= details[:committed_offset] %>
16
24
  </td>
17
25
  <td>
18
- <%= details[:stored_offset] %>
26
+ <% if details[:stored_offset].to_i < 0 %>
27
+ <span class="badge bg-secondary" title="Not available until first offset commit">
28
+ N/A
29
+ </span>
30
+ <% else %>
31
+ <%= details[:stored_offset] %>
32
+ <% end %>
19
33
  </td>
20
34
  <td>
21
35
  <span class="badge <%= kafka_state_bg(details[:fetch_state]) %> mt-1 mb-1">
@@ -3,6 +3,6 @@
3
3
  module Karafka
4
4
  module Web
5
5
  # Current gem version
6
- VERSION = '0.1.1'
6
+ VERSION = '0.1.3'
7
7
  end
8
8
  end
data/lib/karafka/web.rb CHANGED
@@ -27,12 +27,6 @@ module Karafka
27
27
  Config.config
28
28
  end
29
29
 
30
- # Creates all the needed topics for the admin UI to work and populates initial (empty) set
31
- # of data, so the UI will work even when no Karafka servers are started
32
- def bootstrap!
33
- Installer.new.bootstrap!
34
- end
35
-
36
30
  # Activates all the needed routing and sets up listener, etc
37
31
  # This needs to run **after** the optional configuration of the web component
38
32
  def enable!
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: karafka-web
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maciej Mensfeld
@@ -35,7 +35,7 @@ cert_chain:
35
35
  Qf04B9ceLUaC4fPVEz10FyobjaFoY4i32xRto3XnrzeAgfEe4swLq8bQsR3w/EF3
36
36
  MGU0FeSV2Yj7Xc2x/7BzLK8xQn5l7Yy75iPF+KP3vVmDHnNl
37
37
  -----END CERTIFICATE-----
38
- date: 2023-01-30 00:00:00.000000000 Z
38
+ date: 2023-02-14 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: erubi
@@ -71,6 +71,26 @@ dependencies:
71
71
  - - "<"
72
72
  - !ruby/object:Gem::Version
73
73
  version: 3.0.0
74
+ - !ruby/object:Gem::Dependency
75
+ name: karafka-core
76
+ requirement: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: 2.0.10
81
+ - - "<"
82
+ - !ruby/object:Gem::Version
83
+ version: 3.0.0
84
+ type: :runtime
85
+ prerelease: false
86
+ version_requirements: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: 2.0.10
91
+ - - "<"
92
+ - !ruby/object:Gem::Version
93
+ version: 3.0.0
74
94
  - !ruby/object:Gem::Dependency
75
95
  name: roda
76
96
  requirement: !ruby/object:Gem::Requirement
@@ -128,6 +148,7 @@ files:
128
148
  - ".github/ISSUE_TEMPLATE/feature_request.md"
129
149
  - ".github/workflows/ci.yml"
130
150
  - ".gitignore"
151
+ - ".rspec"
131
152
  - ".ruby-gemset"
132
153
  - ".ruby-version"
133
154
  - CHANGELOG.md
@@ -142,6 +163,7 @@ files:
142
163
  - karafka-web.gemspec
143
164
  - lib/karafka/web.rb
144
165
  - lib/karafka/web/app.rb
166
+ - lib/karafka/web/cli.rb
145
167
  - lib/karafka/web/config.rb
146
168
  - lib/karafka/web/deserializer.rb
147
169
  - lib/karafka/web/errors.rb
@@ -321,7 +343,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
321
343
  - !ruby/object:Gem::Version
322
344
  version: '0'
323
345
  requirements: []
324
- rubygems_version: 3.4.1
346
+ rubygems_version: 3.4.6
325
347
  signing_key:
326
348
  specification_version: 4
327
349
  summary: Karafka ecosystem Web UI interface
metadata.gz.sig CHANGED
Binary file