karafka 1.4.4 → 2.1.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (315) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/.github/FUNDING.yml +1 -3
  4. data/.github/workflows/ci.yml +117 -36
  5. data/.rspec +4 -0
  6. data/.ruby-version +1 -1
  7. data/CHANGELOG.md +611 -578
  8. data/CONTRIBUTING.md +10 -19
  9. data/Gemfile +7 -0
  10. data/Gemfile.lock +59 -100
  11. data/LICENSE +17 -0
  12. data/LICENSE-COMM +89 -0
  13. data/LICENSE-LGPL +165 -0
  14. data/README.md +64 -66
  15. data/bin/benchmarks +85 -0
  16. data/bin/create_token +22 -0
  17. data/bin/integrations +297 -0
  18. data/bin/karafka +4 -12
  19. data/bin/rspecs +6 -0
  20. data/bin/scenario +29 -0
  21. data/bin/stress_many +13 -0
  22. data/bin/stress_one +13 -0
  23. data/bin/verify_license_integrity +37 -0
  24. data/certs/cert_chain.pem +26 -0
  25. data/certs/karafka-pro.pem +11 -0
  26. data/config/locales/errors.yml +84 -0
  27. data/config/locales/pro_errors.yml +39 -0
  28. data/docker-compose.yml +13 -3
  29. data/karafka.gemspec +27 -22
  30. data/lib/active_job/karafka.rb +17 -0
  31. data/lib/active_job/queue_adapters/karafka_adapter.rb +32 -0
  32. data/lib/karafka/active_job/consumer.rb +49 -0
  33. data/lib/karafka/active_job/current_attributes/loading.rb +36 -0
  34. data/lib/karafka/active_job/current_attributes/persistence.rb +28 -0
  35. data/lib/karafka/active_job/current_attributes.rb +42 -0
  36. data/lib/karafka/active_job/dispatcher.rb +69 -0
  37. data/lib/karafka/active_job/job_extensions.rb +34 -0
  38. data/lib/karafka/active_job/job_options_contract.rb +32 -0
  39. data/lib/karafka/admin.rb +286 -0
  40. data/lib/karafka/app.rb +47 -23
  41. data/lib/karafka/base_consumer.rb +247 -29
  42. data/lib/karafka/cli/base.rb +24 -4
  43. data/lib/karafka/cli/console.rb +13 -8
  44. data/lib/karafka/cli/info.rb +45 -10
  45. data/lib/karafka/cli/install.rb +22 -12
  46. data/lib/karafka/cli/server.rb +63 -41
  47. data/lib/karafka/cli/topics.rb +146 -0
  48. data/lib/karafka/cli.rb +4 -11
  49. data/lib/karafka/connection/client.rb +502 -89
  50. data/lib/karafka/connection/consumer_group_coordinator.rb +48 -0
  51. data/lib/karafka/connection/listener.rb +294 -38
  52. data/lib/karafka/connection/listeners_batch.rb +40 -0
  53. data/lib/karafka/connection/messages_buffer.rb +84 -0
  54. data/lib/karafka/connection/pauses_manager.rb +46 -0
  55. data/lib/karafka/connection/proxy.rb +92 -0
  56. data/lib/karafka/connection/raw_messages_buffer.rb +101 -0
  57. data/lib/karafka/connection/rebalance_manager.rb +90 -0
  58. data/lib/karafka/contracts/base.rb +17 -0
  59. data/lib/karafka/contracts/config.rb +88 -11
  60. data/lib/karafka/contracts/consumer_group.rb +32 -187
  61. data/lib/karafka/contracts/server_cli_options.rb +80 -19
  62. data/lib/karafka/contracts/topic.rb +65 -0
  63. data/lib/karafka/contracts.rb +1 -1
  64. data/lib/karafka/embedded.rb +36 -0
  65. data/lib/karafka/env.rb +46 -0
  66. data/lib/karafka/errors.rb +26 -21
  67. data/lib/karafka/helpers/async.rb +33 -0
  68. data/lib/karafka/helpers/colorize.rb +26 -0
  69. data/lib/karafka/helpers/multi_delegator.rb +2 -2
  70. data/lib/karafka/instrumentation/callbacks/error.rb +39 -0
  71. data/lib/karafka/instrumentation/callbacks/statistics.rb +51 -0
  72. data/lib/karafka/instrumentation/logger.rb +5 -9
  73. data/lib/karafka/instrumentation/logger_listener.rb +299 -0
  74. data/lib/karafka/instrumentation/monitor.rb +13 -61
  75. data/lib/karafka/instrumentation/notifications.rb +75 -0
  76. data/lib/karafka/instrumentation/proctitle_listener.rb +7 -16
  77. data/lib/karafka/instrumentation/vendors/datadog/dashboard.json +1 -0
  78. data/lib/karafka/instrumentation/vendors/datadog/logger_listener.rb +153 -0
  79. data/lib/karafka/instrumentation/vendors/datadog/metrics_listener.rb +264 -0
  80. data/lib/karafka/instrumentation/vendors/kubernetes/liveness_listener.rb +176 -0
  81. data/lib/karafka/licenser.rb +78 -0
  82. data/lib/karafka/messages/batch_metadata.rb +52 -0
  83. data/lib/karafka/messages/builders/batch_metadata.rb +40 -0
  84. data/lib/karafka/messages/builders/message.rb +36 -0
  85. data/lib/karafka/messages/builders/messages.rb +36 -0
  86. data/lib/karafka/{params/params.rb → messages/message.rb} +20 -13
  87. data/lib/karafka/messages/messages.rb +71 -0
  88. data/lib/karafka/{params → messages}/metadata.rb +4 -6
  89. data/lib/karafka/messages/parser.rb +14 -0
  90. data/lib/karafka/messages/seek.rb +12 -0
  91. data/lib/karafka/patches/rdkafka/bindings.rb +139 -0
  92. data/lib/karafka/pro/active_job/consumer.rb +47 -0
  93. data/lib/karafka/pro/active_job/dispatcher.rb +86 -0
  94. data/lib/karafka/pro/active_job/job_options_contract.rb +45 -0
  95. data/lib/karafka/pro/encryption/cipher.rb +58 -0
  96. data/lib/karafka/pro/encryption/contracts/config.rb +79 -0
  97. data/lib/karafka/pro/encryption/errors.rb +24 -0
  98. data/lib/karafka/pro/encryption/messages/middleware.rb +46 -0
  99. data/lib/karafka/pro/encryption/messages/parser.rb +56 -0
  100. data/lib/karafka/pro/encryption/setup/config.rb +48 -0
  101. data/lib/karafka/pro/encryption.rb +47 -0
  102. data/lib/karafka/pro/iterator/expander.rb +95 -0
  103. data/lib/karafka/pro/iterator/tpl_builder.rb +155 -0
  104. data/lib/karafka/pro/iterator.rb +170 -0
  105. data/lib/karafka/pro/loader.rb +102 -0
  106. data/lib/karafka/pro/performance_tracker.rb +84 -0
  107. data/lib/karafka/pro/processing/collapser.rb +62 -0
  108. data/lib/karafka/pro/processing/coordinator.rb +148 -0
  109. data/lib/karafka/pro/processing/filters/base.rb +61 -0
  110. data/lib/karafka/pro/processing/filters/delayer.rb +70 -0
  111. data/lib/karafka/pro/processing/filters/expirer.rb +51 -0
  112. data/lib/karafka/pro/processing/filters/throttler.rb +84 -0
  113. data/lib/karafka/pro/processing/filters/virtual_limiter.rb +52 -0
  114. data/lib/karafka/pro/processing/filters_applier.rb +105 -0
  115. data/lib/karafka/pro/processing/jobs/consume_non_blocking.rb +39 -0
  116. data/lib/karafka/pro/processing/jobs/revoked_non_blocking.rb +37 -0
  117. data/lib/karafka/pro/processing/jobs_builder.rb +50 -0
  118. data/lib/karafka/pro/processing/partitioner.rb +69 -0
  119. data/lib/karafka/pro/processing/scheduler.rb +75 -0
  120. data/lib/karafka/pro/processing/strategies/aj/dlq_ftr_lrj_mom.rb +70 -0
  121. data/lib/karafka/pro/processing/strategies/aj/dlq_ftr_lrj_mom_vp.rb +76 -0
  122. data/lib/karafka/pro/processing/strategies/aj/dlq_ftr_mom.rb +72 -0
  123. data/lib/karafka/pro/processing/strategies/aj/dlq_ftr_mom_vp.rb +76 -0
  124. data/lib/karafka/pro/processing/strategies/aj/dlq_lrj_mom.rb +66 -0
  125. data/lib/karafka/pro/processing/strategies/aj/dlq_lrj_mom_vp.rb +70 -0
  126. data/lib/karafka/pro/processing/strategies/aj/dlq_mom.rb +64 -0
  127. data/lib/karafka/pro/processing/strategies/aj/dlq_mom_vp.rb +69 -0
  128. data/lib/karafka/pro/processing/strategies/aj/ftr_lrj_mom.rb +38 -0
  129. data/lib/karafka/pro/processing/strategies/aj/ftr_lrj_mom_vp.rb +66 -0
  130. data/lib/karafka/pro/processing/strategies/aj/ftr_mom.rb +38 -0
  131. data/lib/karafka/pro/processing/strategies/aj/ftr_mom_vp.rb +58 -0
  132. data/lib/karafka/pro/processing/strategies/aj/lrj_mom.rb +37 -0
  133. data/lib/karafka/pro/processing/strategies/aj/lrj_mom_vp.rb +82 -0
  134. data/lib/karafka/pro/processing/strategies/aj/mom.rb +36 -0
  135. data/lib/karafka/pro/processing/strategies/aj/mom_vp.rb +52 -0
  136. data/lib/karafka/pro/processing/strategies/base.rb +26 -0
  137. data/lib/karafka/pro/processing/strategies/default.rb +105 -0
  138. data/lib/karafka/pro/processing/strategies/dlq/default.rb +131 -0
  139. data/lib/karafka/pro/processing/strategies/dlq/ftr.rb +61 -0
  140. data/lib/karafka/pro/processing/strategies/dlq/ftr_lrj.rb +75 -0
  141. data/lib/karafka/pro/processing/strategies/dlq/ftr_lrj_mom.rb +71 -0
  142. data/lib/karafka/pro/processing/strategies/dlq/ftr_lrj_mom_vp.rb +43 -0
  143. data/lib/karafka/pro/processing/strategies/dlq/ftr_lrj_vp.rb +41 -0
  144. data/lib/karafka/pro/processing/strategies/dlq/ftr_mom.rb +69 -0
  145. data/lib/karafka/pro/processing/strategies/dlq/ftr_mom_vp.rb +41 -0
  146. data/lib/karafka/pro/processing/strategies/dlq/ftr_vp.rb +40 -0
  147. data/lib/karafka/pro/processing/strategies/dlq/lrj.rb +64 -0
  148. data/lib/karafka/pro/processing/strategies/dlq/lrj_mom.rb +65 -0
  149. data/lib/karafka/pro/processing/strategies/dlq/lrj_mom_vp.rb +36 -0
  150. data/lib/karafka/pro/processing/strategies/dlq/lrj_vp.rb +39 -0
  151. data/lib/karafka/pro/processing/strategies/dlq/mom.rb +68 -0
  152. data/lib/karafka/pro/processing/strategies/dlq/mom_vp.rb +37 -0
  153. data/lib/karafka/pro/processing/strategies/dlq/vp.rb +40 -0
  154. data/lib/karafka/pro/processing/strategies/ftr/default.rb +111 -0
  155. data/lib/karafka/pro/processing/strategies/ftr/vp.rb +40 -0
  156. data/lib/karafka/pro/processing/strategies/lrj/default.rb +87 -0
  157. data/lib/karafka/pro/processing/strategies/lrj/ftr.rb +69 -0
  158. data/lib/karafka/pro/processing/strategies/lrj/ftr_mom.rb +67 -0
  159. data/lib/karafka/pro/processing/strategies/lrj/ftr_mom_vp.rb +40 -0
  160. data/lib/karafka/pro/processing/strategies/lrj/ftr_vp.rb +39 -0
  161. data/lib/karafka/pro/processing/strategies/lrj/mom.rb +82 -0
  162. data/lib/karafka/pro/processing/strategies/lrj/mom_vp.rb +38 -0
  163. data/lib/karafka/pro/processing/strategies/lrj/vp.rb +36 -0
  164. data/lib/karafka/pro/processing/strategies/mom/default.rb +46 -0
  165. data/lib/karafka/pro/processing/strategies/mom/ftr.rb +53 -0
  166. data/lib/karafka/pro/processing/strategies/mom/ftr_vp.rb +37 -0
  167. data/lib/karafka/pro/processing/strategies/mom/vp.rb +35 -0
  168. data/lib/karafka/pro/processing/strategies/vp/default.rb +104 -0
  169. data/lib/karafka/pro/processing/strategies.rb +22 -0
  170. data/lib/karafka/pro/processing/strategy_selector.rb +84 -0
  171. data/lib/karafka/pro/processing/virtual_offset_manager.rb +147 -0
  172. data/lib/karafka/pro/routing/features/base.rb +24 -0
  173. data/lib/karafka/pro/routing/features/dead_letter_queue/contract.rb +50 -0
  174. data/lib/karafka/pro/routing/features/dead_letter_queue.rb +27 -0
  175. data/lib/karafka/pro/routing/features/delaying/config.rb +27 -0
  176. data/lib/karafka/pro/routing/features/delaying/contract.rb +38 -0
  177. data/lib/karafka/pro/routing/features/delaying/topic.rb +59 -0
  178. data/lib/karafka/pro/routing/features/delaying.rb +29 -0
  179. data/lib/karafka/pro/routing/features/expiring/config.rb +27 -0
  180. data/lib/karafka/pro/routing/features/expiring/contract.rb +38 -0
  181. data/lib/karafka/pro/routing/features/expiring/topic.rb +59 -0
  182. data/lib/karafka/pro/routing/features/expiring.rb +27 -0
  183. data/lib/karafka/pro/routing/features/filtering/config.rb +40 -0
  184. data/lib/karafka/pro/routing/features/filtering/contract.rb +41 -0
  185. data/lib/karafka/pro/routing/features/filtering/topic.rb +51 -0
  186. data/lib/karafka/pro/routing/features/filtering.rb +27 -0
  187. data/lib/karafka/pro/routing/features/long_running_job/config.rb +28 -0
  188. data/lib/karafka/pro/routing/features/long_running_job/contract.rb +37 -0
  189. data/lib/karafka/pro/routing/features/long_running_job/topic.rb +42 -0
  190. data/lib/karafka/pro/routing/features/long_running_job.rb +28 -0
  191. data/lib/karafka/pro/routing/features/pausing/contract.rb +48 -0
  192. data/lib/karafka/pro/routing/features/pausing/topic.rb +44 -0
  193. data/lib/karafka/pro/routing/features/pausing.rb +25 -0
  194. data/lib/karafka/pro/routing/features/throttling/config.rb +32 -0
  195. data/lib/karafka/pro/routing/features/throttling/contract.rb +41 -0
  196. data/lib/karafka/pro/routing/features/throttling/topic.rb +69 -0
  197. data/lib/karafka/pro/routing/features/throttling.rb +30 -0
  198. data/lib/karafka/pro/routing/features/virtual_partitions/config.rb +30 -0
  199. data/lib/karafka/pro/routing/features/virtual_partitions/contract.rb +52 -0
  200. data/lib/karafka/pro/routing/features/virtual_partitions/topic.rb +56 -0
  201. data/lib/karafka/pro/routing/features/virtual_partitions.rb +27 -0
  202. data/lib/karafka/pro.rb +13 -0
  203. data/lib/karafka/process.rb +24 -8
  204. data/lib/karafka/processing/coordinator.rb +181 -0
  205. data/lib/karafka/processing/coordinators_buffer.rb +62 -0
  206. data/lib/karafka/processing/executor.rb +148 -0
  207. data/lib/karafka/processing/executors_buffer.rb +72 -0
  208. data/lib/karafka/processing/jobs/base.rb +55 -0
  209. data/lib/karafka/processing/jobs/consume.rb +45 -0
  210. data/lib/karafka/processing/jobs/idle.rb +24 -0
  211. data/lib/karafka/processing/jobs/revoked.rb +22 -0
  212. data/lib/karafka/processing/jobs/shutdown.rb +23 -0
  213. data/lib/karafka/processing/jobs_builder.rb +28 -0
  214. data/lib/karafka/processing/jobs_queue.rb +150 -0
  215. data/lib/karafka/processing/partitioner.rb +24 -0
  216. data/lib/karafka/processing/result.rb +42 -0
  217. data/lib/karafka/processing/scheduler.rb +22 -0
  218. data/lib/karafka/processing/strategies/aj_dlq_mom.rb +44 -0
  219. data/lib/karafka/processing/strategies/aj_mom.rb +21 -0
  220. data/lib/karafka/processing/strategies/base.rb +52 -0
  221. data/lib/karafka/processing/strategies/default.rb +158 -0
  222. data/lib/karafka/processing/strategies/dlq.rb +88 -0
  223. data/lib/karafka/processing/strategies/dlq_mom.rb +49 -0
  224. data/lib/karafka/processing/strategies/mom.rb +29 -0
  225. data/lib/karafka/processing/strategy_selector.rb +47 -0
  226. data/lib/karafka/processing/worker.rb +93 -0
  227. data/lib/karafka/processing/workers_batch.rb +27 -0
  228. data/lib/karafka/railtie.rb +125 -0
  229. data/lib/karafka/routing/activity_manager.rb +84 -0
  230. data/lib/karafka/routing/builder.rb +34 -23
  231. data/lib/karafka/routing/consumer_group.rb +47 -21
  232. data/lib/karafka/routing/consumer_mapper.rb +1 -12
  233. data/lib/karafka/routing/features/active_job/builder.rb +33 -0
  234. data/lib/karafka/routing/features/active_job/config.rb +15 -0
  235. data/lib/karafka/routing/features/active_job/contract.rb +41 -0
  236. data/lib/karafka/routing/features/active_job/topic.rb +33 -0
  237. data/lib/karafka/routing/features/active_job.rb +13 -0
  238. data/lib/karafka/routing/features/base/expander.rb +53 -0
  239. data/lib/karafka/routing/features/base.rb +34 -0
  240. data/lib/karafka/routing/features/dead_letter_queue/config.rb +19 -0
  241. data/lib/karafka/routing/features/dead_letter_queue/contract.rb +42 -0
  242. data/lib/karafka/routing/features/dead_letter_queue/topic.rb +41 -0
  243. data/lib/karafka/routing/features/dead_letter_queue.rb +16 -0
  244. data/lib/karafka/routing/features/declaratives/config.rb +18 -0
  245. data/lib/karafka/routing/features/declaratives/contract.rb +30 -0
  246. data/lib/karafka/routing/features/declaratives/topic.rb +44 -0
  247. data/lib/karafka/routing/features/declaratives.rb +14 -0
  248. data/lib/karafka/routing/features/manual_offset_management/config.rb +15 -0
  249. data/lib/karafka/routing/features/manual_offset_management/contract.rb +24 -0
  250. data/lib/karafka/routing/features/manual_offset_management/topic.rb +35 -0
  251. data/lib/karafka/routing/features/manual_offset_management.rb +18 -0
  252. data/lib/karafka/routing/proxy.rb +18 -20
  253. data/lib/karafka/routing/router.rb +28 -3
  254. data/lib/karafka/routing/subscription_group.rb +91 -0
  255. data/lib/karafka/routing/subscription_groups_builder.rb +58 -0
  256. data/lib/karafka/routing/topic.rb +77 -24
  257. data/lib/karafka/routing/topics.rb +46 -0
  258. data/lib/karafka/runner.rb +52 -0
  259. data/lib/karafka/serialization/json/deserializer.rb +7 -15
  260. data/lib/karafka/server.rb +108 -37
  261. data/lib/karafka/setup/attributes_map.rb +347 -0
  262. data/lib/karafka/setup/config.rb +183 -179
  263. data/lib/karafka/status.rb +54 -7
  264. data/lib/karafka/templates/example_consumer.rb.erb +16 -0
  265. data/lib/karafka/templates/karafka.rb.erb +34 -56
  266. data/lib/karafka/time_trackers/base.rb +14 -0
  267. data/lib/karafka/time_trackers/pause.rb +122 -0
  268. data/lib/karafka/time_trackers/poll.rb +69 -0
  269. data/lib/karafka/version.rb +1 -1
  270. data/lib/karafka.rb +90 -16
  271. data/renovate.json +6 -0
  272. data.tar.gz.sig +0 -0
  273. metadata +290 -172
  274. metadata.gz.sig +0 -0
  275. data/MIT-LICENCE +0 -18
  276. data/certs/mensfeld.pem +0 -25
  277. data/config/errors.yml +0 -41
  278. data/lib/karafka/assignment_strategies/round_robin.rb +0 -13
  279. data/lib/karafka/attributes_map.rb +0 -63
  280. data/lib/karafka/backends/inline.rb +0 -16
  281. data/lib/karafka/base_responder.rb +0 -226
  282. data/lib/karafka/cli/flow.rb +0 -48
  283. data/lib/karafka/cli/missingno.rb +0 -19
  284. data/lib/karafka/code_reloader.rb +0 -67
  285. data/lib/karafka/connection/api_adapter.rb +0 -159
  286. data/lib/karafka/connection/batch_delegator.rb +0 -55
  287. data/lib/karafka/connection/builder.rb +0 -23
  288. data/lib/karafka/connection/message_delegator.rb +0 -36
  289. data/lib/karafka/consumers/batch_metadata.rb +0 -10
  290. data/lib/karafka/consumers/callbacks.rb +0 -71
  291. data/lib/karafka/consumers/includer.rb +0 -64
  292. data/lib/karafka/consumers/responders.rb +0 -24
  293. data/lib/karafka/consumers/single_params.rb +0 -15
  294. data/lib/karafka/contracts/consumer_group_topic.rb +0 -19
  295. data/lib/karafka/contracts/responder_usage.rb +0 -54
  296. data/lib/karafka/fetcher.rb +0 -42
  297. data/lib/karafka/helpers/class_matcher.rb +0 -88
  298. data/lib/karafka/helpers/config_retriever.rb +0 -46
  299. data/lib/karafka/helpers/inflector.rb +0 -26
  300. data/lib/karafka/instrumentation/stdout_listener.rb +0 -140
  301. data/lib/karafka/params/batch_metadata.rb +0 -26
  302. data/lib/karafka/params/builders/batch_metadata.rb +0 -30
  303. data/lib/karafka/params/builders/params.rb +0 -38
  304. data/lib/karafka/params/builders/params_batch.rb +0 -25
  305. data/lib/karafka/params/params_batch.rb +0 -60
  306. data/lib/karafka/patches/ruby_kafka.rb +0 -47
  307. data/lib/karafka/persistence/client.rb +0 -29
  308. data/lib/karafka/persistence/consumers.rb +0 -45
  309. data/lib/karafka/persistence/topics.rb +0 -48
  310. data/lib/karafka/responders/builder.rb +0 -36
  311. data/lib/karafka/responders/topic.rb +0 -55
  312. data/lib/karafka/routing/topic_mapper.rb +0 -53
  313. data/lib/karafka/serialization/json/serializer.rb +0 -31
  314. data/lib/karafka/setup/configurators/water_drop.rb +0 -36
  315. data/lib/karafka/templates/application_responder.rb.erb +0 -11
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Karafka
4
+ module Connection
5
+ # Buffer for raw librdkafka messages.
6
+ #
7
+ # When message is added to this buffer, it gets assigned to an array with other messages from
8
+ # the same topic and partition.
9
+ #
10
+ # @note This buffer is NOT threadsafe.
11
+ #
12
+ # @note We store data here in groups per topic partition to handle the revocation case, where
13
+ # we may need to remove messages from a single topic partition.
14
+ class RawMessagesBuffer
15
+ attr_reader :size
16
+
17
+ # @return [Karafka::Connection::MessagesBuffer] buffer instance
18
+ def initialize
19
+ @size = 0
20
+ @groups = Hash.new do |topic_groups, topic|
21
+ topic_groups[topic] = Hash.new do |partition_groups, partition|
22
+ partition_groups[partition] = []
23
+ end
24
+ end
25
+ end
26
+
27
+ # Adds a message to the buffer.
28
+ #
29
+ # @param message [Rdkafka::Consumer::Message] raw rdkafka message
30
+ # @return [Array<Rdkafka::Consumer::Message>] given partition topic sub-buffer array
31
+ def <<(message)
32
+ @size += 1
33
+ @groups[message.topic][message.partition] << message
34
+ end
35
+
36
+ # Allows to iterate over all the topics and partitions messages
37
+ #
38
+ # @yieldparam [String] topic name
39
+ # @yieldparam [Integer] partition number
40
+ # @yieldparam [Array<Rdkafka::Consumer::Message>] topic partition aggregated results
41
+ def each
42
+ @groups.each do |topic, partitions|
43
+ partitions.each do |partition, messages|
44
+ yield(topic, partition, messages)
45
+ end
46
+ end
47
+ end
48
+
49
+ # Removes given topic and partition data out of the buffer
50
+ # This is used when there's a partition revocation
51
+ # @param topic [String] topic we're interested in
52
+ # @param partition [Integer] partition of which data we want to remove
53
+ def delete(topic, partition)
54
+ return unless @groups.key?(topic)
55
+ return unless @groups.fetch(topic).key?(partition)
56
+
57
+ topic_data = @groups.fetch(topic)
58
+ topic_data.delete(partition)
59
+
60
+ recount!
61
+
62
+ # If there are no more partitions to handle in a given topic, remove it completely
63
+ @groups.delete(topic) if topic_data.empty?
64
+ end
65
+
66
+ # Removes duplicated messages from the same partitions
67
+ # This should be used only when rebalance occurs, as we may get data again we already have
68
+ # due to the processing from the last offset. In cases like this, we may get same data
69
+ # again and we do want to ensure as few duplications as possible
70
+ def uniq!
71
+ @groups.each_value do |partitions|
72
+ partitions.each_value do |messages|
73
+ messages.uniq!(&:offset)
74
+ end
75
+ end
76
+
77
+ recount!
78
+ end
79
+
80
+ # Removes all the data from the buffer.
81
+ #
82
+ # @note We do not clear the whole groups hash but rather we clear the partition hashes, so
83
+ # we save ourselves some objects allocations. We cannot clear the underlying arrays as they
84
+ # may be used in other threads for data processing, thus if we would clear it, we could
85
+ # potentially clear a raw messages array for a job that is in the jobs queue.
86
+ def clear
87
+ @size = 0
88
+ @groups.each_value(&:clear)
89
+ end
90
+
91
+ private
92
+
93
+ # Updates the messages count if we performed any operations that could change the state
94
+ def recount!
95
+ @size = @groups.each_value.sum do |partitions|
96
+ partitions.each_value.map(&:count).sum
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Karafka
4
+ module Connection
5
+ # Manager for tracking changes in the partitions assignment.
6
+ #
7
+ # We need tracking of those to clean up consumers that will no longer process given partitions
8
+ # as they were taken away.
9
+ #
10
+ # @note Since this does not happen really often, we try to stick with same objects for the
11
+ # empty states most of the time, so we don't create many objects during the manager life
12
+ #
13
+ # @note Internally in the rebalance manager we have a notion of lost partitions. Partitions
14
+ # that are lost, are those that got revoked but did not get re-assigned back. We do not
15
+ # expose this concept outside and we normalize to have them revoked, as it is irrelevant
16
+ # from the rest of the code perspective as only those that are lost are truly revoked.
17
+ #
18
+ # @note For cooperative-sticky `#assigned_partitions` holds only the recently assigned
19
+ # partitions, not all the partitions that are owned
20
+ class RebalanceManager
21
+ # Empty array for internal usage not to create new objects
22
+ EMPTY_ARRAY = [].freeze
23
+
24
+ attr_reader :assigned_partitions, :revoked_partitions
25
+
26
+ private_constant :EMPTY_ARRAY
27
+
28
+ # @return [RebalanceManager]
29
+ def initialize
30
+ @assigned_partitions = {}
31
+ @revoked_partitions = {}
32
+ @changed = false
33
+ @active = false
34
+ end
35
+
36
+ # Resets the rebalance manager state
37
+ # This needs to be done before each polling loop as during the polling, the state may be
38
+ # changed
39
+ def clear
40
+ @assigned_partitions.clear
41
+ @revoked_partitions.clear
42
+ @changed = false
43
+ end
44
+
45
+ # @return [Boolean] indicates a state change in the partitions assignment
46
+ def changed?
47
+ @changed
48
+ end
49
+
50
+ # @return [Boolean] true if there was at least one rebalance
51
+ # @note This method is needed to make sure that when using cooperative-sticky, we do not
52
+ # close until first rebalance. Otherwise librdkafka may crash.
53
+ # @see https://github.com/confluentinc/librdkafka/issues/4312
54
+ def active?
55
+ @active
56
+ end
57
+
58
+ # Callback that kicks in inside of rdkafka, when new partitions are assigned.
59
+ #
60
+ # @private
61
+ # @param partitions [Rdkafka::Consumer::TopicPartitionList]
62
+ def on_partitions_assigned(partitions)
63
+ @active = true
64
+ @assigned_partitions = partitions.to_h.transform_values { |part| part.map(&:partition) }
65
+ @changed = true
66
+ end
67
+
68
+ # Callback that kicks in inside of rdkafka, when partitions are revoked.
69
+ #
70
+ # @private
71
+ # @param partitions [Rdkafka::Consumer::TopicPartitionList]
72
+ def on_partitions_revoked(partitions)
73
+ @active = true
74
+ @revoked_partitions = partitions.to_h.transform_values { |part| part.map(&:partition) }
75
+ @changed = true
76
+ end
77
+
78
+ # We consider as lost only partitions that were taken away and not re-assigned back to us
79
+ def lost_partitions
80
+ lost_partitions = {}
81
+
82
+ revoked_partitions.each do |topic, partitions|
83
+ lost_partitions[topic] = partitions - assigned_partitions.fetch(topic, EMPTY_ARRAY)
84
+ end
85
+
86
+ lost_partitions
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Karafka
4
+ module Contracts
5
+ # Base contract for all Karafka contracts
6
+ class Base < ::Karafka::Core::Contractable::Contract
7
+ # @param data [Hash] data for validation
8
+ # @return [Boolean] true if all good
9
+ # @raise [Errors::InvalidConfigurationError] invalid configuration error
10
+ # @note We use contracts only in the config validation context, so no need to add support
11
+ # for multiple error classes. It will be added when it will be needed.
12
+ def validate!(data)
13
+ super(data, Errors::InvalidConfigurationError)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -2,19 +2,96 @@
2
2
 
