karafka 2.5.9 → 2.6.0.beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +34 -0
- data/certs/expired.txt +83 -0
- data/config/locales/errors.yml +17 -7
- data/karafka.gemspec +3 -3
- data/lib/active_job/queue_adapters/karafka_adapter.rb +1 -2
- data/lib/karafka/active_job/job_extensions.rb +1 -2
- data/lib/karafka/admin/configs/resource.rb +1 -2
- data/lib/karafka/admin/consumer_groups.rb +109 -98
- data/lib/karafka/admin/isolation_levels.rb +22 -0
- data/lib/karafka/admin/topics.rb +103 -8
- data/lib/karafka/admin.rb +59 -31
- data/lib/karafka/app.rb +16 -5
- data/lib/karafka/base_consumer.rb +2 -2
- data/lib/karafka/cli/contracts/server.rb +4 -4
- data/lib/karafka/cli/info.rb +1 -1
- data/lib/karafka/cli/topics/base.rb +10 -18
- data/lib/karafka/cli/topics/repartition.rb +1 -1
- data/lib/karafka/connection/client.rb +40 -9
- data/lib/karafka/connection/consumer_groups/rebalance_manager.rb +120 -0
- data/lib/karafka/connection/listener.rb +8 -7
- data/lib/karafka/connection/listeners_batch.rb +1 -1
- data/lib/karafka/connection/mode.rb +1 -2
- data/lib/karafka/connection/raw_messages_buffer.rb +0 -5
- data/lib/karafka/declaratives/builder.rb +65 -0
- data/lib/karafka/declaratives/contracts/topic.rb +28 -0
- data/lib/karafka/declaratives/repository.rb +52 -0
- data/lib/karafka/declaratives/topic.rb +100 -0
- data/lib/karafka/declaratives.rb +9 -0
- data/lib/karafka/helpers/interval_runner.rb +2 -2
- data/lib/karafka/instrumentation/assignments_tracker.rb +65 -2
- data/lib/karafka/instrumentation/callbacks/consumer_groups/error.rb +56 -0
- data/lib/karafka/instrumentation/callbacks/consumer_groups/rebalance.rb +93 -0
- data/lib/karafka/instrumentation/callbacks/consumer_groups/statistics.rb +59 -0
- data/lib/karafka/instrumentation/logger_listener.rb +27 -9
- data/lib/karafka/instrumentation/notifications.rb +2 -0
- data/lib/karafka/instrumentation/vendors/appsignal/metrics_listener.rb +14 -17
- data/lib/karafka/instrumentation/vendors/datadog/metrics_listener.rb +8 -9
- data/lib/karafka/instrumentation/vendors/kubernetes/base_listener.rb +7 -3
- data/lib/karafka/instrumentation/vendors/kubernetes/liveness_listener.rb +13 -10
- data/lib/karafka/licenser.rb +16 -3
- data/lib/karafka/pro/active_job/consumer.rb +1 -2
- data/lib/karafka/pro/active_job/dispatcher.rb +1 -2
- data/lib/karafka/pro/admin/recovery.rb +19 -19
- data/lib/karafka/pro/base_consumer.rb +3 -3
- data/lib/karafka/pro/cli/contracts/server.rb +5 -5
- data/lib/karafka/pro/cli/parallel_segments/base.rb +7 -7
- data/lib/karafka/pro/cli/parallel_segments/collapse.rb +4 -4
- data/lib/karafka/pro/cli/parallel_segments/distribute.rb +6 -6
- data/lib/karafka/pro/iterator/tpl_builder.rb +38 -18
- data/lib/karafka/pro/loader.rb +15 -12
- data/lib/karafka/pro/processing/consumer_groups/adaptive_iterator/consumer.rb +84 -0
- data/lib/karafka/pro/processing/consumer_groups/adaptive_iterator/tracker.rb +97 -0
- data/lib/karafka/pro/processing/consumer_groups/collapser.rb +84 -0
- data/lib/karafka/pro/processing/consumer_groups/coordinator.rb +202 -0
- data/lib/karafka/pro/processing/consumer_groups/coordinators/errors_tracker.rb +124 -0
- data/lib/karafka/pro/processing/consumer_groups/coordinators/filters_applier.rb +157 -0
- data/lib/karafka/pro/processing/consumer_groups/coordinators/virtual_offset_manager.rb +212 -0
- data/lib/karafka/pro/processing/{filters/expirer.rb → consumer_groups/executor.rb} +17 -31
- data/lib/karafka/pro/processing/{jobs/periodic.rb → consumer_groups/expansions_selector.rb} +18 -21
- data/lib/karafka/pro/processing/consumer_groups/filters/base.rb +103 -0
- data/lib/karafka/pro/processing/consumer_groups/filters/delayer.rb +92 -0
- data/lib/karafka/pro/processing/consumer_groups/filters/expirer.rb +78 -0
- data/lib/karafka/pro/processing/consumer_groups/filters/inline_insights_delayer.rb +99 -0
- data/lib/karafka/pro/processing/consumer_groups/filters/throttler.rb +106 -0
- data/lib/karafka/pro/processing/consumer_groups/filters/virtual_limiter.rb +79 -0
- data/lib/karafka/pro/processing/{jobs → consumer_groups/jobs}/consume_non_blocking.rb +21 -17
- data/lib/karafka/pro/processing/{virtual_partitions/distributors/consistent.rb → consumer_groups/jobs/eofed_non_blocking.rb} +16 -14
- data/lib/karafka/pro/processing/consumer_groups/jobs/periodic.rb +64 -0
- data/lib/karafka/pro/processing/{jobs → consumer_groups/jobs}/periodic_non_blocking.rb +16 -11
- data/lib/karafka/pro/processing/{jobs → consumer_groups/jobs}/revoked_non_blocking.rb +19 -15
- data/lib/karafka/pro/processing/consumer_groups/jobs_builder.rb +95 -0
- data/lib/karafka/pro/processing/consumer_groups/offset_metadata/consumer.rb +66 -0
- data/lib/karafka/pro/processing/consumer_groups/offset_metadata/fetcher.rb +154 -0
- data/lib/karafka/pro/processing/consumer_groups/offset_metadata/listener.rb +68 -0
- data/lib/karafka/pro/processing/consumer_groups/parallel_segments/filters/base.rb +102 -0
- data/lib/karafka/pro/processing/consumer_groups/parallel_segments/filters/default.rb +115 -0
- data/lib/karafka/pro/processing/consumer_groups/parallel_segments/filters/mom.rb +96 -0
- data/lib/karafka/pro/processing/consumer_groups/partitioner.rb +98 -0
- data/lib/karafka/pro/processing/consumer_groups/periodic_job/consumer.rb +90 -0
- data/lib/karafka/pro/processing/consumer_groups/piping/consumer.rb +154 -0
- data/lib/karafka/pro/processing/consumer_groups/strategies/aj/dlq_ftr_lrj_mom.rb +93 -0
- data/lib/karafka/pro/processing/consumer_groups/strategies/aj/dlq_ftr_lrj_mom_vp.rb +99 -0
- data/lib/karafka/pro/processing/consumer_groups/strategies/aj/dlq_ftr_mom.rb +92 -0
- data/lib/karafka/pro/processing/consumer_groups/strategies/aj/dlq_ftr_mom_vp.rb +90 -0
- data/lib/karafka/pro/processing/{strategies/aj/dlq_ftr_lrj_mom.rb → consumer_groups/strategies/aj/dlq_lrj_mom.rb} +37 -39
- data/lib/karafka/pro/processing/consumer_groups/strategies/aj/dlq_lrj_mom_vp.rb +90 -0
- data/lib/karafka/pro/processing/consumer_groups/strategies/aj/dlq_mom.rb +84 -0
- data/lib/karafka/pro/processing/consumer_groups/strategies/aj/dlq_mom_vp.rb +89 -0
- data/lib/karafka/pro/processing/{strategies → consumer_groups/strategies}/aj/ftr_lrj_mom.rb +20 -15
- data/lib/karafka/pro/processing/consumer_groups/strategies/aj/ftr_lrj_mom_vp.rb +91 -0
- data/lib/karafka/pro/processing/{strategies → consumer_groups/strategies}/aj/ftr_mom.rb +20 -15
- data/lib/karafka/pro/processing/consumer_groups/strategies/aj/ftr_mom_vp.rb +80 -0
- data/lib/karafka/pro/processing/{strategies/mom/default.rb → consumer_groups/strategies/aj/lrj_mom.rb} +18 -22
- data/lib/karafka/pro/processing/consumer_groups/strategies/aj/lrj_mom_vp.rb +106 -0
- data/lib/karafka/pro/processing/consumer_groups/strategies/aj/mom.rb +58 -0
- data/lib/karafka/pro/processing/consumer_groups/strategies/aj/mom_vp.rb +74 -0
- data/lib/karafka/pro/processing/{strategies/lrj/vp.rb → consumer_groups/strategies/base.rb} +9 -14
- data/lib/karafka/pro/processing/consumer_groups/strategies/default.rb +421 -0
- data/lib/karafka/pro/processing/consumer_groups/strategies/dlq/default.rb +285 -0
- data/lib/karafka/pro/processing/{strategies/dlq/lrj.rb → consumer_groups/strategies/dlq/ftr.rb} +30 -29
- data/lib/karafka/pro/processing/consumer_groups/strategies/dlq/ftr_lrj.rb +95 -0
- data/lib/karafka/pro/processing/consumer_groups/strategies/dlq/ftr_lrj_mom.rb +97 -0
- data/lib/karafka/pro/processing/{executor.rb → consumer_groups/strategies/dlq/ftr_lrj_mom_vp.rb} +26 -15
- data/lib/karafka/pro/processing/consumer_groups/strategies/dlq/ftr_lrj_vp.rb +63 -0
- data/lib/karafka/pro/processing/consumer_groups/strategies/dlq/ftr_mom.rb +97 -0
- data/lib/karafka/pro/processing/consumer_groups/strategies/dlq/ftr_mom_vp.rb +63 -0
- data/lib/karafka/pro/{routing/features/patterns/patterns.rb → processing/consumer_groups/strategies/dlq/ftr_vp.rb} +22 -12
- data/lib/karafka/pro/processing/consumer_groups/strategies/dlq/lrj.rb +83 -0
- data/lib/karafka/pro/processing/consumer_groups/strategies/dlq/lrj_mom.rb +100 -0
- data/lib/karafka/pro/processing/{strategies → consumer_groups/strategies}/dlq/lrj_mom_vp.rb +18 -13
- data/lib/karafka/pro/processing/consumer_groups/strategies/dlq/lrj_vp.rb +61 -0
- data/lib/karafka/pro/processing/consumer_groups/strategies/dlq/mom.rb +96 -0
- data/lib/karafka/pro/processing/{strategies/lrj → consumer_groups/strategies/dlq}/mom_vp.rb +19 -15
- data/lib/karafka/pro/processing/consumer_groups/strategies/dlq/vp.rb +62 -0
- data/lib/karafka/pro/processing/consumer_groups/strategies/ftr/default.rb +146 -0
- data/lib/karafka/pro/processing/{strategies/mom/ftr.rb → consumer_groups/strategies/ftr/vp.rb} +20 -28
- data/lib/karafka/pro/processing/consumer_groups/strategies/lrj/default.rb +119 -0
- data/lib/karafka/pro/processing/consumer_groups/strategies/lrj/ftr.rb +94 -0
- data/lib/karafka/pro/processing/consumer_groups/strategies/lrj/ftr_mom.rb +92 -0
- data/lib/karafka/pro/processing/consumer_groups/strategies/lrj/ftr_mom_vp.rb +62 -0
- data/lib/karafka/pro/processing/consumer_groups/strategies/lrj/ftr_vp.rb +61 -0
- data/lib/karafka/pro/processing/consumer_groups/strategies/lrj/mom.rb +101 -0
- data/lib/karafka/pro/processing/consumer_groups/strategies/lrj/mom_vp.rb +60 -0
- data/lib/karafka/pro/processing/{strategies/mom → consumer_groups/strategies/lrj}/vp.rb +18 -12
- data/lib/karafka/pro/processing/{strategies/aj/mom_vp.rb → consumer_groups/strategies/mom/default.rb} +22 -23
- data/lib/karafka/pro/processing/{strategies/aj/ftr_mom_vp.rb → consumer_groups/strategies/mom/ftr.rb} +28 -28
- data/lib/karafka/pro/processing/{virtual_partitions/distributors/base.rb → consumer_groups/strategies/mom/ftr_vp.rb} +19 -14
- data/lib/karafka/pro/processing/{strategies/aj/mom.rb → consumer_groups/strategies/mom/vp.rb} +16 -12
- data/lib/karafka/pro/processing/consumer_groups/strategies/vp/default.rb +197 -0
- data/lib/karafka/pro/processing/consumer_groups/strategy_selector.rb +106 -0
- data/lib/karafka/pro/processing/consumer_groups/subscription_groups_coordinator.rb +73 -0
- data/lib/karafka/pro/processing/consumer_groups/virtual_partitions/distributors/balanced.rb +82 -0
- data/lib/karafka/pro/processing/consumer_groups/virtual_partitions/distributors/base.rb +59 -0
- data/lib/karafka/pro/processing/{strategies/dlq/ftr.rb → consumer_groups/virtual_partitions/distributors/consistent.rb} +18 -33
- data/lib/karafka/pro/processing/filters/base.rb +3 -61
- data/lib/karafka/pro/processing/partitioner.rb +2 -57
- data/lib/karafka/pro/processing/schedulers/base.rb +10 -6
- data/lib/karafka/pro/processing/schedulers/default.rb +6 -5
- data/lib/karafka/pro/recurring_tasks/executor.rb +1 -2
- data/lib/karafka/pro/routing/features/{active_job → consumer_groups/active_job}/builder.rb +20 -18
- data/lib/karafka/pro/routing/features/{inline_insights/config.rb → consumer_groups/active_job.rb} +5 -9
- data/lib/karafka/pro/routing/features/consumer_groups/adaptive_iterator/config.rb +53 -0
- data/lib/karafka/pro/routing/features/consumer_groups/adaptive_iterator/contracts/topic.rb +91 -0
- data/lib/karafka/pro/routing/features/consumer_groups/adaptive_iterator/topic.rb +90 -0
- data/lib/karafka/pro/routing/features/consumer_groups/adaptive_iterator.rb +50 -0
- data/lib/karafka/pro/routing/features/{patterns/contracts/consumer_group.rb → consumer_groups/dead_letter_queue/contracts/topic.rb} +25 -30
- data/lib/karafka/pro/routing/features/consumer_groups/dead_letter_queue/topic.rb +70 -0
- data/lib/karafka/pro/routing/features/consumer_groups/dead_letter_queue.rb +46 -0
- data/lib/karafka/pro/routing/features/{direct_assignments → consumer_groups/delaying}/config.rb +6 -4
- data/lib/karafka/pro/routing/features/{patterns/contracts/pattern.rb → consumer_groups/delaying/contracts/topic.rb} +13 -16
- data/lib/karafka/pro/routing/features/consumer_groups/delaying/topic.rb +85 -0
- data/lib/karafka/pro/routing/features/{adaptive_iterator/config.rb → consumer_groups/delaying.rb} +8 -11
- data/lib/karafka/pro/routing/features/consumer_groups/direct_assignments/config.rb +46 -0
- data/lib/karafka/pro/routing/features/consumer_groups/direct_assignments/contracts/consumer_group.rb +68 -0
- data/lib/karafka/pro/routing/features/consumer_groups/direct_assignments/contracts/topic.rb +125 -0
- data/lib/karafka/pro/routing/features/consumer_groups/direct_assignments/subscription_group.rb +97 -0
- data/lib/karafka/pro/routing/features/consumer_groups/direct_assignments/topic.rb +97 -0
- data/lib/karafka/pro/routing/features/consumer_groups/direct_assignments.rb +44 -0
- data/lib/karafka/pro/routing/features/consumer_groups/inline_insights/config.rb +51 -0
- data/lib/karafka/pro/routing/features/consumer_groups/inline_insights/contracts/topic.rb +58 -0
- data/lib/karafka/pro/routing/features/consumer_groups/inline_insights/topic.rb +80 -0
- data/lib/karafka/pro/routing/features/consumer_groups/inline_insights.rb +45 -0
- data/lib/karafka/pro/routing/features/consumer_groups/long_running_job/config.rb +47 -0
- data/lib/karafka/pro/routing/features/{multiplexing/patches/contracts/consumer_group.rb → consumer_groups/long_running_job/contracts/topic.rb} +13 -15
- data/lib/karafka/pro/routing/features/consumer_groups/long_running_job/topic.rb +72 -0
- data/lib/karafka/pro/routing/features/{long_running_job.rb → consumer_groups/long_running_job.rb} +6 -4
- data/lib/karafka/pro/routing/features/consumer_groups/multiplexing/config.rb +58 -0
- data/lib/karafka/pro/routing/features/consumer_groups/multiplexing/contracts/routing.rb +83 -0
- data/lib/karafka/pro/routing/features/consumer_groups/multiplexing/contracts/topic.rb +148 -0
- data/lib/karafka/pro/routing/features/{delaying/contracts/topic.rb → consumer_groups/multiplexing/patches/contracts/consumer_group.rb} +19 -14
- data/lib/karafka/pro/routing/features/{multiplexing/subscription_group.rb → consumer_groups/multiplexing/proxy.rb} +17 -23
- data/lib/karafka/pro/routing/features/consumer_groups/multiplexing/subscription_group.rb +68 -0
- data/lib/karafka/pro/routing/features/{multiplexing → consumer_groups/multiplexing}/subscription_groups_builder.rb +16 -14
- data/lib/karafka/pro/routing/features/consumer_groups/multiplexing.rb +85 -0
- data/lib/karafka/pro/routing/features/consumer_groups/non_blocking_job/topic.rb +51 -0
- data/lib/karafka/pro/routing/features/{non_blocking_job.rb → consumer_groups/non_blocking_job.rb} +15 -13
- data/lib/karafka/pro/routing/features/consumer_groups/offset_metadata/config.rb +52 -0
- data/lib/karafka/pro/routing/features/consumer_groups/offset_metadata/contracts/topic.rb +59 -0
- data/lib/karafka/pro/routing/features/consumer_groups/offset_metadata/topic.rb +93 -0
- data/lib/karafka/pro/routing/features/{offset_metadata.rb → consumer_groups/offset_metadata.rb} +16 -14
- data/lib/karafka/pro/routing/features/consumer_groups/parallel_segments/builder.rb +74 -0
- data/lib/karafka/pro/routing/features/{multiplexing → consumer_groups/parallel_segments}/config.rb +13 -15
- data/lib/karafka/pro/routing/features/consumer_groups/parallel_segments/consumer_group.rb +110 -0
- data/lib/karafka/pro/routing/features/consumer_groups/parallel_segments/contracts/consumer_group.rb +74 -0
- data/lib/karafka/pro/routing/features/{parallel_segments → consumer_groups/parallel_segments}/topic.rb +24 -22
- data/lib/karafka/pro/routing/features/consumer_groups/parallel_segments.rb +51 -0
- data/lib/karafka/pro/routing/features/{patterns → consumer_groups/patterns}/builder.rb +15 -13
- data/lib/karafka/pro/routing/features/{offset_metadata/contracts/topic.rb → consumer_groups/patterns/config.rb} +28 -13
- data/lib/karafka/pro/routing/features/consumer_groups/patterns/consumer_group.rb +91 -0
- data/lib/karafka/pro/routing/features/consumer_groups/patterns/contracts/consumer_group.rb +83 -0
- data/lib/karafka/pro/routing/features/{parallel_segments.rb → consumer_groups/patterns/contracts/pattern.rb} +24 -10
- data/lib/karafka/pro/routing/features/consumer_groups/patterns/contracts/topic.rb +58 -0
- data/lib/karafka/pro/routing/features/consumer_groups/patterns/detector.rb +98 -0
- data/lib/karafka/pro/routing/features/consumer_groups/patterns/pattern.rb +114 -0
- data/lib/karafka/pro/routing/features/{recurring_tasks/contracts/topic.rb → consumer_groups/patterns/patterns.rb} +12 -13
- data/lib/karafka/pro/routing/features/consumer_groups/patterns/topic.rb +78 -0
- data/lib/karafka/pro/routing/features/consumer_groups/patterns/topics.rb +72 -0
- data/lib/karafka/pro/routing/features/consumer_groups/patterns.rb +52 -0
- data/lib/karafka/pro/routing/features/consumer_groups/periodic_job/config.rb +56 -0
- data/lib/karafka/pro/routing/features/{direct_assignments/contracts/consumer_group.rb → consumer_groups/periodic_job/contracts/topic.rb} +17 -22
- data/lib/karafka/pro/routing/features/consumer_groups/periodic_job/topic.rb +122 -0
- data/lib/karafka/pro/routing/features/consumer_groups/periodic_job.rb +46 -0
- data/lib/karafka/pro/routing/features/consumer_groups/recurring_tasks/builder.rb +150 -0
- data/lib/karafka/pro/routing/features/{swarm → consumer_groups/recurring_tasks}/config.rb +7 -8
- data/lib/karafka/pro/routing/features/{inline_insights → consumer_groups/recurring_tasks}/contracts/topic.rb +14 -13
- data/lib/karafka/pro/routing/features/{scheduled_messages → consumer_groups/recurring_tasks}/proxy.rb +6 -4
- data/lib/karafka/pro/routing/features/consumer_groups/recurring_tasks/topic.rb +72 -0
- data/lib/karafka/pro/routing/features/consumer_groups/recurring_tasks.rb +44 -0
- data/lib/karafka/pro/routing/features/consumer_groups/scheduled_messages/builder.rb +154 -0
- data/lib/karafka/pro/routing/features/consumer_groups/scheduled_messages/config.rb +47 -0
- data/lib/karafka/pro/routing/features/{long_running_job → consumer_groups/scheduled_messages}/contracts/topic.rb +14 -12
- data/lib/karafka/pro/routing/features/{delaying/config.rb → consumer_groups/scheduled_messages/proxy.rb} +6 -4
- data/lib/karafka/pro/routing/features/consumer_groups/scheduled_messages/topic.rb +72 -0
- data/lib/karafka/pro/routing/features/{recurring_tasks/proxy.rb → consumer_groups/scheduled_messages.rb} +3 -4
- data/lib/karafka/pro/routing/features/{non_blocking_job/topic.rb → consumer_groups/swarm/config.rb} +9 -8
- data/lib/karafka/pro/routing/features/consumer_groups/swarm/contracts/routing.rb +94 -0
- data/lib/karafka/pro/routing/features/consumer_groups/swarm/contracts/topic.rb +95 -0
- data/lib/karafka/pro/routing/features/consumer_groups/swarm/topic.rb +105 -0
- data/lib/karafka/pro/routing/features/consumer_groups/swarm.rb +58 -0
- data/lib/karafka/pro/routing/features/consumer_groups/virtual_partitions/config.rb +69 -0
- data/lib/karafka/pro/routing/features/{parallel_segments/contracts/consumer_group.rb → consumer_groups/virtual_partitions/contracts/topic.rb} +21 -18
- data/lib/karafka/pro/routing/features/consumer_groups/virtual_partitions/topic.rb +101 -0
- data/lib/karafka/pro/routing/features/consumer_groups/virtual_partitions.rb +46 -0
- data/lib/karafka/pro/routing/features/{scheduled_messages.rb → consumer_groups.rb} +3 -2
- data/lib/karafka/pro/routing/features/expiring/topic.rb +4 -4
- data/lib/karafka/pro/routing/features/filtering/topic.rb +3 -3
- data/lib/karafka/pro/routing/features/pausing/topic.rb +3 -3
- data/lib/karafka/pro/routing/features/throttling/topic.rb +4 -4
- data/lib/karafka/pro/setup/defaults_injector.rb +70 -0
- data/lib/karafka/pro/swarm/liveness_listener.rb +22 -10
- data/lib/karafka/processing/consumer_groups/coordinator.rb +221 -0
- data/lib/karafka/processing/consumer_groups/coordinators_buffer.rb +69 -0
- data/lib/karafka/processing/consumer_groups/executor.rb +220 -0
- data/lib/karafka/processing/consumer_groups/executors_buffer.rb +94 -0
- data/lib/karafka/processing/consumer_groups/expansions_selector.rb +26 -0
- data/lib/karafka/processing/consumer_groups/inline_insights/consumer.rb +47 -0
- data/lib/karafka/processing/consumer_groups/inline_insights/listener.rb +23 -0
- data/lib/karafka/processing/consumer_groups/inline_insights/tracker.rb +132 -0
- data/lib/karafka/processing/consumer_groups/jobs/consume.rb +52 -0
- data/lib/karafka/processing/consumer_groups/jobs/eofed.rb +34 -0
- data/lib/karafka/processing/consumer_groups/jobs/idle.rb +33 -0
- data/lib/karafka/processing/consumer_groups/jobs/revoked.rb +34 -0
- data/lib/karafka/processing/consumer_groups/jobs/shutdown.rb +32 -0
- data/lib/karafka/processing/consumer_groups/jobs_builder.rb +36 -0
- data/lib/karafka/processing/consumer_groups/partitioner.rb +28 -0
- data/lib/karafka/processing/consumer_groups/strategies/aj_dlq_mom.rb +48 -0
- data/lib/karafka/processing/consumer_groups/strategies/aj_mom.rb +25 -0
- data/lib/karafka/processing/consumer_groups/strategies/base.rb +65 -0
- data/lib/karafka/processing/consumer_groups/strategies/default.rb +218 -0
- data/lib/karafka/processing/consumer_groups/strategies/dlq.rb +157 -0
- data/lib/karafka/processing/consumer_groups/strategies/dlq_mom.rb +72 -0
- data/lib/karafka/processing/consumer_groups/strategies/mom.rb +33 -0
- data/lib/karafka/processing/consumer_groups/strategy_selector.rb +53 -0
- data/lib/karafka/processing/coordinator.rb +4 -211
- data/lib/karafka/processing/coordinators_buffer.rb +4 -59
- data/lib/karafka/processing/jobs_queue.rb +12 -4
- data/lib/karafka/processing/partitioner.rb +4 -18
- data/lib/karafka/processing/schedulers/default.rb +2 -1
- data/lib/karafka/processing/strategy_selector.rb +4 -42
- data/lib/karafka/processing/worker.rb +8 -4
- data/lib/karafka/processing/workers_pool.rb +158 -0
- data/lib/karafka/routing/builder.rb +12 -12
- data/lib/karafka/routing/contracts/routing.rb +3 -4
- data/lib/karafka/routing/features/base/expander.rb +5 -5
- data/lib/karafka/routing/features/consumer_groups/active_job/builder.rb +35 -0
- data/lib/karafka/routing/features/consumer_groups/active_job/config.rb +17 -0
- data/lib/karafka/routing/features/consumer_groups/active_job/contracts/topic.rb +44 -0
- data/lib/karafka/routing/features/consumer_groups/active_job/proxy.rb +16 -0
- data/lib/karafka/routing/features/consumer_groups/active_job/topic.rb +50 -0
- data/lib/karafka/routing/features/consumer_groups/active_job.rb +15 -0
- data/lib/karafka/routing/features/consumer_groups/dead_letter_queue/config.rb +39 -0
- data/lib/karafka/routing/features/consumer_groups/dead_letter_queue/contracts/topic.rb +58 -0
- data/lib/karafka/routing/features/consumer_groups/dead_letter_queue/topic.rb +76 -0
- data/lib/karafka/routing/features/consumer_groups/dead_letter_queue.rb +18 -0
- data/lib/karafka/routing/features/consumer_groups/eofed/config.rb +17 -0
- data/lib/karafka/routing/features/consumer_groups/eofed/contracts/topic.rb +39 -0
- data/lib/karafka/routing/features/consumer_groups/eofed/topic.rb +42 -0
- data/lib/karafka/routing/features/consumer_groups/eofed.rb +16 -0
- data/lib/karafka/routing/features/consumer_groups/inline_insights/config.rb +17 -0
- data/lib/karafka/routing/features/consumer_groups/inline_insights/contracts/topic.rb +27 -0
- data/lib/karafka/routing/features/consumer_groups/inline_insights/topic.rb +42 -0
- data/lib/karafka/routing/features/consumer_groups/inline_insights.rb +42 -0
- data/lib/karafka/routing/features/consumer_groups/manual_offset_management/config.rb +17 -0
- data/lib/karafka/routing/features/consumer_groups/manual_offset_management/contracts/topic.rb +27 -0
- data/lib/karafka/routing/features/consumer_groups/manual_offset_management/topic.rb +46 -0
- data/lib/karafka/routing/features/consumer_groups/manual_offset_management.rb +20 -0
- data/lib/karafka/routing/features/consumer_groups.rb +12 -0
- data/lib/karafka/routing/features/declaratives/contracts/topic.rb +4 -19
- data/lib/karafka/routing/features/declaratives/topic.rb +30 -14
- data/lib/karafka/routing/features/deserializers/topic.rb +3 -3
- data/lib/karafka/routing/router.rb +2 -2
- data/lib/karafka/routing/subscription_group.rb +18 -9
- data/lib/karafka/routing/topic.rb +25 -11
- data/lib/karafka/runner.rb +17 -17
- data/lib/karafka/server.rb +28 -6
- data/lib/karafka/setup/attributes_map.rb +2 -0
- data/lib/karafka/setup/config.rb +64 -15
- data/lib/karafka/setup/config_proxy.rb +1 -2
- data/lib/karafka/setup/contracts/config.rb +28 -8
- data/lib/karafka/setup/defaults_injector.rb +10 -0
- data/lib/karafka/status.rb +1 -2
- data/lib/karafka/swarm/liveness_listener.rb +7 -0
- data/lib/karafka/swarm/manager.rb +7 -7
- data/lib/karafka/swarm/node.rb +8 -0
- data/lib/karafka/swarm/supervisor.rb +9 -1
- data/lib/karafka/templates/karafka.rb.erb +11 -5
- data/lib/karafka/version.rb +1 -1
- metadata +237 -224
- data/lib/karafka/connection/rebalance_manager.rb +0 -116
- data/lib/karafka/instrumentation/callbacks/error.rb +0 -52
- data/lib/karafka/instrumentation/callbacks/rebalance.rb +0 -84
- data/lib/karafka/instrumentation/callbacks/statistics.rb +0 -55
- data/lib/karafka/pro/processing/adaptive_iterator/consumer.rb +0 -79
- data/lib/karafka/pro/processing/adaptive_iterator/tracker.rb +0 -92
- data/lib/karafka/pro/processing/collapser.rb +0 -79
- data/lib/karafka/pro/processing/coordinator.rb +0 -197
- data/lib/karafka/pro/processing/coordinators/errors_tracker.rb +0 -119
- data/lib/karafka/pro/processing/coordinators/filters_applier.rb +0 -152
- data/lib/karafka/pro/processing/coordinators/virtual_offset_manager.rb +0 -207
- data/lib/karafka/pro/processing/expansions_selector.rb +0 -52
- data/lib/karafka/pro/processing/filters/delayer.rb +0 -87
- data/lib/karafka/pro/processing/filters/inline_insights_delayer.rb +0 -95
- data/lib/karafka/pro/processing/filters/throttler.rb +0 -101
- data/lib/karafka/pro/processing/filters/virtual_limiter.rb +0 -74
- data/lib/karafka/pro/processing/jobs/eofed_non_blocking.rb +0 -51
- data/lib/karafka/pro/processing/jobs_builder.rb +0 -90
- data/lib/karafka/pro/processing/offset_metadata/consumer.rb +0 -61
- data/lib/karafka/pro/processing/offset_metadata/fetcher.rb +0 -149
- data/lib/karafka/pro/processing/offset_metadata/listener.rb +0 -63
- data/lib/karafka/pro/processing/parallel_segments/filters/base.rb +0 -98
- data/lib/karafka/pro/processing/parallel_segments/filters/default.rb +0 -110
- data/lib/karafka/pro/processing/parallel_segments/filters/mom.rb +0 -91
- data/lib/karafka/pro/processing/periodic_job/consumer.rb +0 -85
- data/lib/karafka/pro/processing/piping/consumer.rb +0 -149
- data/lib/karafka/pro/processing/strategies/aj/dlq_ftr_lrj_mom_vp.rb +0 -94
- data/lib/karafka/pro/processing/strategies/aj/dlq_ftr_mom.rb +0 -87
- data/lib/karafka/pro/processing/strategies/aj/dlq_ftr_mom_vp.rb +0 -85
- data/lib/karafka/pro/processing/strategies/aj/dlq_lrj_mom.rb +0 -81
- data/lib/karafka/pro/processing/strategies/aj/dlq_lrj_mom_vp.rb +0 -85
- data/lib/karafka/pro/processing/strategies/aj/dlq_mom.rb +0 -79
- data/lib/karafka/pro/processing/strategies/aj/dlq_mom_vp.rb +0 -84
- data/lib/karafka/pro/processing/strategies/aj/ftr_lrj_mom_vp.rb +0 -86
- data/lib/karafka/pro/processing/strategies/aj/lrj_mom.rb +0 -54
- data/lib/karafka/pro/processing/strategies/aj/lrj_mom_vp.rb +0 -101
- data/lib/karafka/pro/processing/strategies/base.rb +0 -43
- data/lib/karafka/pro/processing/strategies/default.rb +0 -416
- data/lib/karafka/pro/processing/strategies/dlq/default.rb +0 -280
- data/lib/karafka/pro/processing/strategies/dlq/ftr_lrj.rb +0 -90
- data/lib/karafka/pro/processing/strategies/dlq/ftr_lrj_mom.rb +0 -92
- data/lib/karafka/pro/processing/strategies/dlq/ftr_lrj_mom_vp.rb +0 -60
- data/lib/karafka/pro/processing/strategies/dlq/ftr_lrj_vp.rb +0 -58
- data/lib/karafka/pro/processing/strategies/dlq/ftr_mom.rb +0 -92
- data/lib/karafka/pro/processing/strategies/dlq/ftr_mom_vp.rb +0 -58
- data/lib/karafka/pro/processing/strategies/dlq/ftr_vp.rb +0 -57
- data/lib/karafka/pro/processing/strategies/dlq/lrj_mom.rb +0 -95
- data/lib/karafka/pro/processing/strategies/dlq/lrj_vp.rb +0 -56
- data/lib/karafka/pro/processing/strategies/dlq/mom.rb +0 -91
- data/lib/karafka/pro/processing/strategies/dlq/mom_vp.rb +0 -54
- data/lib/karafka/pro/processing/strategies/dlq/vp.rb +0 -57
- data/lib/karafka/pro/processing/strategies/ftr/default.rb +0 -141
- data/lib/karafka/pro/processing/strategies/ftr/vp.rb +0 -57
- data/lib/karafka/pro/processing/strategies/lrj/default.rb +0 -114
- data/lib/karafka/pro/processing/strategies/lrj/ftr.rb +0 -89
- data/lib/karafka/pro/processing/strategies/lrj/ftr_mom.rb +0 -87
- data/lib/karafka/pro/processing/strategies/lrj/ftr_mom_vp.rb +0 -57
- data/lib/karafka/pro/processing/strategies/lrj/ftr_vp.rb +0 -56
- data/lib/karafka/pro/processing/strategies/lrj/mom.rb +0 -96
- data/lib/karafka/pro/processing/strategies/mom/ftr_vp.rb +0 -54
- data/lib/karafka/pro/processing/strategies/vp/default.rb +0 -192
- data/lib/karafka/pro/processing/strategies.rb +0 -39
- data/lib/karafka/pro/processing/strategy_selector.rb +0 -102
- data/lib/karafka/pro/processing/subscription_groups_coordinator.rb +0 -68
- data/lib/karafka/pro/processing/virtual_partitions/distributors/balanced.rb +0 -77
- data/lib/karafka/pro/routing/features/active_job.rb +0 -43
- data/lib/karafka/pro/routing/features/adaptive_iterator/contracts/topic.rb +0 -89
- data/lib/karafka/pro/routing/features/adaptive_iterator/topic.rb +0 -88
- data/lib/karafka/pro/routing/features/adaptive_iterator.rb +0 -48
- data/lib/karafka/pro/routing/features/dead_letter_queue/contracts/topic.rb +0 -74
- data/lib/karafka/pro/routing/features/dead_letter_queue/topic.rb +0 -68
- data/lib/karafka/pro/routing/features/dead_letter_queue.rb +0 -44
- data/lib/karafka/pro/routing/features/delaying/topic.rb +0 -83
- data/lib/karafka/pro/routing/features/delaying.rb +0 -46
- data/lib/karafka/pro/routing/features/direct_assignments/contracts/topic.rb +0 -123
- data/lib/karafka/pro/routing/features/direct_assignments/subscription_group.rb +0 -95
- data/lib/karafka/pro/routing/features/direct_assignments/topic.rb +0 -95
- data/lib/karafka/pro/routing/features/direct_assignments.rb +0 -42
- data/lib/karafka/pro/routing/features/inline_insights/topic.rb +0 -78
- data/lib/karafka/pro/routing/features/inline_insights.rb +0 -43
- data/lib/karafka/pro/routing/features/long_running_job/config.rb +0 -45
- data/lib/karafka/pro/routing/features/long_running_job/topic.rb +0 -70
- data/lib/karafka/pro/routing/features/multiplexing/contracts/routing.rb +0 -81
- data/lib/karafka/pro/routing/features/multiplexing/contracts/topic.rb +0 -146
- data/lib/karafka/pro/routing/features/multiplexing/proxy.rb +0 -58
- data/lib/karafka/pro/routing/features/multiplexing.rb +0 -83
- data/lib/karafka/pro/routing/features/offset_metadata/config.rb +0 -50
- data/lib/karafka/pro/routing/features/offset_metadata/topic.rb +0 -91
- data/lib/karafka/pro/routing/features/parallel_segments/builder.rb +0 -72
- data/lib/karafka/pro/routing/features/parallel_segments/config.rb +0 -52
- data/lib/karafka/pro/routing/features/parallel_segments/consumer_group.rb +0 -108
- data/lib/karafka/pro/routing/features/patterns/config.rb +0 -71
- data/lib/karafka/pro/routing/features/patterns/consumer_group.rb +0 -89
- data/lib/karafka/pro/routing/features/patterns/contracts/topic.rb +0 -56
- data/lib/karafka/pro/routing/features/patterns/detector.rb +0 -96
- data/lib/karafka/pro/routing/features/patterns/pattern.rb +0 -112
- data/lib/karafka/pro/routing/features/patterns/topic.rb +0 -76
- data/lib/karafka/pro/routing/features/patterns/topics.rb +0 -70
- data/lib/karafka/pro/routing/features/patterns.rb +0 -50
- data/lib/karafka/pro/routing/features/periodic_job/config.rb +0 -54
- data/lib/karafka/pro/routing/features/periodic_job/contracts/topic.rb +0 -59
- data/lib/karafka/pro/routing/features/periodic_job/topic.rb +0 -120
- data/lib/karafka/pro/routing/features/periodic_job.rb +0 -44
- data/lib/karafka/pro/routing/features/recurring_tasks/builder.rb +0 -148
- data/lib/karafka/pro/routing/features/recurring_tasks/config.rb +0 -45
- data/lib/karafka/pro/routing/features/recurring_tasks/topic.rb +0 -70
- data/lib/karafka/pro/routing/features/recurring_tasks.rb +0 -42
- data/lib/karafka/pro/routing/features/scheduled_messages/builder.rb +0 -152
- data/lib/karafka/pro/routing/features/scheduled_messages/config.rb +0 -45
- data/lib/karafka/pro/routing/features/scheduled_messages/contracts/topic.rb +0 -55
- data/lib/karafka/pro/routing/features/scheduled_messages/topic.rb +0 -70
- data/lib/karafka/pro/routing/features/swarm/contracts/routing.rb +0 -92
- data/lib/karafka/pro/routing/features/swarm/contracts/topic.rb +0 -93
- data/lib/karafka/pro/routing/features/swarm/topic.rb +0 -103
- data/lib/karafka/pro/routing/features/swarm.rb +0 -56
- data/lib/karafka/pro/routing/features/virtual_partitions/config.rb +0 -67
- data/lib/karafka/pro/routing/features/virtual_partitions/contracts/topic.rb +0 -73
- data/lib/karafka/pro/routing/features/virtual_partitions/topic.rb +0 -99
- data/lib/karafka/pro/routing/features/virtual_partitions.rb +0 -44
- data/lib/karafka/processing/executor.rb +0 -216
- data/lib/karafka/processing/executors_buffer.rb +0 -90
- data/lib/karafka/processing/expansions_selector.rb +0 -22
- data/lib/karafka/processing/inline_insights/consumer.rb +0 -43
- data/lib/karafka/processing/inline_insights/listener.rb +0 -19
- data/lib/karafka/processing/inline_insights/tracker.rb +0 -129
- data/lib/karafka/processing/jobs/consume.rb +0 -47
- data/lib/karafka/processing/jobs/eofed.rb +0 -29
- data/lib/karafka/processing/jobs/idle.rb +0 -31
- data/lib/karafka/processing/jobs/revoked.rb +0 -29
- data/lib/karafka/processing/jobs/shutdown.rb +0 -30
- data/lib/karafka/processing/jobs_builder.rb +0 -34
- data/lib/karafka/processing/strategies/aj_dlq_mom.rb +0 -44
- data/lib/karafka/processing/strategies/aj_mom.rb +0 -21
- data/lib/karafka/processing/strategies/base.rb +0 -61
- data/lib/karafka/processing/strategies/default.rb +0 -214
- data/lib/karafka/processing/strategies/dlq.rb +0 -153
- data/lib/karafka/processing/strategies/dlq_mom.rb +0 -68
- data/lib/karafka/processing/strategies/mom.rb +0 -29
- data/lib/karafka/processing/workers_batch.rb +0 -29
- data/lib/karafka/routing/features/active_job/builder.rb +0 -33
- data/lib/karafka/routing/features/active_job/config.rb +0 -15
- data/lib/karafka/routing/features/active_job/contracts/topic.rb +0 -42
- data/lib/karafka/routing/features/active_job/proxy.rb +0 -14
- data/lib/karafka/routing/features/active_job/topic.rb +0 -48
- data/lib/karafka/routing/features/active_job.rb +0 -13
- data/lib/karafka/routing/features/dead_letter_queue/config.rb +0 -37
- data/lib/karafka/routing/features/dead_letter_queue/contracts/topic.rb +0 -56
- data/lib/karafka/routing/features/dead_letter_queue/topic.rb +0 -74
- data/lib/karafka/routing/features/dead_letter_queue.rb +0 -16
- data/lib/karafka/routing/features/declaratives/config.rb +0 -18
- data/lib/karafka/routing/features/eofed/config.rb +0 -15
- data/lib/karafka/routing/features/eofed/contracts/topic.rb +0 -37
- data/lib/karafka/routing/features/eofed/topic.rb +0 -40
- data/lib/karafka/routing/features/eofed.rb +0 -14
- data/lib/karafka/routing/features/inline_insights/config.rb +0 -15
- data/lib/karafka/routing/features/inline_insights/contracts/topic.rb +0 -25
- data/lib/karafka/routing/features/inline_insights/topic.rb +0 -40
- data/lib/karafka/routing/features/inline_insights.rb +0 -40
- data/lib/karafka/routing/features/manual_offset_management/config.rb +0 -15
- data/lib/karafka/routing/features/manual_offset_management/contracts/topic.rb +0 -25
- data/lib/karafka/routing/features/manual_offset_management/topic.rb +0 -44
- data/lib/karafka/routing/features/manual_offset_management.rb +0 -18
data/lib/karafka/pro/loader.rb
CHANGED
|
@@ -37,9 +37,10 @@ module Karafka
|
|
|
37
37
|
# We require those not to deal with this and then all works as expected
|
|
38
38
|
FORCE_LOADED = %w[
|
|
39
39
|
active_job/dispatcher
|
|
40
|
-
processing/jobs/consume_non_blocking
|
|
41
|
-
processing/strategies/base
|
|
40
|
+
processing/consumer_groups/jobs/consume_non_blocking
|
|
41
|
+
processing/consumer_groups/strategies/base
|
|
42
42
|
routing/features/base
|
|
43
|
+
routing/features/consumer_groups
|
|
43
44
|
encryption
|
|
44
45
|
encryption/cipher
|
|
45
46
|
encryption/setup/config
|
|
@@ -48,8 +49,7 @@ module Karafka
|
|
|
48
49
|
cli/topics
|
|
49
50
|
].freeze
|
|
50
51
|
|
|
51
|
-
# Zeitwerk pro loader
|
|
52
|
-
# We need to have one per process, that's why it's set as a constant
|
|
52
|
+
# Zeitwerk pro loader We need to have one per process, that's why it's set as a constant
|
|
53
53
|
PRO_LOADER = Zeitwerk::Loader.new
|
|
54
54
|
|
|
55
55
|
private_constant :PRO_LOADER
|
|
@@ -83,7 +83,7 @@ module Karafka
|
|
|
83
83
|
features.each { |feature| feature.post_setup(config) }
|
|
84
84
|
|
|
85
85
|
# We initialize it here so we don't initialize it during multi-threading work
|
|
86
|
-
Processing::SubscriptionGroupsCoordinator.instance
|
|
86
|
+
Processing::ConsumerGroups::SubscriptionGroupsCoordinator.instance
|
|
87
87
|
end
|
|
88
88
|
|
|
89
89
|
# Runs operations needed after fork in swarm for features that need it
|
|
@@ -113,20 +113,23 @@ module Karafka
|
|
|
113
113
|
def reconfigure(config)
|
|
114
114
|
icfg = config.internal
|
|
115
115
|
|
|
116
|
+
Karafka::Setup::DefaultsInjector.singleton_class.prepend(Setup::DefaultsInjector)
|
|
117
|
+
|
|
116
118
|
icfg.cli.contract = Cli::Contracts::Server.new
|
|
117
119
|
|
|
118
120
|
# Use manager that supports multiplexing
|
|
119
121
|
icfg.connection.manager = Connection::Manager.new
|
|
120
122
|
|
|
121
|
-
icfg.processing.coordinator_class = Processing::Coordinator
|
|
122
|
-
icfg.processing.errors_tracker_class = Processing::Coordinators::ErrorsTracker
|
|
123
|
-
icfg.processing.partitioner_class = Processing::Partitioner
|
|
124
123
|
icfg.processing.scheduler_class = Processing::Schedulers::Default
|
|
125
124
|
icfg.processing.jobs_queue_class = Processing::JobsQueue
|
|
126
|
-
|
|
127
|
-
icfg.processing.
|
|
128
|
-
icfg.processing.
|
|
129
|
-
icfg.processing.
|
|
125
|
+
|
|
126
|
+
icfg.processing.consumer_groups.coordinator_class = Processing::ConsumerGroups::Coordinator
|
|
127
|
+
icfg.processing.consumer_groups.errors_tracker_class = Processing::ConsumerGroups::Coordinators::ErrorsTracker
|
|
128
|
+
icfg.processing.consumer_groups.partitioner_class = Processing::ConsumerGroups::Partitioner
|
|
129
|
+
icfg.processing.consumer_groups.executor_class = Processing::ConsumerGroups::Executor
|
|
130
|
+
icfg.processing.consumer_groups.jobs_builder = Processing::ConsumerGroups::JobsBuilder.new
|
|
131
|
+
icfg.processing.consumer_groups.strategy_selector = Processing::ConsumerGroups::StrategySelector.new
|
|
132
|
+
icfg.processing.consumer_groups.expansions_selector = Processing::ConsumerGroups::ExpansionsSelector.new
|
|
130
133
|
|
|
131
134
|
icfg.active_job.consumer_class = ActiveJob::Consumer
|
|
132
135
|
icfg.active_job.dispatcher = ActiveJob::Dispatcher.new
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Karafka Pro - Source Available Commercial Software
|
|
4
|
+
# Copyright (c) 2017-present Maciej Mensfeld. All rights reserved.
|
|
5
|
+
#
|
|
6
|
+
# This software is NOT open source. It is source-available commercial software
|
|
7
|
+
# requiring a paid license for use. It is NOT covered by LGPL.
|
|
8
|
+
#
|
|
9
|
+
# The author retains all right, title, and interest in this software,
|
|
10
|
+
# including all copyrights, patents, and other intellectual property rights.
|
|
11
|
+
# No patent rights are granted under this license.
|
|
12
|
+
#
|
|
13
|
+
# PROHIBITED:
|
|
14
|
+
# - Use without a valid commercial license
|
|
15
|
+
# - Redistribution, modification, or derivative works without authorization
|
|
16
|
+
# - Reverse engineering, decompilation, or disassembly of this software
|
|
17
|
+
# - Use as training data for AI/ML models or inclusion in datasets
|
|
18
|
+
# - Scraping, crawling, or automated collection for any purpose
|
|
19
|
+
#
|
|
20
|
+
# PERMITTED:
|
|
21
|
+
# - Reading, referencing, and linking for personal or commercial use
|
|
22
|
+
# - Runtime retrieval by AI assistants, coding agents, and RAG systems
|
|
23
|
+
# for the purpose of providing contextual help to Karafka users
|
|
24
|
+
#
|
|
25
|
+
# Receipt, viewing, or possession of this software does not convey or
|
|
26
|
+
# imply any license or right beyond those expressly stated above.
|
|
27
|
+
#
|
|
28
|
+
# License: https://karafka.io/docs/Pro-License-Comm/
|
|
29
|
+
# Contact: contact@karafka.io
|
|
30
|
+
|
|
31
|
+
module Karafka
|
|
32
|
+
module Pro
|
|
33
|
+
module Processing
|
|
34
|
+
# Consumer-group-specific Pro processing components (driven by rebalance callbacks and
|
|
35
|
+
# partition ticks). Parallel `ShareGroups` will live next to this namespace once KIP-932
|
|
36
|
+
# lands.
|
|
37
|
+
module ConsumerGroups
|
|
38
|
+
# Namespace for adaptive iterator consumer components
|
|
39
|
+
module AdaptiveIterator
|
|
40
|
+
# Consumer enhancements needed to wrap the batch iterator for adaptive iterating
|
|
41
|
+
# It automatically marks as consumed, ensures that we do not reach `max.poll.interval.ms`
|
|
42
|
+
# and does other stuff to simplify user per-message processing
|
|
43
|
+
module Consumer
|
|
44
|
+
# @param args [Array] anything accepted by `Karafka::Messages::Messages#each`
|
|
45
|
+
def each(*args)
|
|
46
|
+
adi_config = topic.adaptive_iterator
|
|
47
|
+
|
|
48
|
+
tracker = Tracker.new(
|
|
49
|
+
adi_config.safety_margin,
|
|
50
|
+
coordinator.last_polled_at,
|
|
51
|
+
topic.subscription_group.kafka.fetch(:"max.poll.interval.ms")
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
messages.each(*args) do |message|
|
|
55
|
+
# Always stop if we've lost the assignment
|
|
56
|
+
return if revoked?
|
|
57
|
+
# No automatic marking risk when mom is enabled so we can fast stop
|
|
58
|
+
return if Karafka::App.done? && topic.manual_offset_management?
|
|
59
|
+
|
|
60
|
+
# Seek request on done will allow us to stop without marking the offset when user had
|
|
61
|
+
# the automatic offset marking. This should not be a big network traffic issue for
|
|
62
|
+
# the end user as we're stopping anyhow but should improve shutdown time
|
|
63
|
+
if tracker.enough? || Karafka::App.done?
|
|
64
|
+
# Enough means we no longer have time to process more data without polling as we
|
|
65
|
+
# risk reaching max poll interval. Instead we seek and we will poll again soon.
|
|
66
|
+
seek(message.offset, reset_offset: true)
|
|
67
|
+
|
|
68
|
+
return
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
tracker.track { yield(message) }
|
|
72
|
+
|
|
73
|
+
# Clean if this is what user configured
|
|
74
|
+
message.clean! if adi_config.clean_after_yielding?
|
|
75
|
+
|
|
76
|
+
public_send(adi_config.marking_method, message)
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Karafka Pro - Source Available Commercial Software
|
|
4
|
+
# Copyright (c) 2017-present Maciej Mensfeld. All rights reserved.
|
|
5
|
+
#
|
|
6
|
+
# This software is NOT open source. It is source-available commercial software
|
|
7
|
+
# requiring a paid license for use. It is NOT covered by LGPL.
|
|
8
|
+
#
|
|
9
|
+
# The author retains all right, title, and interest in this software,
|
|
10
|
+
# including all copyrights, patents, and other intellectual property rights.
|
|
11
|
+
# No patent rights are granted under this license.
|
|
12
|
+
#
|
|
13
|
+
# PROHIBITED:
|
|
14
|
+
# - Use without a valid commercial license
|
|
15
|
+
# - Redistribution, modification, or derivative works without authorization
|
|
16
|
+
# - Reverse engineering, decompilation, or disassembly of this software
|
|
17
|
+
# - Use as training data for AI/ML models or inclusion in datasets
|
|
18
|
+
# - Scraping, crawling, or automated collection for any purpose
|
|
19
|
+
#
|
|
20
|
+
# PERMITTED:
|
|
21
|
+
# - Reading, referencing, and linking for personal or commercial use
|
|
22
|
+
# - Runtime retrieval by AI assistants, coding agents, and RAG systems
|
|
23
|
+
# for the purpose of providing contextual help to Karafka users
|
|
24
|
+
#
|
|
25
|
+
# Receipt, viewing, or possession of this software does not convey or
|
|
26
|
+
# imply any license or right beyond those expressly stated above.
|
|
27
|
+
#
|
|
28
|
+
# License: https://karafka.io/docs/Pro-License-Comm/
|
|
29
|
+
# Contact: contact@karafka.io
|
|
30
|
+
|
|
31
|
+
module Karafka
|
|
32
|
+
module Pro
|
|
33
|
+
module Processing
|
|
34
|
+
# Consumer-group-specific Pro processing components (driven by rebalance callbacks and
|
|
35
|
+
# partition ticks). Parallel `ShareGroups` will live next to this namespace once KIP-932
|
|
36
|
+
# lands.
|
|
37
|
+
module ConsumerGroups
|
|
38
|
+
module AdaptiveIterator
|
|
39
|
+
# Tracker is responsible for monitoring the processing of messages within the poll
|
|
40
|
+
# interval limitation.
|
|
41
|
+
# It ensures that the consumer does not exceed the maximum poll interval by tracking the
|
|
42
|
+
# processing cost and determining when to halt further processing (if needed).
|
|
43
|
+
class Tracker
|
|
44
|
+
include Karafka::Core::Helpers::Time
|
|
45
|
+
|
|
46
|
+
# Initializes a new Tracker instance.
|
|
47
|
+
#
|
|
48
|
+
# @param safety_margin [Float] The safety margin percentage (0-100) to leave as a buffer.
|
|
49
|
+
# @param last_polled_at [Float] The timestamp of the last polling in milliseconds.
|
|
50
|
+
# @param max_poll_interval_ms [Integer] The maximum poll interval time in milliseconds.
|
|
51
|
+
def initialize(
|
|
52
|
+
safety_margin,
|
|
53
|
+
last_polled_at,
|
|
54
|
+
max_poll_interval_ms
|
|
55
|
+
)
|
|
56
|
+
@safety_margin = safety_margin / 100.0 # Convert percentage to decimal
|
|
57
|
+
@last_polled_at = last_polled_at
|
|
58
|
+
@max_processing_cost = 0
|
|
59
|
+
@max_poll_interval_ms = max_poll_interval_ms
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Tracks the processing time of a block and updates the maximum processing cost.
|
|
63
|
+
#
|
|
64
|
+
# @yield Executes the block, measuring the time taken for processing.
|
|
65
|
+
def track
|
|
66
|
+
before = monotonic_now
|
|
67
|
+
|
|
68
|
+
yield
|
|
69
|
+
|
|
70
|
+
time_taken = monotonic_now - before
|
|
71
|
+
|
|
72
|
+
return unless time_taken > @max_processing_cost
|
|
73
|
+
|
|
74
|
+
@max_processing_cost = time_taken
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Determines if there is enough time left to process more messages without exceeding the
|
|
78
|
+
# maximum poll interval, considering both the safety margin and adaptive margin.
|
|
79
|
+
#
|
|
80
|
+
# @return [Boolean] Returns true if it is time to stop processing. False otherwise.
|
|
81
|
+
def enough?
|
|
82
|
+
elapsed_time_ms = monotonic_now - @last_polled_at
|
|
83
|
+
remaining_time_ms = @max_poll_interval_ms - elapsed_time_ms
|
|
84
|
+
|
|
85
|
+
safety_margin_ms = @max_poll_interval_ms * @safety_margin
|
|
86
|
+
|
|
87
|
+
return true if remaining_time_ms <= safety_margin_ms
|
|
88
|
+
return true if remaining_time_ms - @max_processing_cost <= safety_margin_ms
|
|
89
|
+
|
|
90
|
+
false
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Karafka Pro - Source Available Commercial Software
|
|
4
|
+
# Copyright (c) 2017-present Maciej Mensfeld. All rights reserved.
|
|
5
|
+
#
|
|
6
|
+
# This software is NOT open source. It is source-available commercial software
|
|
7
|
+
# requiring a paid license for use. It is NOT covered by LGPL.
|
|
8
|
+
#
|
|
9
|
+
# The author retains all right, title, and interest in this software,
|
|
10
|
+
# including all copyrights, patents, and other intellectual property rights.
|
|
11
|
+
# No patent rights are granted under this license.
|
|
12
|
+
#
|
|
13
|
+
# PROHIBITED:
|
|
14
|
+
# - Use without a valid commercial license
|
|
15
|
+
# - Redistribution, modification, or derivative works without authorization
|
|
16
|
+
# - Reverse engineering, decompilation, or disassembly of this software
|
|
17
|
+
# - Use as training data for AI/ML models or inclusion in datasets
|
|
18
|
+
# - Scraping, crawling, or automated collection for any purpose
|
|
19
|
+
#
|
|
20
|
+
# PERMITTED:
|
|
21
|
+
# - Reading, referencing, and linking for personal or commercial use
|
|
22
|
+
# - Runtime retrieval by AI assistants, coding agents, and RAG systems
|
|
23
|
+
# for the purpose of providing contextual help to Karafka users
|
|
24
|
+
#
|
|
25
|
+
# Receipt, viewing, or possession of this software does not convey or
|
|
26
|
+
# imply any license or right beyond those expressly stated above.
|
|
27
|
+
#
|
|
28
|
+
# License: https://karafka.io/docs/Pro-License-Comm/
|
|
29
|
+
# Contact: contact@karafka.io
|
|
30
|
+
|
|
31
|
+
module Karafka
|
|
32
|
+
module Pro
|
|
33
|
+
module Processing
|
|
34
|
+
# Consumer-group-specific Pro processing components (driven by rebalance callbacks and
|
|
35
|
+
# partition ticks). Parallel `ShareGroups` will live next to this namespace once KIP-932
|
|
36
|
+
# lands.
|
|
37
|
+
module ConsumerGroups
|
|
38
|
+
# Manages the collapse of virtual partitions
|
|
39
|
+
# Since any non-virtual partition is actually a virtual partition of size one, we can use
|
|
40
|
+
# it in a generic manner without having to distinguish between those cases.
|
|
41
|
+
#
|
|
42
|
+
# We need to have notion of the offset until we want to collapse because upon pause and retry
|
|
43
|
+
# rdkafka may purge the buffer. This means, that we may end up with smaller or bigger
|
|
44
|
+
# (different) dataset and without tracking the end of collapse, there would be a chance for
|
|
45
|
+
# things to flicker. Tracking allows us to ensure, that collapse is happening until all the
|
|
46
|
+
# messages from the corrupted batch are processed.
|
|
47
|
+
class Collapser
|
|
48
|
+
# When initialized, nothing is collapsed
|
|
49
|
+
def initialize
|
|
50
|
+
@collapsed = false
|
|
51
|
+
@until_offset = -1
|
|
52
|
+
@mutex = Mutex.new
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# @return [Boolean] Should we collapse into a single consumer
|
|
56
|
+
def collapsed?
|
|
57
|
+
@collapsed
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Collapse until given offset. Until given offset is encountered or offset bigger than that
|
|
61
|
+
# we keep collapsing.
|
|
62
|
+
# @param offset [Integer] offset until which we keep the collapse
|
|
63
|
+
def collapse_until!(offset)
|
|
64
|
+
@mutex.synchronize do
|
|
65
|
+
# We check it here in case after a pause and re-fetch we would get less messages and
|
|
66
|
+
# one of them would cause an error. We do not want to overwrite the offset here unless
|
|
67
|
+
# it is bigger.
|
|
68
|
+
@until_offset = offset if offset > @until_offset
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Sets the collapse state based on the first collective offset that we are going to process
|
|
73
|
+
# and makes the decision whether or not we need to still keep the collapse.
|
|
74
|
+
# @param first_offset [Integer] first offset from a collective batch
|
|
75
|
+
def refresh!(first_offset)
|
|
76
|
+
@mutex.synchronize do
|
|
77
|
+
@collapsed = first_offset < @until_offset
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Karafka Pro - Source Available Commercial Software
|
|
4
|
+
# Copyright (c) 2017-present Maciej Mensfeld. All rights reserved.
|
|
5
|
+
#
|
|
6
|
+
# This software is NOT open source. It is source-available commercial software
|
|
7
|
+
# requiring a paid license for use. It is NOT covered by LGPL.
|
|
8
|
+
#
|
|
9
|
+
# The author retains all right, title, and interest in this software,
|
|
10
|
+
# including all copyrights, patents, and other intellectual property rights.
|
|
11
|
+
# No patent rights are granted under this license.
|
|
12
|
+
#
|
|
13
|
+
# PROHIBITED:
|
|
14
|
+
# - Use without a valid commercial license
|
|
15
|
+
# - Redistribution, modification, or derivative works without authorization
|
|
16
|
+
# - Reverse engineering, decompilation, or disassembly of this software
|
|
17
|
+
# - Use as training data for AI/ML models or inclusion in datasets
|
|
18
|
+
# - Scraping, crawling, or automated collection for any purpose
|
|
19
|
+
#
|
|
20
|
+
# PERMITTED:
|
|
21
|
+
# - Reading, referencing, and linking for personal or commercial use
|
|
22
|
+
# - Runtime retrieval by AI assistants, coding agents, and RAG systems
|
|
23
|
+
# for the purpose of providing contextual help to Karafka users
|
|
24
|
+
#
|
|
25
|
+
# Receipt, viewing, or possession of this software does not convey or
|
|
26
|
+
# imply any license or right beyond those expressly stated above.
|
|
27
|
+
#
|
|
28
|
+
# License: https://karafka.io/docs/Pro-License-Comm/
|
|
29
|
+
# Contact: contact@karafka.io
|
|
30
|
+
|
|
31
|
+
module Karafka
|
|
32
|
+
module Pro
|
|
33
|
+
module Processing
|
|
34
|
+
# Consumer-group-specific Pro processing components (driven by rebalance callbacks and
|
|
35
|
+
# partition ticks). Parallel `ShareGroups` will live next to this namespace once KIP-932
|
|
36
|
+
# lands.
|
|
37
|
+
module ConsumerGroups
|
|
38
|
+
# Pro coordinator that provides extra orchestration methods useful for parallel processing
|
|
39
|
+
# within the same partition
|
|
40
|
+
class Coordinator < Karafka::Processing::ConsumerGroups::Coordinator
|
|
41
|
+
extend Forwardable
|
|
42
|
+
include Helpers::ConfigImporter.new(
|
|
43
|
+
errors_tracker_class: %i[internal processing consumer_groups errors_tracker_class]
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
def_delegators :@collapser, :collapsed?, :collapse_until!
|
|
47
|
+
|
|
48
|
+
attr_reader :filter, :virtual_offset_manager, :shared_mutex, :errors_tracker
|
|
49
|
+
|
|
50
|
+
# @param args [Object] anything the base coordinator accepts
|
|
51
|
+
def initialize(*args)
|
|
52
|
+
super
|
|
53
|
+
|
|
54
|
+
@executed = []
|
|
55
|
+
@errors_tracker = errors_tracker_class.new(topic, partition)
|
|
56
|
+
@flow_mutex = Mutex.new
|
|
57
|
+
# Lock for user code synchronization
|
|
58
|
+
# We do not want to mix coordinator lock with the user lock not to create cases where
|
|
59
|
+
# user imposed lock would lock the internal operations of Karafka
|
|
60
|
+
# This shared lock can be used by the end user as it is not used internally by the
|
|
61
|
+
# framework and can be used for user-facing locking
|
|
62
|
+
@shared_mutex = Mutex.new
|
|
63
|
+
@collapser = Collapser.new
|
|
64
|
+
@filter = Coordinators::FiltersApplier.new(self)
|
|
65
|
+
|
|
66
|
+
return unless topic.virtual_partitions?
|
|
67
|
+
|
|
68
|
+
@virtual_offset_manager = Coordinators::VirtualOffsetManager.new(
|
|
69
|
+
topic.name,
|
|
70
|
+
partition,
|
|
71
|
+
topic.virtual_partitions.offset_metadata_strategy
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
# We register our own "internal" filter to support filtering of messages that were marked
|
|
75
|
+
# as consumed virtually
|
|
76
|
+
@filter.filters << Filters::VirtualLimiter.new(
|
|
77
|
+
@virtual_offset_manager,
|
|
78
|
+
@collapser
|
|
79
|
+
)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# Starts the coordination process
|
|
83
|
+
# @param messages [Array<Karafka::Messages::Message>] messages for which processing we are
|
|
84
|
+
# going to coordinate.
|
|
85
|
+
def start(messages)
|
|
86
|
+
super
|
|
87
|
+
|
|
88
|
+
@collapser.refresh!(messages.first.offset)
|
|
89
|
+
|
|
90
|
+
@filter.apply!(messages)
|
|
91
|
+
|
|
92
|
+
# Do not clear coordinator errors storage when we are retrying, so we can reference the
|
|
93
|
+
# errors that have happened during recovery. This can be useful for implementing custom
|
|
94
|
+
# flows. There can be more errors than one when running with virtual partitions so we
|
|
95
|
+
# need to make sure we collect them all. Under collapse when we reference a given
|
|
96
|
+
# consumer we should be able to get all the errors and not just first/last.
|
|
97
|
+
#
|
|
98
|
+
# @note We use zero as the attempt mark because we are not "yet" in the attempt 1
|
|
99
|
+
@errors_tracker.clear if attempt.zero?
|
|
100
|
+
@executed.clear
|
|
101
|
+
|
|
102
|
+
# We keep the old processed offsets until the collapsing is done and regular processing
|
|
103
|
+
# with virtualization is restored
|
|
104
|
+
@virtual_offset_manager.clear if topic.virtual_partitions? && !collapsed?
|
|
105
|
+
|
|
106
|
+
@last_message = messages.last
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# Sets the consumer failure status and additionally starts the collapse until
|
|
110
|
+
#
|
|
111
|
+
# @param consumer [Karafka::BaseConsumer] consumer that failed
|
|
112
|
+
# @param error [StandardError] error from the failure
|
|
113
|
+
def failure!(consumer, error)
|
|
114
|
+
super
|
|
115
|
+
@errors_tracker << error
|
|
116
|
+
collapse_until!(@last_message.offset + 1)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# @return [Boolean] did any of the filters apply any logic that would cause use to run
|
|
120
|
+
# the filtering flow
|
|
121
|
+
def filtered?
|
|
122
|
+
@filter.applied?
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
# @return [Boolean] is the coordinated work finished or not
|
|
126
|
+
# @note Used only in the consume operation context
|
|
127
|
+
def finished?
|
|
128
|
+
@running_jobs[:consume].zero?
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
# Runs synchronized code once for a collective of virtual partitions prior to work being
|
|
132
|
+
# enqueued
|
|
133
|
+
def on_enqueued
|
|
134
|
+
@flow_mutex.synchronize do
|
|
135
|
+
return unless executable?(:on_enqueued)
|
|
136
|
+
|
|
137
|
+
yield(@last_message)
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
# Runs given code only once per all the coordinated jobs upon starting first of them
|
|
142
|
+
def on_started
|
|
143
|
+
@flow_mutex.synchronize do
|
|
144
|
+
return unless executable?(:on_started)
|
|
145
|
+
|
|
146
|
+
yield(@last_message)
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
# Runs given code once when all the work that is suppose to be coordinated is finished
|
|
151
|
+
# It runs once per all the coordinated jobs and should be used to run any type of post
|
|
152
|
+
# jobs coordination processing execution
|
|
153
|
+
def on_finished
|
|
154
|
+
@flow_mutex.synchronize do
|
|
155
|
+
return unless finished?
|
|
156
|
+
return unless executable?(:on_finished)
|
|
157
|
+
|
|
158
|
+
yield(@last_message)
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
# Runs once after a partition is revoked
|
|
163
|
+
def on_revoked
|
|
164
|
+
@flow_mutex.synchronize do
|
|
165
|
+
return unless executable?(:on_revoked)
|
|
166
|
+
|
|
167
|
+
yield(@last_message)
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
# @param interval [Integer] milliseconds of activity
|
|
172
|
+
# @return [Boolean] was this partition in activity within last `interval` milliseconds
|
|
173
|
+
# @note Will return true also if currently active
|
|
174
|
+
def active_within?(interval)
|
|
175
|
+
# its always active if there's any job related to this coordinator that is still
|
|
176
|
+
# enqueued or running
|
|
177
|
+
return true if @running_jobs.values.any?(:positive?)
|
|
178
|
+
|
|
179
|
+
# Otherwise we check last time any job of this coordinator was active
|
|
180
|
+
@changed_at + interval > monotonic_now
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
private
|
|
184
|
+
|
|
185
|
+
# Checks if given action is executable once. If it is and true is returned, this method
|
|
186
|
+
# will return false next time it is used.
|
|
187
|
+
#
|
|
188
|
+
# @param action [Symbol] what action we want to perform
|
|
189
|
+
# @return [Boolean] true if we can
|
|
190
|
+
# @note This method needs to run behind a mutex.
|
|
191
|
+
def executable?(action)
|
|
192
|
+
return false if @executed.include?(action)
|
|
193
|
+
|
|
194
|
+
@executed << action
|
|
195
|
+
|
|
196
|
+
true
|
|
197
|
+
end
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
end
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Karafka Pro - Source Available Commercial Software
|
|
4
|
+
# Copyright (c) 2017-present Maciej Mensfeld. All rights reserved.
|
|
5
|
+
#
|
|
6
|
+
# This software is NOT open source. It is source-available commercial software
|
|
7
|
+
# requiring a paid license for use. It is NOT covered by LGPL.
|
|
8
|
+
#
|
|
9
|
+
# The author retains all right, title, and interest in this software,
|
|
10
|
+
# including all copyrights, patents, and other intellectual property rights.
|
|
11
|
+
# No patent rights are granted under this license.
|
|
12
|
+
#
|
|
13
|
+
# PROHIBITED:
|
|
14
|
+
# - Use without a valid commercial license
|
|
15
|
+
# - Redistribution, modification, or derivative works without authorization
|
|
16
|
+
# - Reverse engineering, decompilation, or disassembly of this software
|
|
17
|
+
# - Use as training data for AI/ML models or inclusion in datasets
|
|
18
|
+
# - Scraping, crawling, or automated collection for any purpose
|
|
19
|
+
#
|
|
20
|
+
# PERMITTED:
|
|
21
|
+
# - Reading, referencing, and linking for personal or commercial use
|
|
22
|
+
# - Runtime retrieval by AI assistants, coding agents, and RAG systems
|
|
23
|
+
# for the purpose of providing contextual help to Karafka users
|
|
24
|
+
#
|
|
25
|
+
# Receipt, viewing, or possession of this software does not convey or
|
|
26
|
+
# imply any license or right beyond those expressly stated above.
|
|
27
|
+
#
|
|
28
|
+
# License: https://karafka.io/docs/Pro-License-Comm/
|
|
29
|
+
# Contact: contact@karafka.io
|
|
30
|
+
|
|
31
|
+
module Karafka
|
|
32
|
+
module Pro
|
|
33
|
+
module Processing
|
|
34
|
+
# Consumer-group-specific Pro processing components (driven by rebalance callbacks and
|
|
35
|
+
# partition ticks). Parallel `ShareGroups` will live next to this namespace once KIP-932
|
|
36
|
+
# lands.
|
|
37
|
+
module ConsumerGroups
|
|
38
|
+
# Namespace for Pro coordinator related sub-components
|
|
39
|
+
module Coordinators
|
|
40
|
+
# Object used to track errors in between executions to be able to build error-type based
|
|
41
|
+
# recovery flows.
|
|
42
|
+
class ErrorsTracker
|
|
43
|
+
include Enumerable
|
|
44
|
+
|
|
45
|
+
# @return [Karafka::Routing::Topic] topic of this error tracker
|
|
46
|
+
attr_reader :topic
|
|
47
|
+
|
|
48
|
+
# @return [Integer] partition of this error tracker
|
|
49
|
+
attr_reader :partition
|
|
50
|
+
|
|
51
|
+
# @return [Hash]
|
|
52
|
+
attr_reader :counts
|
|
53
|
+
|
|
54
|
+
# @return [String]
|
|
55
|
+
attr_reader :trace_id
|
|
56
|
+
|
|
57
|
+
# Max errors we keep in memory.
|
|
58
|
+
# We do not want to keep more because for DLQ-less this would cause memory-leaks.
|
|
59
|
+
# We do however count per class for granular error counting
|
|
60
|
+
STORAGE_LIMIT = 100
|
|
61
|
+
|
|
62
|
+
private_constant :STORAGE_LIMIT
|
|
63
|
+
|
|
64
|
+
# @param topic [Karafka::Routing::Topic]
|
|
65
|
+
# @param partition [Integer]
|
|
66
|
+
# @param limit [Integer] max number of errors we want to keep for reference when
|
|
67
|
+
# implementing custom error handling.
|
|
68
|
+
# @note `limit` does not apply to the counts. They will work beyond the number of errors
|
|
69
|
+
# occurring
|
|
70
|
+
def initialize(topic, partition, limit: STORAGE_LIMIT)
|
|
71
|
+
@errors = []
|
|
72
|
+
@counts = Hash.new { |hash, key| hash[key] = 0 }
|
|
73
|
+
@topic = topic
|
|
74
|
+
@partition = partition
|
|
75
|
+
@limit = limit
|
|
76
|
+
@trace_id = SecureRandom.uuid
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# Clears all the errors
|
|
80
|
+
def clear
|
|
81
|
+
@errors.clear
|
|
82
|
+
@counts.clear
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# @param error [StandardError] adds the error to the tracker
|
|
86
|
+
def <<(error)
|
|
87
|
+
@errors.shift if @errors.size >= @limit
|
|
88
|
+
@errors << error
|
|
89
|
+
@counts[error.class] += 1
|
|
90
|
+
@trace_id = SecureRandom.uuid
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# @return [Boolean] is the error tracker empty
|
|
94
|
+
def empty?
|
|
95
|
+
@errors.empty?
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# @return [Integer] number of elements
|
|
99
|
+
def size
|
|
100
|
+
# We use counts reference of all errors and not the `@errors` array because it allows
|
|
101
|
+
# us to go beyond the whole errors storage limit
|
|
102
|
+
@counts.values.sum
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# @return [StandardError, nil] last error that occurred or nil if no errors
|
|
106
|
+
def last
|
|
107
|
+
@errors.last
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# Iterates over errors
|
|
111
|
+
def each(&)
|
|
112
|
+
@errors.each(&)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# @return [Array<StandardError>] array with all the errors that occurred
|
|
116
|
+
def all
|
|
117
|
+
@errors
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|