karafka 2.3.4 → 2.4.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/.github/workflows/ci.yml +12 -38
  4. data/CHANGELOG.md +56 -2
  5. data/Gemfile +6 -3
  6. data/Gemfile.lock +25 -23
  7. data/bin/integrations +1 -1
  8. data/config/locales/errors.yml +21 -2
  9. data/config/locales/pro_errors.yml +16 -1
  10. data/karafka.gemspec +4 -2
  11. data/lib/active_job/queue_adapters/karafka_adapter.rb +2 -0
  12. data/lib/karafka/admin/configs/config.rb +81 -0
  13. data/lib/karafka/admin/configs/resource.rb +88 -0
  14. data/lib/karafka/admin/configs.rb +103 -0
  15. data/lib/karafka/admin.rb +201 -100
  16. data/lib/karafka/base_consumer.rb +2 -2
  17. data/lib/karafka/cli/info.rb +9 -7
  18. data/lib/karafka/cli/server.rb +7 -7
  19. data/lib/karafka/cli/topics/align.rb +109 -0
  20. data/lib/karafka/cli/topics/base.rb +66 -0
  21. data/lib/karafka/cli/topics/create.rb +35 -0
  22. data/lib/karafka/cli/topics/delete.rb +30 -0
  23. data/lib/karafka/cli/topics/migrate.rb +31 -0
  24. data/lib/karafka/cli/topics/plan.rb +169 -0
  25. data/lib/karafka/cli/topics/repartition.rb +41 -0
  26. data/lib/karafka/cli/topics/reset.rb +18 -0
  27. data/lib/karafka/cli/topics.rb +13 -123
  28. data/lib/karafka/connection/client.rb +55 -37
  29. data/lib/karafka/connection/listener.rb +22 -17
  30. data/lib/karafka/connection/proxy.rb +93 -4
  31. data/lib/karafka/connection/status.rb +14 -2
  32. data/lib/karafka/contracts/config.rb +14 -1
  33. data/lib/karafka/contracts/topic.rb +1 -1
  34. data/lib/karafka/deserializers/headers.rb +15 -0
  35. data/lib/karafka/deserializers/key.rb +15 -0
  36. data/lib/karafka/deserializers/payload.rb +16 -0
  37. data/lib/karafka/embedded.rb +2 -0
  38. data/lib/karafka/helpers/async.rb +5 -2
  39. data/lib/karafka/helpers/colorize.rb +6 -0
  40. data/lib/karafka/instrumentation/callbacks/oauthbearer_token_refresh.rb +29 -0
  41. data/lib/karafka/instrumentation/logger_listener.rb +23 -3
  42. data/lib/karafka/instrumentation/notifications.rb +10 -0
  43. data/lib/karafka/instrumentation/vendors/appsignal/client.rb +16 -2
  44. data/lib/karafka/instrumentation/vendors/kubernetes/liveness_listener.rb +20 -0
  45. data/lib/karafka/messages/batch_metadata.rb +1 -1
  46. data/lib/karafka/messages/builders/batch_metadata.rb +1 -1
  47. data/lib/karafka/messages/builders/message.rb +10 -6
  48. data/lib/karafka/messages/message.rb +2 -1
  49. data/lib/karafka/messages/metadata.rb +20 -4
  50. data/lib/karafka/messages/parser.rb +1 -1
  51. data/lib/karafka/pro/base_consumer.rb +12 -23
  52. data/lib/karafka/pro/encryption/cipher.rb +7 -3
  53. data/lib/karafka/pro/encryption/contracts/config.rb +1 -0
  54. data/lib/karafka/pro/encryption/errors.rb +4 -1
  55. data/lib/karafka/pro/encryption/messages/middleware.rb +13 -11
  56. data/lib/karafka/pro/encryption/messages/parser.rb +22 -20
  57. data/lib/karafka/pro/encryption/setup/config.rb +5 -0
  58. data/lib/karafka/pro/iterator/expander.rb +2 -1
  59. data/lib/karafka/pro/iterator/tpl_builder.rb +38 -0
  60. data/lib/karafka/pro/iterator.rb +28 -2
  61. data/lib/karafka/pro/loader.rb +3 -0
  62. data/lib/karafka/pro/processing/coordinator.rb +15 -2
  63. data/lib/karafka/pro/processing/expansions_selector.rb +2 -0
  64. data/lib/karafka/pro/processing/jobs_queue.rb +122 -5
  65. data/lib/karafka/pro/processing/periodic_job/consumer.rb +67 -0
  66. data/lib/karafka/pro/processing/piping/consumer.rb +126 -0
  67. data/lib/karafka/pro/processing/strategies/aj/dlq_ftr_lrj_mom.rb +1 -1
  68. data/lib/karafka/pro/processing/strategies/aj/dlq_ftr_lrj_mom_vp.rb +1 -1
  69. data/lib/karafka/pro/processing/strategies/aj/dlq_ftr_mom.rb +1 -1
  70. data/lib/karafka/pro/processing/strategies/aj/dlq_ftr_mom_vp.rb +1 -1
  71. data/lib/karafka/pro/processing/strategies/aj/dlq_lrj_mom.rb +1 -1
  72. data/lib/karafka/pro/processing/strategies/aj/dlq_lrj_mom_vp.rb +1 -1
  73. data/lib/karafka/pro/processing/strategies/aj/dlq_mom.rb +1 -1
  74. data/lib/karafka/pro/processing/strategies/aj/dlq_mom_vp.rb +1 -1
  75. data/lib/karafka/pro/processing/strategies/aj/lrj_mom_vp.rb +2 -0
  76. data/lib/karafka/pro/processing/strategies/default.rb +5 -1
  77. data/lib/karafka/pro/processing/strategies/dlq/default.rb +21 -5
  78. data/lib/karafka/pro/processing/strategies/lrj/default.rb +2 -0
  79. data/lib/karafka/pro/processing/strategies/lrj/mom.rb +2 -0
  80. data/lib/karafka/pro/processing/subscription_groups_coordinator.rb +52 -0
  81. data/lib/karafka/pro/routing/features/direct_assignments/config.rb +27 -0
  82. data/lib/karafka/pro/routing/features/direct_assignments/contracts/consumer_group.rb +53 -0
  83. data/lib/karafka/pro/routing/features/direct_assignments/contracts/topic.rb +108 -0
  84. data/lib/karafka/pro/routing/features/direct_assignments/subscription_group.rb +77 -0
  85. data/lib/karafka/pro/routing/features/direct_assignments/topic.rb +69 -0
  86. data/lib/karafka/pro/routing/features/direct_assignments.rb +25 -0
  87. data/lib/karafka/pro/routing/features/patterns/builder.rb +1 -1
  88. data/lib/karafka/pro/routing/features/swarm/contracts/routing.rb +76 -0
  89. data/lib/karafka/pro/routing/features/swarm/contracts/topic.rb +16 -5
  90. data/lib/karafka/pro/routing/features/swarm/topic.rb +25 -2
  91. data/lib/karafka/pro/routing/features/swarm.rb +11 -0
  92. data/lib/karafka/pro/swarm/liveness_listener.rb +20 -0
  93. data/lib/karafka/processing/coordinator.rb +17 -8
  94. data/lib/karafka/processing/coordinators_buffer.rb +5 -2
  95. data/lib/karafka/processing/executor.rb +6 -2
  96. data/lib/karafka/processing/executors_buffer.rb +5 -2
  97. data/lib/karafka/processing/jobs_queue.rb +9 -4
  98. data/lib/karafka/processing/strategies/aj_dlq_mom.rb +1 -1
  99. data/lib/karafka/processing/strategies/default.rb +7 -1
  100. data/lib/karafka/processing/strategies/dlq.rb +17 -2
  101. data/lib/karafka/processing/workers_batch.rb +4 -1
  102. data/lib/karafka/routing/builder.rb +6 -2
  103. data/lib/karafka/routing/consumer_group.rb +2 -1
  104. data/lib/karafka/routing/features/dead_letter_queue/config.rb +5 -0
  105. data/lib/karafka/routing/features/dead_letter_queue/contracts/topic.rb +8 -0
  106. data/lib/karafka/routing/features/dead_letter_queue/topic.rb +10 -2
  107. data/lib/karafka/routing/features/deserializers/config.rb +18 -0
  108. data/lib/karafka/routing/features/deserializers/contracts/topic.rb +31 -0
  109. data/lib/karafka/routing/features/deserializers/topic.rb +51 -0
  110. data/lib/karafka/routing/features/deserializers.rb +11 -0
  111. data/lib/karafka/routing/proxy.rb +9 -14
  112. data/lib/karafka/routing/router.rb +11 -2
  113. data/lib/karafka/routing/subscription_group.rb +9 -1
  114. data/lib/karafka/routing/topic.rb +0 -1
  115. data/lib/karafka/runner.rb +1 -1
  116. data/lib/karafka/setup/config.rb +50 -9
  117. data/lib/karafka/status.rb +7 -8
  118. data/lib/karafka/swarm/supervisor.rb +16 -2
  119. data/lib/karafka/templates/karafka.rb.erb +28 -1
  120. data/lib/karafka/version.rb +1 -1
  121. data.tar.gz.sig +0 -0
  122. metadata +38 -12
  123. metadata.gz.sig +0 -0
  124. data/lib/karafka/routing/consumer_mapper.rb +0 -23
  125. data/lib/karafka/serialization/json/deserializer.rb +0 -19
  126. data/lib/karafka/time_trackers/partition_usage.rb +0 -56