3
3
  module Karafka
4
4
  module Contracts
5
- # Contract with validation rules for Karafka configuration details
5
+ # Contract with validation rules for Karafka configuration details.
6
+ #
6
7
  # @note There are many more configuration options inside of the
7
- # Karafka::Setup::Config model, but we don't validate them here as they are
8
+ # `Karafka::Setup::Config` model, but we don't validate them here as they are
8
9
  # validated per each route (topic + consumer_group) because they can be overwritten,
9
- # so we validate all of that once all the routes are defined and ready
10
- class Config < Dry::Validation::Contract
11
- params do
12
- required(:client_id).filled(:str?, format?: Karafka::Contracts::TOPIC_REGEXP)
13
- required(:shutdown_timeout) { (int? & gt?(0)) }
14
- required(:consumer_mapper)
15
- required(:topic_mapper)
16
-
17
- optional(:backend).filled
10
+ # so we validate all of that once all the routes are defined and ready.
11
+ class Config < Base
12
+ configure do |config|
13
+ config.error_messages = YAML.safe_load(
14
+ File.read(
15
+ File.join(Karafka.gem_root, 'config', 'locales', 'errors.yml')
16
+ )
17
+ ).fetch('en').fetch('validations').fetch('config')
18
+ end
19
+
20
+ # License validity happens in the licenser. Here we do only the simple consistency checks
21
+ nested(:license) do
22
+ required(:token) { |val| [true, false].include?(val) || val.is_a?(String) }
23
+ required(:entity) { |val| val.is_a?(String) }
24
+ end
25
+
26
+ required(:client_id) { |val| val.is_a?(String) && Contracts::TOPIC_REGEXP.match?(val) }
27
+ required(:concurrency) { |val| val.is_a?(Integer) && val.positive? }
28
+ required(:consumer_mapper) { |val| !val.nil? }
29
+ required(:consumer_persistence) { |val| [true, false].include?(val) }
30
+ required(:pause_timeout) { |val| val.is_a?(Integer) && val.positive? }
31
+ required(:pause_max_timeout) { |val| val.is_a?(Integer) && val.positive? }
32
+ required(:pause_with_exponential_backoff) { |val| [true, false].include?(val) }
33
+ required(:shutdown_timeout) { |val| val.is_a?(Integer) && val.positive? }
34
+ required(:max_wait_time) { |val| val.is_a?(Integer) && val.positive? }
35
+ required(:kafka) { |val| val.is_a?(Hash) && !val.empty? }
36
+
37
+ # We validate internals just to be sure, that they are present and working
38
+ nested(:internal) do
39
+ required(:status) { |val| !val.nil? }
40
+ required(:process) { |val| !val.nil? }
41
+
42
+ nested(:routing) do
43
+ required(:builder) { |val| !val.nil? }
44
+ required(:subscription_groups_builder) { |val| !val.nil? }
45
+ end
46
+
47
+ nested(:processing) do
48
+ required(:jobs_builder) { |val| !val.nil? }
49
+ required(:scheduler) { |val| !val.nil? }
50
+ required(:coordinator_class) { |val| !val.nil? }
51
+ required(:partitioner_class) { |val| !val.nil? }
52
+ end
53
+
54
+ nested(:active_job) do
55
+ required(:dispatcher) { |val| !val.nil? }
56
+ required(:job_options_contract) { |val| !val.nil? }
57
+ required(:consumer_class) { |val| !val.nil? }
58
+ end
59
+ end
60
+
61
+ virtual do |data, errors|
62
+ next unless errors.empty?
63
+
64
+ detected_errors = []
65
+
66
+ data.fetch(:kafka).each_key do |key|
67
+ next if key.is_a?(Symbol)
68
+
69
+ detected_errors << [[:kafka, key], :key_must_be_a_symbol]
70
+ end
71
+
72
+ detected_errors
73
+ end
74
+
75
+ virtual do |data, errors|
76
+ next unless errors.empty?
77
+
78
+ pause_timeout = data.fetch(:pause_timeout)
79
+ pause_max_timeout = data.fetch(:pause_max_timeout)
80
+
81
+ next if pause_timeout <= pause_max_timeout
82
+
83
+ [[%i[pause_timeout], :max_timeout_vs_pause_max_timeout]]
84
+ end
85
+
86
+ virtual do |data, errors|
87
+ next unless errors.empty?
88
+
89
+ shutdown_timeout = data.fetch(:shutdown_timeout)
90
+ max_wait_time = data.fetch(:max_wait_time)
91
+
92
+ next if max_wait_time < shutdown_timeout
93
+
94
+ [[%i[shutdown_timeout], :shutdown_timeout_vs_max_wait_time]]
18
95
  end
