karafka 1.4.12 → 2.2.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/.github/FUNDING.yml +1 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +10 -9
- data/.github/workflows/ci.yml +169 -31
- data/.rspec +4 -0
- data/.ruby-version +1 -1
- data/CHANGELOG.md +716 -607
- data/CONTRIBUTING.md +10 -19
- data/Gemfile +7 -0
- data/Gemfile.lock +69 -92
- data/LICENSE +17 -0
- data/LICENSE-COMM +89 -0
- data/LICENSE-LGPL +165 -0
- data/README.md +48 -47
- data/bin/benchmarks +99 -0
- data/bin/create_token +22 -0
- data/bin/integrations +310 -0
- data/bin/karafka +5 -14
- data/bin/record_rss +50 -0
- data/bin/rspecs +6 -0
- data/bin/scenario +29 -0
- data/bin/stress_many +13 -0
- data/bin/stress_one +13 -0
- data/bin/verify_license_integrity +37 -0
- data/bin/wait_for_kafka +24 -0
- data/certs/cert_chain.pem +26 -0
- data/certs/karafka-pro.pem +11 -0
- data/config/locales/errors.yml +97 -0
- data/config/locales/pro_errors.yml +59 -0
- data/docker-compose.yml +19 -11
- data/karafka.gemspec +26 -22
- data/lib/active_job/karafka.rb +17 -0
- data/lib/active_job/queue_adapters/karafka_adapter.rb +32 -0
- data/lib/karafka/active_job/consumer.rb +49 -0
- data/lib/karafka/active_job/current_attributes/loading.rb +36 -0
- data/lib/karafka/active_job/current_attributes/persistence.rb +28 -0
- data/lib/karafka/active_job/current_attributes.rb +42 -0
- data/lib/karafka/active_job/dispatcher.rb +69 -0
- data/lib/karafka/active_job/job_extensions.rb +34 -0
- data/lib/karafka/active_job/job_options_contract.rb +32 -0
- data/lib/karafka/admin.rb +313 -0
- data/lib/karafka/app.rb +47 -23
- data/lib/karafka/base_consumer.rb +260 -29
- data/lib/karafka/cli/base.rb +67 -36
- data/lib/karafka/cli/console.rb +18 -12
- data/lib/karafka/cli/help.rb +24 -0
- data/lib/karafka/cli/info.rb +47 -12
- data/lib/karafka/cli/install.rb +23 -14
- data/lib/karafka/cli/server.rb +101 -44
- data/lib/karafka/cli/topics.rb +146 -0
- data/lib/karafka/cli.rb +24 -27
- data/lib/karafka/connection/client.rb +553 -90
- data/lib/karafka/connection/consumer_group_coordinator.rb +48 -0
- data/lib/karafka/connection/listener.rb +294 -38
- data/lib/karafka/connection/listeners_batch.rb +40 -0
- data/lib/karafka/connection/messages_buffer.rb +84 -0
- data/lib/karafka/connection/pauses_manager.rb +46 -0
- data/lib/karafka/connection/proxy.rb +98 -0
- data/lib/karafka/connection/raw_messages_buffer.rb +101 -0
- data/lib/karafka/connection/rebalance_manager.rb +105 -0
- data/lib/karafka/contracts/base.rb +17 -0
- data/lib/karafka/contracts/config.rb +130 -11
- data/lib/karafka/contracts/consumer_group.rb +32 -187
- data/lib/karafka/contracts/server_cli_options.rb +80 -19
- data/lib/karafka/contracts/topic.rb +65 -0
- data/lib/karafka/contracts.rb +1 -1
- data/lib/karafka/embedded.rb +36 -0
- data/lib/karafka/env.rb +46 -0
- data/lib/karafka/errors.rb +37 -21
- data/lib/karafka/helpers/async.rb +33 -0
- data/lib/karafka/helpers/colorize.rb +26 -0
- data/lib/karafka/helpers/multi_delegator.rb +2 -2
- data/lib/karafka/instrumentation/callbacks/error.rb +39 -0
- data/lib/karafka/instrumentation/callbacks/rebalance.rb +64 -0
- data/lib/karafka/instrumentation/callbacks/statistics.rb +51 -0
- data/lib/karafka/instrumentation/logger_listener.rb +303 -0
- data/lib/karafka/instrumentation/monitor.rb +13 -61
- data/lib/karafka/instrumentation/notifications.rb +79 -0
- data/lib/karafka/instrumentation/proctitle_listener.rb +7 -16
- data/lib/karafka/instrumentation/vendors/appsignal/base.rb +30 -0
- data/lib/karafka/instrumentation/vendors/appsignal/client.rb +122 -0
- data/lib/karafka/instrumentation/vendors/appsignal/dashboard.json +222 -0
- data/lib/karafka/instrumentation/vendors/appsignal/errors_listener.rb +30 -0
- data/lib/karafka/instrumentation/vendors/appsignal/metrics_listener.rb +331 -0
- data/lib/karafka/instrumentation/vendors/datadog/dashboard.json +1 -0
- data/lib/karafka/instrumentation/vendors/datadog/logger_listener.rb +155 -0
- data/lib/karafka/instrumentation/vendors/datadog/metrics_listener.rb +264 -0
- data/lib/karafka/instrumentation/vendors/kubernetes/liveness_listener.rb +176 -0
- data/lib/karafka/licenser.rb +78 -0
- data/lib/karafka/messages/batch_metadata.rb +52 -0
- data/lib/karafka/messages/builders/batch_metadata.rb +60 -0
- data/lib/karafka/messages/builders/message.rb +40 -0
- data/lib/karafka/messages/builders/messages.rb +36 -0
- data/lib/karafka/{params/params.rb → messages/message.rb} +20 -13
- data/lib/karafka/messages/messages.rb +71 -0
- data/lib/karafka/{params → messages}/metadata.rb +4 -6
- data/lib/karafka/messages/parser.rb +14 -0
- data/lib/karafka/messages/seek.rb +12 -0
- data/lib/karafka/patches/rdkafka/bindings.rb +122 -0
- data/lib/karafka/patches/rdkafka/opaque.rb +36 -0
- data/lib/karafka/pro/active_job/consumer.rb +47 -0
- data/lib/karafka/pro/active_job/dispatcher.rb +86 -0
- data/lib/karafka/pro/active_job/job_options_contract.rb +45 -0
- data/lib/karafka/pro/cleaner/errors.rb +27 -0
- data/lib/karafka/pro/cleaner/messages/message.rb +46 -0
- data/lib/karafka/pro/cleaner/messages/messages.rb +42 -0
- data/lib/karafka/pro/cleaner.rb +41 -0
- data/lib/karafka/pro/contracts/base.rb +23 -0
- data/lib/karafka/pro/contracts/server_cli_options.rb +111 -0
- data/lib/karafka/pro/encryption/cipher.rb +58 -0
- data/lib/karafka/pro/encryption/contracts/config.rb +79 -0
- data/lib/karafka/pro/encryption/errors.rb +27 -0
- data/lib/karafka/pro/encryption/messages/middleware.rb +46 -0
- data/lib/karafka/pro/encryption/messages/parser.rb +56 -0
- data/lib/karafka/pro/encryption/setup/config.rb +48 -0
- data/lib/karafka/pro/encryption.rb +47 -0
- data/lib/karafka/pro/iterator/expander.rb +95 -0
- data/lib/karafka/pro/iterator/tpl_builder.rb +155 -0
- data/lib/karafka/pro/iterator.rb +170 -0
- data/lib/karafka/pro/loader.rb +106 -0
- data/lib/karafka/pro/performance_tracker.rb +84 -0
- data/lib/karafka/pro/processing/collapser.rb +62 -0
- data/lib/karafka/pro/processing/coordinator.rb +147 -0
- data/lib/karafka/pro/processing/filters/base.rb +61 -0
- data/lib/karafka/pro/processing/filters/delayer.rb +70 -0
- data/lib/karafka/pro/processing/filters/expirer.rb +51 -0
- data/lib/karafka/pro/processing/filters/inline_insights_delayer.rb +78 -0
- data/lib/karafka/pro/processing/filters/throttler.rb +84 -0
- data/lib/karafka/pro/processing/filters/virtual_limiter.rb +52 -0
- data/lib/karafka/pro/processing/filters_applier.rb +105 -0
- data/lib/karafka/pro/processing/jobs/consume_non_blocking.rb +39 -0
- data/lib/karafka/pro/processing/jobs/revoked_non_blocking.rb +37 -0
- data/lib/karafka/pro/processing/jobs_builder.rb +50 -0
- data/lib/karafka/pro/processing/partitioner.rb +69 -0
- data/lib/karafka/pro/processing/scheduler.rb +75 -0
- data/lib/karafka/pro/processing/strategies/aj/dlq_ftr_lrj_mom.rb +70 -0
- data/lib/karafka/pro/processing/strategies/aj/dlq_ftr_lrj_mom_vp.rb +76 -0
- data/lib/karafka/pro/processing/strategies/aj/dlq_ftr_mom.rb +72 -0
- data/lib/karafka/pro/processing/strategies/aj/dlq_ftr_mom_vp.rb +76 -0
- data/lib/karafka/pro/processing/strategies/aj/dlq_lrj_mom.rb +66 -0
- data/lib/karafka/pro/processing/strategies/aj/dlq_lrj_mom_vp.rb +70 -0
- data/lib/karafka/pro/processing/strategies/aj/dlq_mom.rb +64 -0
- data/lib/karafka/pro/processing/strategies/aj/dlq_mom_vp.rb +69 -0
- data/lib/karafka/pro/processing/strategies/aj/ftr_lrj_mom.rb +38 -0
- data/lib/karafka/pro/processing/strategies/aj/ftr_lrj_mom_vp.rb +66 -0
- data/lib/karafka/pro/processing/strategies/aj/ftr_mom.rb +38 -0
- data/lib/karafka/pro/processing/strategies/aj/ftr_mom_vp.rb +58 -0
- data/lib/karafka/pro/processing/strategies/aj/lrj_mom.rb +37 -0
- data/lib/karafka/pro/processing/strategies/aj/lrj_mom_vp.rb +82 -0
- data/lib/karafka/pro/processing/strategies/aj/mom.rb +36 -0
- data/lib/karafka/pro/processing/strategies/aj/mom_vp.rb +52 -0
- data/lib/karafka/pro/processing/strategies/base.rb +26 -0
- data/lib/karafka/pro/processing/strategies/default.rb +105 -0
- data/lib/karafka/pro/processing/strategies/dlq/default.rb +137 -0
- data/lib/karafka/pro/processing/strategies/dlq/ftr.rb +61 -0
- data/lib/karafka/pro/processing/strategies/dlq/ftr_lrj.rb +75 -0
- data/lib/karafka/pro/processing/strategies/dlq/ftr_lrj_mom.rb +71 -0
- data/lib/karafka/pro/processing/strategies/dlq/ftr_lrj_mom_vp.rb +43 -0
- data/lib/karafka/pro/processing/strategies/dlq/ftr_lrj_vp.rb +41 -0
- data/lib/karafka/pro/processing/strategies/dlq/ftr_mom.rb +69 -0
- data/lib/karafka/pro/processing/strategies/dlq/ftr_mom_vp.rb +41 -0
- data/lib/karafka/pro/processing/strategies/dlq/ftr_vp.rb +40 -0
- data/lib/karafka/pro/processing/strategies/dlq/lrj.rb +64 -0
- data/lib/karafka/pro/processing/strategies/dlq/lrj_mom.rb +65 -0
- data/lib/karafka/pro/processing/strategies/dlq/lrj_mom_vp.rb +36 -0
- data/lib/karafka/pro/processing/strategies/dlq/lrj_vp.rb +39 -0
- data/lib/karafka/pro/processing/strategies/dlq/mom.rb +68 -0
- data/lib/karafka/pro/processing/strategies/dlq/mom_vp.rb +37 -0
- data/lib/karafka/pro/processing/strategies/dlq/vp.rb +40 -0
- data/lib/karafka/pro/processing/strategies/ftr/default.rb +111 -0
- data/lib/karafka/pro/processing/strategies/ftr/vp.rb +40 -0
- data/lib/karafka/pro/processing/strategies/lrj/default.rb +85 -0
- data/lib/karafka/pro/processing/strategies/lrj/ftr.rb +69 -0
- data/lib/karafka/pro/processing/strategies/lrj/ftr_mom.rb +67 -0
- data/lib/karafka/pro/processing/strategies/lrj/ftr_mom_vp.rb +40 -0
- data/lib/karafka/pro/processing/strategies/lrj/ftr_vp.rb +39 -0
- data/lib/karafka/pro/processing/strategies/lrj/mom.rb +77 -0
- data/lib/karafka/pro/processing/strategies/lrj/mom_vp.rb +38 -0
- data/lib/karafka/pro/processing/strategies/lrj/vp.rb +36 -0
- data/lib/karafka/pro/processing/strategies/mom/default.rb +46 -0
- data/lib/karafka/pro/processing/strategies/mom/ftr.rb +53 -0
- data/lib/karafka/pro/processing/strategies/mom/ftr_vp.rb +37 -0
- data/lib/karafka/pro/processing/strategies/mom/vp.rb +35 -0
- data/lib/karafka/pro/processing/strategies/vp/default.rb +124 -0
- data/lib/karafka/pro/processing/strategies.rb +22 -0
- data/lib/karafka/pro/processing/strategy_selector.rb +84 -0
- data/lib/karafka/pro/processing/virtual_offset_manager.rb +147 -0
- data/lib/karafka/pro/routing/features/active_job/builder.rb +45 -0
- data/lib/karafka/pro/routing/features/active_job.rb +26 -0
- data/lib/karafka/pro/routing/features/base.rb +24 -0
- data/lib/karafka/pro/routing/features/dead_letter_queue/contracts/topic.rb +53 -0
- data/lib/karafka/pro/routing/features/dead_letter_queue.rb +27 -0
- data/lib/karafka/pro/routing/features/delaying/config.rb +27 -0
- data/lib/karafka/pro/routing/features/delaying/contracts/topic.rb +41 -0
- data/lib/karafka/pro/routing/features/delaying/topic.rb +59 -0
- data/lib/karafka/pro/routing/features/delaying.rb +29 -0
- data/lib/karafka/pro/routing/features/expiring/config.rb +27 -0
- data/lib/karafka/pro/routing/features/expiring/contracts/topic.rb +41 -0
- data/lib/karafka/pro/routing/features/expiring/topic.rb +59 -0
- data/lib/karafka/pro/routing/features/expiring.rb +27 -0
- data/lib/karafka/pro/routing/features/filtering/config.rb +40 -0
- data/lib/karafka/pro/routing/features/filtering/contracts/topic.rb +44 -0
- data/lib/karafka/pro/routing/features/filtering/topic.rb +51 -0
- data/lib/karafka/pro/routing/features/filtering.rb +27 -0
- data/lib/karafka/pro/routing/features/inline_insights/config.rb +32 -0
- data/lib/karafka/pro/routing/features/inline_insights/contracts/topic.rb +41 -0
- data/lib/karafka/pro/routing/features/inline_insights/topic.rb +52 -0
- data/lib/karafka/pro/routing/features/inline_insights.rb +26 -0
- data/lib/karafka/pro/routing/features/long_running_job/config.rb +28 -0
- data/lib/karafka/pro/routing/features/long_running_job/contracts/topic.rb +40 -0
- data/lib/karafka/pro/routing/features/long_running_job/topic.rb +42 -0
- data/lib/karafka/pro/routing/features/long_running_job.rb +28 -0
- data/lib/karafka/pro/routing/features/patterns/builder.rb +38 -0
- data/lib/karafka/pro/routing/features/patterns/config.rb +54 -0
- data/lib/karafka/pro/routing/features/patterns/consumer_group.rb +72 -0
- data/lib/karafka/pro/routing/features/patterns/contracts/consumer_group.rb +62 -0
- data/lib/karafka/pro/routing/features/patterns/contracts/pattern.rb +46 -0
- data/lib/karafka/pro/routing/features/patterns/contracts/topic.rb +41 -0
- data/lib/karafka/pro/routing/features/patterns/detector.rb +71 -0
- data/lib/karafka/pro/routing/features/patterns/pattern.rb +95 -0
- data/lib/karafka/pro/routing/features/patterns/patterns.rb +35 -0
- data/lib/karafka/pro/routing/features/patterns/topic.rb +50 -0
- data/lib/karafka/pro/routing/features/patterns/topics.rb +53 -0
- data/lib/karafka/pro/routing/features/patterns.rb +33 -0
- data/lib/karafka/pro/routing/features/pausing/contracts/topic.rb +51 -0
- data/lib/karafka/pro/routing/features/pausing/topic.rb +44 -0
- data/lib/karafka/pro/routing/features/pausing.rb +25 -0
- data/lib/karafka/pro/routing/features/throttling/config.rb +32 -0
- data/lib/karafka/pro/routing/features/throttling/contracts/topic.rb +44 -0
- data/lib/karafka/pro/routing/features/throttling/topic.rb +69 -0
- data/lib/karafka/pro/routing/features/throttling.rb +30 -0
- data/lib/karafka/pro/routing/features/virtual_partitions/config.rb +30 -0
- data/lib/karafka/pro/routing/features/virtual_partitions/contracts/topic.rb +55 -0
- data/lib/karafka/pro/routing/features/virtual_partitions/topic.rb +56 -0
- data/lib/karafka/pro/routing/features/virtual_partitions.rb +27 -0
- data/lib/karafka/pro.rb +13 -0
- data/lib/karafka/process.rb +24 -8
- data/lib/karafka/processing/coordinator.rb +181 -0
- data/lib/karafka/processing/coordinators_buffer.rb +62 -0
- data/lib/karafka/processing/executor.rb +155 -0
- data/lib/karafka/processing/executors_buffer.rb +72 -0
- data/lib/karafka/processing/expansions_selector.rb +22 -0
- data/lib/karafka/processing/inline_insights/consumer.rb +41 -0
- data/lib/karafka/processing/inline_insights/listener.rb +19 -0
- data/lib/karafka/processing/inline_insights/tracker.rb +128 -0
- data/lib/karafka/processing/jobs/base.rb +55 -0
- data/lib/karafka/processing/jobs/consume.rb +45 -0
- data/lib/karafka/processing/jobs/idle.rb +24 -0
- data/lib/karafka/processing/jobs/revoked.rb +22 -0
- data/lib/karafka/processing/jobs/shutdown.rb +23 -0
- data/lib/karafka/processing/jobs_builder.rb +28 -0
- data/lib/karafka/processing/jobs_queue.rb +150 -0
- data/lib/karafka/processing/partitioner.rb +24 -0
- data/lib/karafka/processing/result.rb +42 -0
- data/lib/karafka/processing/scheduler.rb +22 -0
- data/lib/karafka/processing/strategies/aj_dlq_mom.rb +44 -0
- data/lib/karafka/processing/strategies/aj_mom.rb +21 -0
- data/lib/karafka/processing/strategies/base.rb +52 -0
- data/lib/karafka/processing/strategies/default.rb +158 -0
- data/lib/karafka/processing/strategies/dlq.rb +88 -0
- data/lib/karafka/processing/strategies/dlq_mom.rb +49 -0
- data/lib/karafka/processing/strategies/mom.rb +29 -0
- data/lib/karafka/processing/strategy_selector.rb +47 -0
- data/lib/karafka/processing/worker.rb +93 -0
- data/lib/karafka/processing/workers_batch.rb +27 -0
- data/lib/karafka/railtie.rb +141 -0
- data/lib/karafka/routing/activity_manager.rb +84 -0
- data/lib/karafka/routing/builder.rb +45 -19
- data/lib/karafka/routing/consumer_group.rb +56 -20
- data/lib/karafka/routing/consumer_mapper.rb +1 -12
- data/lib/karafka/routing/features/active_job/builder.rb +33 -0
- data/lib/karafka/routing/features/active_job/config.rb +15 -0
- data/lib/karafka/routing/features/active_job/contracts/topic.rb +44 -0
- data/lib/karafka/routing/features/active_job/proxy.rb +14 -0
- data/lib/karafka/routing/features/active_job/topic.rb +33 -0
- data/lib/karafka/routing/features/active_job.rb +13 -0
- data/lib/karafka/routing/features/base/expander.rb +59 -0
- data/lib/karafka/routing/features/base.rb +71 -0
- data/lib/karafka/routing/features/dead_letter_queue/config.rb +19 -0
- data/lib/karafka/routing/features/dead_letter_queue/contracts/topic.rb +46 -0
- data/lib/karafka/routing/features/dead_letter_queue/topic.rb +41 -0
- data/lib/karafka/routing/features/dead_letter_queue.rb +16 -0
- data/lib/karafka/routing/features/declaratives/config.rb +18 -0
- data/lib/karafka/routing/features/declaratives/contracts/topic.rb +33 -0
- data/lib/karafka/routing/features/declaratives/topic.rb +44 -0
- data/lib/karafka/routing/features/declaratives.rb +14 -0
- data/lib/karafka/routing/features/inline_insights/config.rb +15 -0
- data/lib/karafka/routing/features/inline_insights/contracts/topic.rb +27 -0
- data/lib/karafka/routing/features/inline_insights/topic.rb +31 -0
- data/lib/karafka/routing/features/inline_insights.rb +40 -0
- data/lib/karafka/routing/features/manual_offset_management/config.rb +15 -0
- data/lib/karafka/routing/features/manual_offset_management/contracts/topic.rb +27 -0
- data/lib/karafka/routing/features/manual_offset_management/topic.rb +35 -0
- data/lib/karafka/routing/features/manual_offset_management.rb +18 -0
- data/lib/karafka/routing/proxy.rb +22 -21
- data/lib/karafka/routing/router.rb +24 -10
- data/lib/karafka/routing/subscription_group.rb +110 -0
- data/lib/karafka/routing/subscription_groups_builder.rb +65 -0
- data/lib/karafka/routing/topic.rb +87 -24
- data/lib/karafka/routing/topics.rb +46 -0
- data/lib/karafka/runner.rb +52 -0
- data/lib/karafka/serialization/json/deserializer.rb +7 -15
- data/lib/karafka/server.rb +113 -37
- data/lib/karafka/setup/attributes_map.rb +348 -0
- data/lib/karafka/setup/config.rb +256 -175
- data/lib/karafka/status.rb +54 -7
- data/lib/karafka/templates/example_consumer.rb.erb +16 -0
- data/lib/karafka/templates/karafka.rb.erb +33 -55
- data/lib/karafka/time_trackers/base.rb +14 -0
- data/lib/karafka/time_trackers/pause.rb +122 -0
- data/lib/karafka/time_trackers/poll.rb +69 -0
- data/lib/karafka/version.rb +1 -1
- data/lib/karafka.rb +91 -17
- data/renovate.json +9 -0
- data.tar.gz.sig +0 -0
- metadata +330 -168
- metadata.gz.sig +0 -0
- data/MIT-LICENCE +0 -18
- data/certs/mensfeld.pem +0 -25
- data/config/errors.yml +0 -41
- data/lib/karafka/assignment_strategies/round_robin.rb +0 -13
- data/lib/karafka/attributes_map.rb +0 -63
- data/lib/karafka/backends/inline.rb +0 -16
- data/lib/karafka/base_responder.rb +0 -226
- data/lib/karafka/cli/flow.rb +0 -48
- data/lib/karafka/cli/missingno.rb +0 -19
- data/lib/karafka/code_reloader.rb +0 -67
- data/lib/karafka/connection/api_adapter.rb +0 -158
- data/lib/karafka/connection/batch_delegator.rb +0 -55
- data/lib/karafka/connection/builder.rb +0 -23
- data/lib/karafka/connection/message_delegator.rb +0 -36
- data/lib/karafka/consumers/batch_metadata.rb +0 -10
- data/lib/karafka/consumers/callbacks.rb +0 -71
- data/lib/karafka/consumers/includer.rb +0 -64
- data/lib/karafka/consumers/responders.rb +0 -24
- data/lib/karafka/consumers/single_params.rb +0 -15
- data/lib/karafka/contracts/consumer_group_topic.rb +0 -19
- data/lib/karafka/contracts/responder_usage.rb +0 -54
- data/lib/karafka/fetcher.rb +0 -42
- data/lib/karafka/helpers/class_matcher.rb +0 -88
- data/lib/karafka/helpers/config_retriever.rb +0 -46
- data/lib/karafka/helpers/inflector.rb +0 -26
- data/lib/karafka/instrumentation/stdout_listener.rb +0 -140
- data/lib/karafka/params/batch_metadata.rb +0 -26
- data/lib/karafka/params/builders/batch_metadata.rb +0 -30
- data/lib/karafka/params/builders/params.rb +0 -38
- data/lib/karafka/params/builders/params_batch.rb +0 -25
- data/lib/karafka/params/params_batch.rb +0 -60
- data/lib/karafka/patches/ruby_kafka.rb +0 -47
- data/lib/karafka/persistence/client.rb +0 -29
- data/lib/karafka/persistence/consumers.rb +0 -45
- data/lib/karafka/persistence/topics.rb +0 -48
- data/lib/karafka/responders/builder.rb +0 -36
- data/lib/karafka/responders/topic.rb +0 -55
- data/lib/karafka/routing/topic_mapper.rb +0 -53
- data/lib/karafka/serialization/json/serializer.rb +0 -31
- data/lib/karafka/setup/configurators/water_drop.rb +0 -36
- 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,105 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Karafka
|
4
|
+
module Connection
|
5
|
+
# Manager for tracking changes in the partitions assignment after the assignment is done.
|
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
|
+
#
|
21
|
+
# @note We have to have the `subscription_group` reference because we have a global pipeline
|
22
|
+
# for notifications and we need to make sure we track changes only for things that are of
|
23
|
+
# relevance to our subscription group
|
24
|
+
class RebalanceManager
|
25
|
+
# Empty array for internal usage not to create new objects
|
26
|
+
EMPTY_ARRAY = [].freeze
|
27
|
+
|
28
|
+
attr_reader :assigned_partitions, :revoked_partitions
|
29
|
+
|
30
|
+
private_constant :EMPTY_ARRAY
|
31
|
+
|
32
|
+
# @param subscription_group_id [String] subscription group id
|
33
|
+
# @return [RebalanceManager]
|
34
|
+
def initialize(subscription_group_id)
|
35
|
+
@assigned_partitions = {}
|
36
|
+
@revoked_partitions = {}
|
37
|
+
@changed = false
|
38
|
+
@active = false
|
39
|
+
@subscription_group_id = subscription_group_id
|
40
|
+
|
41
|
+
# Connects itself to the instrumentation pipeline so rebalances can be tracked
|
42
|
+
::Karafka.monitor.subscribe(self)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Resets the rebalance manager state
|
46
|
+
# This needs to be done before each polling loop as during the polling, the state may be
|
47
|
+
# changed
|
48
|
+
def clear
|
49
|
+
@assigned_partitions.clear
|
50
|
+
@revoked_partitions.clear
|
51
|
+
@changed = false
|
52
|
+
end
|
53
|
+
|
54
|
+
# @return [Boolean] indicates a state change in the partitions assignment
|
55
|
+
def changed?
|
56
|
+
@changed
|
57
|
+
end
|
58
|
+
|
59
|
+
# @return [Boolean] true if there was at least one rebalance
|
60
|
+
# @note This method is needed to make sure that when using cooperative-sticky, we do not
|
61
|
+
# close until first rebalance. Otherwise librdkafka may crash.
|
62
|
+
# @see https://github.com/confluentinc/librdkafka/issues/4312
|
63
|
+
def active?
|
64
|
+
@active
|
65
|
+
end
|
66
|
+
|
67
|
+
# We consider as lost only partitions that were taken away and not re-assigned back to us
|
68
|
+
def lost_partitions
|
69
|
+
lost_partitions = {}
|
70
|
+
|
71
|
+
revoked_partitions.each do |topic, partitions|
|
72
|
+
lost_partitions[topic] = partitions - assigned_partitions.fetch(topic, EMPTY_ARRAY)
|
73
|
+
end
|
74
|
+
|
75
|
+
lost_partitions
|
76
|
+
end
|
77
|
+
|
78
|
+
# Callback that kicks in inside of rdkafka, when new partitions were assigned.
|
79
|
+
#
|
80
|
+
# @private
|
81
|
+
# @param event [Karafka::Core::Monitoring::Event]
|
82
|
+
def on_rebalance_partitions_assigned(event)
|
83
|
+
# Apply changes only for our subscription group
|
84
|
+
return unless event[:subscription_group_id] == @subscription_group_id
|
85
|
+
|
86
|
+
@active = true
|
87
|
+
@assigned_partitions = event[:tpl].to_h.transform_values { |part| part.map(&:partition) }
|
88
|
+
@changed = true
|
89
|
+
end
|
90
|
+
|
91
|
+
# Callback that kicks in inside of rdkafka, when partitions were revoked.
|
92
|
+
#
|
93
|
+
# @private
|
94
|
+
# @param event [Karafka::Core::Monitoring::Event]
|
95
|
+
def on_rebalance_partitions_revoked(event)
|
96
|
+
# Apply changes only for our subscription group
|
97
|
+
return unless event[:subscription_group_id] == @subscription_group_id
|
98
|
+
|
99
|
+
@active = true
|
100
|
+
@revoked_partitions = event[:tpl].to_h.transform_values { |part| part.map(&:partition) }
|
101
|
+
@changed = true
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
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,138 @@
|
|
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 <
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
+
nested(:admin) do
|
38
|
+
# Can be empty because inherits values from the root kafka
|
39
|
+
required(:kafka) { |val| val.is_a?(Hash) }
|
40
|
+
required(:group_id) { |val| val.is_a?(String) && Contracts::TOPIC_REGEXP.match?(val) }
|
41
|
+
required(:max_wait_time) { |val| val.is_a?(Integer) && val.positive? }
|
42
|
+
required(:max_attempts) { |val| val.is_a?(Integer) && val.positive? }
|
43
|
+
end
|
44
|
+
|
45
|
+
# We validate internals just to be sure, that they are present and working
|
46
|
+
nested(:internal) do
|
47
|
+
required(:status) { |val| !val.nil? }
|
48
|
+
required(:process) { |val| !val.nil? }
|
49
|
+
|
50
|
+
nested(:connection) do
|
51
|
+
nested(:proxy) do
|
52
|
+
nested(:query_watermark_offsets) do
|
53
|
+
required(:timeout) { |val| val.is_a?(Integer) && val.positive? }
|
54
|
+
required(:max_attempts) { |val| val.is_a?(Integer) && val.positive? }
|
55
|
+
required(:wait_time) { |val| val.is_a?(Integer) && val.positive? }
|
56
|
+
end
|
57
|
+
|
58
|
+
nested(:offsets_for_times) do
|
59
|
+
required(:timeout) { |val| val.is_a?(Integer) && val.positive? }
|
60
|
+
required(:max_attempts) { |val| val.is_a?(Integer) && val.positive? }
|
61
|
+
required(:wait_time) { |val| val.is_a?(Integer) && val.positive? }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
nested(:routing) do
|
67
|
+
required(:builder) { |val| !val.nil? }
|
68
|
+
required(:subscription_groups_builder) { |val| !val.nil? }
|
69
|
+
end
|
70
|
+
|
71
|
+
nested(:processing) do
|
72
|
+
required(:jobs_builder) { |val| !val.nil? }
|
73
|
+
required(:scheduler) { |val| !val.nil? }
|
74
|
+
required(:coordinator_class) { |val| !val.nil? }
|
75
|
+
required(:partitioner_class) { |val| !val.nil? }
|
76
|
+
required(:strategy_selector) { |val| !val.nil? }
|
77
|
+
required(:expansions_selector) { |val| !val.nil? }
|
78
|
+
end
|
79
|
+
|
80
|
+
nested(:active_job) do
|
81
|
+
required(:dispatcher) { |val| !val.nil? }
|
82
|
+
required(:job_options_contract) { |val| !val.nil? }
|
83
|
+
required(:consumer_class) { |val| !val.nil? }
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# Ensure all root kafka keys are symbols
|
88
|
+
virtual do |data, errors|
|
89
|
+
next unless errors.empty?
|
90
|
+
|
91
|
+
detected_errors = []
|
92
|
+
|
93
|
+
data.fetch(:kafka).each_key do |key|
|
94
|
+
next if key.is_a?(Symbol)
|
95
|
+
|
96
|
+
detected_errors << [[:kafka, key], :key_must_be_a_symbol]
|
97
|
+
end
|
98
|
+
|
99
|
+
detected_errors
|
100
|
+
end
|
101
|
+
|
102
|
+
# Ensure all admin kafka keys are symbols
|
103
|
+
virtual do |data, errors|
|
104
|
+
next unless errors.empty?
|
105
|
+
|
106
|
+
detected_errors = []
|
107
|
+
|
108
|
+
data.fetch(:admin).fetch(:kafka).each_key do |key|
|
109
|
+
next if key.is_a?(Symbol)
|
110
|
+
|
111
|
+
detected_errors << [[:admin, :kafka, key], :key_must_be_a_symbol]
|
112
|
+
end
|
113
|
+
|
114
|
+
detected_errors
|
115
|
+
end
|
116
|
+
|
117
|
+
virtual do |data, errors|
|
118
|
+
next unless errors.empty?
|
119
|
+
|
120
|
+
pause_timeout = data.fetch(:pause_timeout)
|
121
|
+
pause_max_timeout = data.fetch(:pause_max_timeout)
|
122
|
+
|
123
|
+
next if pause_timeout <= pause_max_timeout
|
124
|
+
|
125
|
+
[[%i[pause_timeout], :max_timeout_vs_pause_max_timeout]]
|
126
|
+
end
|
127
|
+
|
128
|
+
virtual do |data, errors|
|
129
|
+
next unless errors.empty?
|
130
|
+
|
131
|
+
shutdown_timeout = data.fetch(:shutdown_timeout)
|
132
|
+
max_wait_time = data.fetch(:max_wait_time)
|
133
|
+
|
134
|
+
next if max_wait_time < shutdown_timeout
|
135
|
+
|
136
|
+
[[%i[shutdown_timeout], :shutdown_timeout_vs_max_wait_time]]
|
18
137
|
end
|
19
138
|
end
|
20
139
|
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 <
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
73
|
-
|
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
|
-
|
80
|
-
|
81
|
-
names = value.map { |topic| topic[:name] }
|
18
|
+
virtual do |data, errors|
|
19
|
+
next unless errors.empty?
|
82
20
|
|
83
|
-
|
84
|
-
end
|
85
|
-
end
|
21
|
+
names = data.fetch(:topics).map { |topic| topic[:name] }
|
86
22
|
|
87
|
-
|
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
|
-
|
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
|
-
|
102
|
-
|
103
|
-
|
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
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
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
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
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
|
-
|
145
|
-
|
146
|
-
|
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
|
-
|
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
|
-
|
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
|