@@ -23,6 +23,15 @@ module Karafka
23
23
  process: %i[internal process]
24
24
  )
25
25
 
26
+ # How long extra should we wait on shutdown before forceful termination
27
+ # We add this time because we send signals and it always can take a bit of time for them
28
+ # to reach out nodes and be processed to start the shutdown flow. Because of that and
29
+ # because we always want to give all nodes all the time of `shutdown_timeout` they are
30
+ # expected to have, we add this just to compensate.
31
+ SHUTDOWN_GRACE_PERIOD = 1_000
32
+
33
+ private_constant :SHUTDOWN_GRACE_PERIOD
34
+
26
35
  def initialize
27
36
  @mutex = Mutex.new
28
37
  @queue = Processing::TimedQueue.new
@@ -70,7 +79,10 @@ module Karafka
70
79
  type: 'swarm.supervisor.error'
71
80
  )
72
81
 
73
- @nodes.terminate
82
+ manager.terminate
83
+ manager.cleanup
84
+
85
+ raise e
74
86
  end
75
87
 
76
88
  private
@@ -102,10 +114,12 @@ module Karafka
102
114
 
103
115
  manager.stop
104
116
 
117
+ total_shutdown_timeout = shutdown_timeout + SHUTDOWN_GRACE_PERIOD
118
+
105
119
  # We check from time to time (for the timeout period) if all the threads finished