19
96
  end
20
97
  end
@@ -3,208 +3,53 @@
3
3
  module Karafka
4
4
  module Contracts
5
5
  # Contract for single full route (consumer group + topics) validation.
6
- class ConsumerGroup < Dry::Validation::Contract
7
- config.messages.load_paths << File.join(Karafka.gem_root, 'config', 'errors.yml')
8
-
9
- # Valid uri schemas of Kafka broker url
10
- # The ||= is due to the behavior of require_all that resolves dependencies
11
- # but sometimes loads things twice
12
- URI_SCHEMES ||= %w[kafka kafka+ssl plaintext ssl].freeze
13
-
14
- # Available sasl scram mechanism of authentication (plus nil)
15
- SASL_SCRAM_MECHANISMS ||= %w[sha256 sha512].freeze
16
-
17
- # Internal contract for sub-validating topics schema
18
- TOPIC_CONTRACT = ConsumerGroupTopic.new.freeze
19
-
20
- private_constant :TOPIC_CONTRACT
21
-
22
- params do
23
- required(:id).filled(:str?, format?: Karafka::Contracts::TOPIC_REGEXP)
24
- required(:topics).value(:array, :filled?)
25
- required(:seed_brokers).value(:array, :filled?)
26
- required(:session_timeout).filled { int? | float? }
27
- required(:pause_timeout).maybe(%i[integer float]) { filled? > gteq?(0) }
28
- required(:pause_max_timeout).maybe(%i[integer float]) { filled? > gteq?(0) }
29
- required(:pause_exponential_backoff).filled(:bool?)
30
- required(:offset_commit_interval) { int? | float? }
31
- required(:offset_commit_threshold).filled(:int?)
32
- required(:offset_retention_time).maybe(:integer)
33
- required(:heartbeat_interval).filled { (int? | float?) & gteq?(0) }
34
- required(:fetcher_max_queue_size).filled(:int?, gt?: 0)
35
- required(:assignment_strategy).value(:any)
36
- required(:connect_timeout).filled { (int? | float?) & gt?(0) }
37
- required(:reconnect_timeout).filled { (int? | float?) & gteq?(0) }
38
- required(:socket_timeout).filled { (int? | float?) & gt?(0) }
39
- required(:min_bytes).filled(:int?, gt?: 0)
40
- required(:max_bytes).filled(:int?, gt?: 0)
41
- required(:max_wait_time).filled { (int? | float?) & gteq?(0) }
42
- required(:batch_fetching).filled(:bool?)
43
-
44
- %i[
45
- ssl_ca_cert
46
- ssl_ca_cert_file_path
47
- ssl_client_cert
48
- ssl_client_cert_key
49
- ssl_client_cert_chain
50
- ssl_client_cert_key_password
51
- sasl_gssapi_principal
52
- sasl_gssapi_keytab
53
- sasl_plain_authzid
54
- sasl_plain_username
55
- sasl_plain_password
56
- sasl_scram_username
57
- sasl_scram_password
58
- ].each do |encryption_attribute|
59
- optional(encryption_attribute).maybe(:str?)
60
- end
61
-
62
- optional(:ssl_verify_hostname).maybe(:bool?)
63
- optional(:ssl_ca_certs_from_system).maybe(:bool?)
64
- optional(:sasl_over_ssl).maybe(:bool?)
65
- optional(:sasl_oauth_token_provider).value(:any)
66
-
67
- # It's not with other encryptions as it has some more rules
68
- optional(:sasl_scram_mechanism)
69
- .maybe(:str?, included_in?: SASL_SCRAM_MECHANISMS)
6
+ class ConsumerGroup < Base
7
+ configure do |config|
8
+ config.error_messages = YAML.safe_load(
9
+ File.read(
10
+ File.join(Karafka.gem_root, 'config', 'locales', 'errors.yml')
11
+ )
12
+ ).fetch('en').fetch('validations').fetch('consumer_group')
70
13
  end
71
14
 
72
- # Uri rule to check if uri is in a Karafka acceptable format
73
- rule(:seed_brokers) do
74
- if value.is_a?(Array) && !value.all?(&method(:kafka_uri?))
75
- key.failure(:invalid_broker_schema)
76
- end
77
- end
15
+ required(:id) { |val| val.is_a?(String) && Contracts::TOPIC_REGEXP.match?(val) }
16
+ required(:topics) { |val| val.is_a?(Array) && !val.empty? }
78
17
 
79
- rule(:topics) do
80
- if value.is_a?(Array)
81
- names = value.map { |topic| topic[:name] }
18
+ virtual do |data, errors|
19
+ next unless errors.empty?
82
20
 
83
- key.failure(:topics_names_not_unique) if names.size != names.uniq.size
84
- end
85
- end
21
+ names = data.fetch(:topics).map { |topic| topic[:name] }
86
22
 
87
- rule(:topics) do
88
- if value.is_a?(Array)
89
- value.each_with_index do |topic, index|
90
- TOPIC_CONTRACT.call(topic).errors.each do |error|
91
- key([:topics, index, error.path[0]]).failure(error.text)
92
- end
93
- end
94
- end
95
- end
23
+ next if names.size == names.uniq.size
96
24
 
97
- rule(:assignment_strategy) do
98
- key.failure(:does_not_respond_to_call) unless value.respond_to?(:call)
25
+ [[%i[topics], :names_not_unique]]
99
26
  end