106
120
  # their work and if so, we can just return and normal shutdown process will take place
107
121
  # We divide it by 1000 because we use time in ms.
108
- ((shutdown_timeout / 1_000) * (1 / supervision_sleep)).to_i.times do
122
+ ((total_shutdown_timeout / 1_000) * (1 / supervision_sleep)).to_i.times do
109
123
  if manager.stopped?
110
124
  manager.cleanup
111
125
  return
@@ -37,7 +37,14 @@ class KarafkaApp < Karafka::App
37
37
  # interested in logging events for certain environments. Since instrumentation
38
38
  # notifications add extra boilerplate, if you want to achieve max performance,
39
39
  # listen to only what you really need for given environment.
40
- Karafka.monitor.subscribe(Karafka::Instrumentation::LoggerListener.new)
40
+ Karafka.monitor.subscribe(
41
+ Karafka::Instrumentation::LoggerListener.new(
42
+ # Karafka, when the logger is set to info producers logs each time it polls data from an
43
+ # internal messages wueue. This can be extensive, so you can turn it off by setting below
44
+ # to false.
45
+ log_polling: true
46
+ )
47
+ )
41
48
  # Karafka.monitor.subscribe(Karafka::Instrumentation::ProctitleListener.new)
42
49
 
43
50
  # This logger prints the producer development info using the Karafka logger.
@@ -52,6 +59,26 @@ class KarafkaApp < Karafka::App
52
59
  )
53
60
  )
54
61
 
62
+ # You can subscribe to all consumer related errors and record/track then that way
63
+ #
64
+ # Karafka.monitor.subscribe 'error.occurred' do |event|
65
+ # type = event[:type]
66
+ # error = event[:error]
67
+ # details = (error.backtrace || []).join("\n")
68
+ # ErrorTracker.send_error(error, type, details)
69
+ # end
70
+
71
+ # You can subscribe to all producer related errors and record/track then that way
72
+ # Please note, that producer and consumer have their own notifications pipeline so you need to
73
+ # setup error tracking independently for each of them
74
+ #
75
+ # Karafka.producer.monitor.subscribe('error.occurred') do |event|
76
+ # type = event[:type]
77
+ # error = event[:error]
78
+ # details = (error.backtrace || []).join("\n")
79
+ # ErrorTracker.send_error(error, type, details)
80
+ # end
81
+
55
82
  routes.draw do
56
83
  <% if rails? -%>
57
84
  # Uncomment this if you use Karafka with ActiveJob
@@ -3,5 +3,5 @@
3
3
  # Main module namespace
4
4
  module Karafka
5
5
  # Current Karafka version
6
- VERSION = '2.3.4'
6
+ VERSION = '2.4.0.beta1'
7
7
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: karafka
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.4
4
+ version: 2.4.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maciej Mensfeld
@@ -35,7 +35,7 @@ cert_chain:
35
35
  AnG1dJU+yL2BK7vaVytLTstJME5mepSZ46qqIJXMuWob/YPDmVaBF39TDSG9e34s
36
36
  msG3BiCqgOgHAnL23+CN3Rt8MsuRfEtoTKpJVcCfoEoNHOkc
37
37
  -----END CERTIFICATE-----
38
- date: 2024-04-11 00:00:00.000000000 Z
38
+ date: 2024-04-10 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: karafka-core
@@ -43,27 +43,27 @@ dependencies:
43
43
  requirements:
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
- version: 2.3.0
46
+ version: 2.4.0.rc1
47
47
  - - "<"
48
48
  - !ruby/object:Gem::Version
49
- version: 2.4.0
49
+ version: 2.5.0
50
50
  type: :runtime
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
54
  - - ">="
55
55
  - !ruby/object:Gem::Version
56
- version: 2.3.0
56
+ version: 2.4.0.rc1
57
57
  - - "<"
58
58
  - !ruby/object:Gem::Version
59
- version: 2.4.0
59
+ version: 2.5.0
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: waterdrop
62
62
  requirement: !ruby/object:Gem::Requirement
63
63
  requirements:
64
64
  - - ">="
65
65
  - !ruby/object:Gem::Version
66
- version: 2.6.12
66
+ version: 2.7.0.rc1
67
67
  - - "<"
68
68
  - !ruby/object:Gem::Version
69
69
  version: 3.0.0
@@ -73,7 +73,7 @@ dependencies:
73
73
  requirements:
74
74
  - - ">="
75
75
  - !ruby/object:Gem::Version
76
- version: 2.6.12
76
+ version: 2.7.0.rc1
77
77
  - - "<"
78
78
  - !ruby/object:Gem::Version
79
79
  version: 3.0.0
@@ -153,6 +153,9 @@ files:
153
153
  - lib/karafka/active_job/job_options_contract.rb
154
154
  - lib/karafka/admin.rb
155
155
  - lib/karafka/admin/acl.rb
156
+ - lib/karafka/admin/configs.rb
157
+ - lib/karafka/admin/configs/config.rb
158
+ - lib/karafka/admin/configs/resource.rb
156
159
  - lib/karafka/app.rb
157
160
  - lib/karafka/base_consumer.rb
158
161
  - lib/karafka/cli.rb
@@ -164,6 +167,14 @@ files:
164
167
  - lib/karafka/cli/server.rb
165
168
  - lib/karafka/cli/swarm.rb
166
169
  - lib/karafka/cli/topics.rb
170
+ - lib/karafka/cli/topics/align.rb
171
+ - lib/karafka/cli/topics/base.rb
172
+ - lib/karafka/cli/topics/create.rb
173
+ - lib/karafka/cli/topics/delete.rb
174
+ - lib/karafka/cli/topics/migrate.rb
175
+ - lib/karafka/cli/topics/plan.rb
176
+ - lib/karafka/cli/topics/repartition.rb
177
+ - lib/karafka/cli/topics/reset.rb
167
178
  - lib/karafka/connection/client.rb
168
179
  - lib/karafka/connection/conductor.rb
169
180
  - lib/karafka/connection/listener.rb
@@ -182,6 +193,9 @@ files:
182
193
  - lib/karafka/contracts/consumer_group.rb
183
194
  - lib/karafka/contracts/server_cli_options.rb
184
195
  - lib/karafka/contracts/topic.rb
196
+ - lib/karafka/deserializers/headers.rb
197
+ - lib/karafka/deserializers/key.rb
198
+ - lib/karafka/deserializers/payload.rb
185
199
  - lib/karafka/embedded.rb
186
200
  - lib/karafka/env.rb
187
201
  - lib/karafka/errors.rb
@@ -192,6 +206,7 @@ files:
192
206
  - lib/karafka/helpers/multi_delegator.rb
193
207
  - lib/karafka/instrumentation/assignments_tracker.rb
194
208
  - lib/karafka/instrumentation/callbacks/error.rb