100
27
 
101
- rule(:ssl_client_cert, :ssl_client_cert_key) do
102
- if values[:ssl_client_cert] && !values[:ssl_client_cert_key]
103
- key(:ssl_client_cert_key).failure(:ssl_client_cert_with_ssl_client_cert_key)
104
- end
105
- end
28
+ virtual do |data, errors|
29
+ next unless errors.empty?
30
+ next unless ::Karafka::App.config.strict_topics_namespacing
106
31
 
107
- rule(:ssl_client_cert, :ssl_client_cert_key) do
108
- if values[:ssl_client_cert_key] && !values[:ssl_client_cert]
109
- key(:ssl_client_cert).failure(:ssl_client_cert_key_with_ssl_client_cert)
110
- end
111
- end
32
+ names = data.fetch(:topics).map { |topic| topic[:name] }
33
+ names_hash = names.each_with_object({}) { |n, h| h[n] = true }
34
+ error_occured = false
35
+ names.each do |n|
36
+ # Skip topic names that are not namespaced
37
+ next unless n.chars.find { |c| ['.', '_'].include?(c) }
112
38
 
113
- rule(:ssl_client_cert, :ssl_client_cert_chain) do
114
- if values[:ssl_client_cert_chain] && !values[:ssl_client_cert]
115
- key(:ssl_client_cert).failure(:ssl_client_cert_chain_with_ssl_client_cert)
116
- end
117
- end
118
-
119
- rule(:ssl_client_cert_chain, :ssl_client_cert_key) do
120
- if values[:ssl_client_cert_chain] && !values[:ssl_client_cert]
121
- key(:ssl_client_cert).failure(:ssl_client_cert_chain_with_ssl_client_cert_key)
122
- end
123
- end
124
-
125
- rule(:ssl_client_cert_key_password, :ssl_client_cert_key) do
126
- if values[:ssl_client_cert_key_password] && !values[:ssl_client_cert_key]
127
- key(:ssl_client_cert_key).failure(:ssl_client_cert_key_password_with_ssl_client_cert_key)
128
- end
129
- end
130
-
131
- rule(:ssl_ca_cert) do
132
- key.failure(:invalid_certificate) if value && !valid_certificate?(value)
133
- end
134
-
135
- rule(:ssl_client_cert) do
136
- key.failure(:invalid_certificate) if value && !valid_certificate?(value)
137
- end
138
-
139
- rule(:ssl_ca_cert_file_path) do
140
- if value
141
- if File.exist?(value)
142
- key.failure(:invalid_certificate_from_path) unless valid_certificate?(File.read(value))
39
+ if n.chars.include?('.')
40
+ # Check underscore styled topic
41
+ underscored_topic = n.tr('.', '_')
42
+ error_occured = names_hash[underscored_topic] ? true : false
143
43
  else
144
- key.failure(:does_not_exist)
145
- end
146
- end
147
- end
148
-
149
- rule(:ssl_client_cert_key) do
150
- key.failure(:invalid_private_key) if value && !valid_private_key?(value)
151
- end
152
-
153
- rule(:ssl_client_cert_chain) do
154
- key.failure(:invalid_certificate) if value && !valid_certificate?(value)
155
- end
156
-
157
- rule(:sasl_oauth_token_provider) do
158
- key.failure(:does_not_respond_to_token) if value && !value.respond_to?(:token)
159
- end
160
-
161
- rule(:max_wait_time, :socket_timeout) do
162
- max_wait_time = values[:max_wait_time]
163
- socket_timeout = values[:socket_timeout]
164
-
165
- if socket_timeout.is_a?(Numeric) &&
166
- max_wait_time.is_a?(Numeric) &&
167
- max_wait_time > socket_timeout
168
-
169
- key(:max_wait_time).failure(:max_wait_time_limit)
170
- end
171
- end
172
-
173
- rule(:pause_timeout, :pause_max_timeout, :pause_exponential_backoff) do
174
- if values[:pause_exponential_backoff]
175
- if values[:pause_timeout].to_i > values[:pause_max_timeout].to_i
176
- key(:pause_max_timeout).failure(:max_timeout_size_for_exponential)
44
+ # Check dot styled topic
45
+ dot_topic = n.tr('_', '.')
46
+ error_occured = names_hash[dot_topic] ? true : false
177
47
  end