209
+ - lib/karafka/instrumentation/callbacks/oauthbearer_token_refresh.rb
195
210
  - lib/karafka/instrumentation/callbacks/rebalance.rb
196
211
  - lib/karafka/instrumentation/callbacks/statistics.rb
197
212
  - lib/karafka/instrumentation/logger.rb
@@ -270,6 +285,8 @@ files:
270
285
  - lib/karafka/pro/processing/offset_metadata/fetcher.rb
271
286
  - lib/karafka/pro/processing/offset_metadata/listener.rb
272
287
  - lib/karafka/pro/processing/partitioner.rb
288
+ - lib/karafka/pro/processing/periodic_job/consumer.rb
289
+ - lib/karafka/pro/processing/piping/consumer.rb
273
290
  - lib/karafka/pro/processing/schedulers/base.rb
274
291
  - lib/karafka/pro/processing/schedulers/default.rb
275
292
  - lib/karafka/pro/processing/strategies.rb
@@ -323,6 +340,7 @@ files:
323
340
  - lib/karafka/pro/processing/strategies/mom/vp.rb
324
341
  - lib/karafka/pro/processing/strategies/vp/default.rb
325
342
  - lib/karafka/pro/processing/strategy_selector.rb
343
+ - lib/karafka/pro/processing/subscription_groups_coordinator.rb
326
344
  - lib/karafka/pro/routing/features/active_job.rb
327
345
  - lib/karafka/pro/routing/features/active_job/builder.rb
328
346
  - lib/karafka/pro/routing/features/base.rb
@@ -333,6 +351,12 @@ files:
333
351
  - lib/karafka/pro/routing/features/delaying/config.rb
334
352
  - lib/karafka/pro/routing/features/delaying/contracts/topic.rb
335
353
  - lib/karafka/pro/routing/features/delaying/topic.rb
354
+ - lib/karafka/pro/routing/features/direct_assignments.rb
355
+ - lib/karafka/pro/routing/features/direct_assignments/config.rb
356
+ - lib/karafka/pro/routing/features/direct_assignments/contracts/consumer_group.rb
357
+ - lib/karafka/pro/routing/features/direct_assignments/contracts/topic.rb
358
+ - lib/karafka/pro/routing/features/direct_assignments/subscription_group.rb
359
+ - lib/karafka/pro/routing/features/direct_assignments/topic.rb
336
360
  - lib/karafka/pro/routing/features/expiring.rb
337
361
  - lib/karafka/pro/routing/features/expiring/config.rb
338
362
  - lib/karafka/pro/routing/features/expiring/contracts/topic.rb
@@ -383,6 +407,7 @@ files:
383
407
  - lib/karafka/pro/routing/features/periodic_job/topic.rb
384
408
  - lib/karafka/pro/routing/features/swarm.rb
385
409
  - lib/karafka/pro/routing/features/swarm/config.rb
410
+ - lib/karafka/pro/routing/features/swarm/contracts/routing.rb
386
411
  - lib/karafka/pro/routing/features/swarm/contracts/topic.rb
387
412
  - lib/karafka/pro/routing/features/swarm/topic.rb
388
413
  - lib/karafka/pro/routing/features/throttling.rb
@@ -428,7 +453,6 @@ files:
428
453
  - lib/karafka/routing/activity_manager.rb
429
454
  - lib/karafka/routing/builder.rb
430
455
  - lib/karafka/routing/consumer_group.rb
431
- - lib/karafka/routing/consumer_mapper.rb
432
456
  - lib/karafka/routing/features/active_job.rb
433
457
  - lib/karafka/routing/features/active_job/builder.rb
434
458
  - lib/karafka/routing/features/active_job/config.rb
@@ -445,6 +469,10 @@ files:
445
469
  - lib/karafka/routing/features/declaratives/config.rb
446
470
  - lib/karafka/routing/features/declaratives/contracts/topic.rb
447
471
  - lib/karafka/routing/features/declaratives/topic.rb
472
+ - lib/karafka/routing/features/deserializers.rb
473
+ - lib/karafka/routing/features/deserializers/config.rb
474
+ - lib/karafka/routing/features/deserializers/contracts/topic.rb
475
+ - lib/karafka/routing/features/deserializers/topic.rb
448
476
  - lib/karafka/routing/features/inline_insights.rb
449
477
  - lib/karafka/routing/features/inline_insights/config.rb
450
478
  - lib/karafka/routing/features/inline_insights/contracts/topic.rb