178
48
  end
179
- end
180
-
181
- private
182
49
 
183
- # @param value [String] potential RSA key value
184
- # @return [Boolean] is the given string a valid RSA key
185
- def valid_private_key?(value)
186
- OpenSSL::PKey.read(value)
187
- true
188
- rescue OpenSSL::PKey::PKeyError
189
- false
190
- end
191
-
192
- # @param value [String] potential X509 cert value
193
- # @return [Boolean] is the given string a valid X509 cert
194
- def valid_certificate?(value)
195
- OpenSSL::X509::Certificate.new(value)
196
- true
197
- rescue OpenSSL::X509::CertificateError
198
- false
199
- end
50
+ next unless error_occured
200
51
 
201
- # @param value [String] potential kafka uri
202
- # @return [Boolean] true if it is a kafka uri, otherwise false
203
- def kafka_uri?(value)
204
- uri = URI.parse(value)
205
- URI_SCHEMES.include?(uri.scheme) && uri.port
206
- rescue URI::InvalidURIError
207
- false
52
+ [[%i[topics], :topics_namespaced_names_not_unique]]
208
53
  end
209
54
  end
210
55
  end
@@ -2,29 +2,90 @@
2
2
 
3
3
  module Karafka
4
4
  module Contracts
5
- # Contract for validating correctness of the server cli command options
6
- # We validate some basics + the list of consumer_groups on which we want to use, to make
7
- # sure that all of them are defined, plus that a pidfile does not exist
8
- class ServerCliOptions < Dry::Validation::Contract
9
- config.messages.load_paths << File.join(Karafka.gem_root, 'config', 'errors.yml')
10
-
11
- params do
12
- optional(:pid).filled(:str?)
13
- optional(:daemon).filled(:bool?)
14
- optional(:consumer_groups).value(:array, :filled?)
5
+ # Contract for validating correctness of the server cli command options.
6
+ class ServerCliOptions < Base
7
+ configure do |config|
8
+ config.error_messages = YAML.safe_load(
9
+ File.read(
10
+ File.join(Karafka.gem_root, 'config', 'locales', 'errors.yml')
11
+ )
12
+ ).fetch('en').fetch('validations').fetch('server_cli_options')
15
13
  end
16
14
 
17
- rule(:pid) do
18
- key(:pid).failure(:pid_already_exists) if value && File.exist?(value)
19
- end
15
+ %i[
16
+ include
17
+ exclude
18
+ ].each do |action|
19
+ optional(:"#{action}_consumer_groups") { |cg| cg.is_a?(Array) }
20
+ optional(:"#{action}_subscription_groups") { |sg| sg.is_a?(Array) }
21
+ optional(:"#{action}_topics") { |topics| topics.is_a?(Array) }
22
+
23
+ virtual do |data, errors|
24
+ next unless errors.empty?
25
+
26
+ value = data.fetch(:"#{action}_consumer_groups")
27
+
28
+ # If there were no consumer_groups declared in the server cli, it means that we will
29
+ # run all of them and no need to validate them here at all
30
+ next if value.empty?
31
+ next if (value - Karafka::App.consumer_groups.map(&:name)).empty?
32
+
33
+ # Found unknown consumer groups
34
+ [[[:"#{action}_consumer_groups"], :consumer_groups_inclusion]]
35
+ end
36
+
37
+ virtual do |data, errors|
38
+ next unless errors.empty?
39
+
40
+ value = data.fetch(:"#{action}_subscription_groups")
41
+
42
+ # If there were no subscription_groups declared in the server cli, it means that we will
43
+ # run all of them and no need to validate them here at all
44
+ next if value.empty?
45
+
46
+ subscription_groups = Karafka::App
47
+ .consumer_groups
48
+ .map(&:subscription_groups)
49
+ .flatten
50
+ .map(&:name)
51
+
52
+ next if (value - subscription_groups).empty?
20
53
 
21
- rule(:consumer_groups) do
22
- # If there were no consumer_groups declared in the server cli, it means that we will
23
- # run all of them and no need to validate them here at all
24
- if !value.nil? &&
25
- !(value - Karafka::App.config.internal.routing_builder.map(&:name)).empty?
26
- key(:consumer_groups).failure(:consumer_groups_inclusion)
54
+ # Found unknown subscription groups
55
+ [[[:"#{action}_subscription_groups"], :subscription_groups_inclusion]]
27
56
  end
57
+
58
+ virtual do |data, errors|
59
+ next unless errors.empty?
60
+
61
+ value = data.fetch(:"#{action}_topics")
62
+
63
+ # If there were no topics declared in the server cli, it means that we will
64
+ # run all of them and no need to validate them here at all
65
+ next if value.empty?
66
+
67
+ topics = Karafka::App
68
+ .consumer_groups
69
+ .map(&:subscription_groups)
70
+ .flatten
71
+ .map(&:topics)
72
+ .map { |gtopics| gtopics.map(&:name) }
73
+ .flatten
74
+
75
+ next if (value - topics).empty?
76
+
77
+ # Found unknown topics
78
+ [[[:"#{action}_topics"], :topics_inclusion]]
79
+ end
80
+ end
81
+
82
+ # Makes sure we have anything to subscribe to when we start the server
83
+ virtual do |_, errors|
84
+ next unless errors.empty?
85
+
86
+ next unless Karafka::App.subscription_groups.empty?
87
+
88
+ [[%i[include_topics], :topics_missing]]
28
89
  end
29
90
  end
30
91
  end