@@ -460,7 +488,6 @@ files:
460
488
  - lib/karafka/routing/topic.rb
461
489
  - lib/karafka/routing/topics.rb
462
490
  - lib/karafka/runner.rb
463
- - lib/karafka/serialization/json/deserializer.rb
464
491
  - lib/karafka/server.rb
465
492
  - lib/karafka/setup/attributes_map.rb
466
493
  - lib/karafka/setup/config.rb
@@ -476,7 +503,6 @@ files:
476
503
  - lib/karafka/templates/example_consumer.rb.erb
477
504
  - lib/karafka/templates/karafka.rb.erb
478
505
  - lib/karafka/time_trackers/base.rb
479
- - lib/karafka/time_trackers/partition_usage.rb
480
506
  - lib/karafka/time_trackers/pause.rb
481
507
  - lib/karafka/time_trackers/poll.rb
482
508
  - lib/karafka/version.rb
@@ -502,7 +528,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
502
528
  requirements:
503
529
  - - ">="
504
530
  - !ruby/object:Gem::Version
505
- version: '0'
531
+ version: 3.0.0
506
532
  required_rubygems_version: !ruby/object:Gem::Requirement
507
533
  requirements:
508
534
  - - ">="
metadata.gz.sig CHANGED
Binary file
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Karafka
4
- module Routing
5
- # Default consumer mapper that builds consumer ids based on app id and consumer group name
6
- # Different mapper can be used in case of preexisting consumer names or for applying
7
- # other naming conventions not compatible with Karafka client_id + consumer name concept
8
- #
9
- # @example Mapper for using consumer groups without a client_id prefix
10
- # class MyMapper
11
- # def call(raw_consumer_group_name)
12
- # raw_consumer_group_name
13
- # end
14
- # end
15
- class ConsumerMapper
16
- # @param raw_consumer_group_name [String, Symbol] string or symbolized consumer group name
17
- # @return [String] remapped final consumer group name
18
- def call(raw_consumer_group_name)
19
- "#{Karafka::App.config.client_id}_#{raw_consumer_group_name}"
20
- end
21
- end
22
- end
23
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Karafka
4
- # Module for all supported by default serialization and deserialization ways.
5
- module Serialization
6
- # Namespace for json serializers and deserializers.
7
- module Json
8
- # Default Karafka Json deserializer for loading JSON data.
9
- class Deserializer
10
- # @param message [Karafka::Messages::Message] Message object that we want to deserialize
11
- # @return [Hash] hash with deserialized JSON data
12
- def call(message)
13
- # nil payload can be present for example for tombstone messages
14
- message.raw_payload.nil? ? nil : ::JSON.parse(message.raw_payload)
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,56 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Karafka
4
- module TimeTrackers
5
- # Tracker used to keep time reference when we last time dispatched any job related to a given
6
- # topic partition.
7
- #
8
- # We can use it to know when last time a job was scheduled
9
- #
10
- # @note We do not track revocation as on revocation we clear given topic partition reference
11
- # not to have a potential memory leak
12
- #
13
- # @note We do not track shutdown jobs as shutdown is finishing the process, so no time
14
- # sensitive operations remain that would use this
15
- #
16
- # @note We consider partition as active if we scheduled any job related to it within the tick
17
- # interval. This has nothing to do whether a partition is assigned.
18
- class PartitionUsage < Base
19
- # Creates new partition usage time tracker
20
- def initialize
21
- super
22
-
23
- @last_usage = Hash.new do |topics_hash, topic_name|
24
- topics_hash[topic_name] = Hash.new do |partitions_hash, partition_id|
25
- partitions_hash[partition_id] = 0
26
- end
27
- end
28
- end
29
-
30
- # @param topic [String]
31
- # @param partition [Integer]
32
- # @param interval [Integer] minimum interval
33
- # @return [Boolean] was this topic partition active
34
- def active?(topic, partition, interval)
35
- monotonic_now - @last_usage[topic][partition] < interval
36
- end
37
-
38
- # Marks usage of given partition
39
- #
40
- # @param topic [String]
41
- # @param partition [Integer]
42
- def track(topic, partition)
43
- @last_usage[topic][partition] = monotonic_now
44
- end
45
-
46
- # Clears references about given partition. Useful on revocation so we do not store old
47
- # unassigned partitions data
48
- #
49
- # @param topic [String]
50
- # @param partition [Integer]
51
- def revoke(topic, partition)
52
- @last_usage[topic].delete(partition)
53
- end
54
- end
55
- end
56
- end