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
@@ -2,29 +2,90 @@
|
|
2
2
|
|
3
3
|
module Karafka
|
4
4
|
module Contracts
|
5
|
-
# Contract for validating correctness of the server cli command options
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
optional(:daemon).filled(:bool?)
|
14
|
-
optional(:consumer_groups).value(:array, :filled?)
|
5
|
+
# Contract for validating correctness of the server cli command options.
|
6
|
+
class ServerCliOptions < Base
|
7
|
+
configure do |config|
|
8
|
+
config.error_messages = YAML.safe_load(
|
9
|
+
File.read(
|
10
|
+
File.join(Karafka.gem_root, 'config', 'locales', 'errors.yml')
|
11
|
+
)
|
12
|
+
).fetch('en').fetch('validations').fetch('server_cli_options')
|
15
13
|
end
|
16
14
|
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
%i[
|
16
|
+
include
|
17
|
+
exclude
|
18
|
+
].each do |action|
|
19
|
+
optional(:"#{action}_consumer_groups") { |cg| cg.is_a?(Array) }
|
20
|
+
optional(:"#{action}_subscription_groups") { |sg| sg.is_a?(Array) }
|
21
|
+
optional(:"#{action}_topics") { |topics| topics.is_a?(Array) }
|
22
|
+
|
23
|
+
virtual do |data, errors|
|
24
|
+
next unless errors.empty?
|
25
|
+
|
26
|
+
value = data.fetch(:"#{action}_consumer_groups")
|
27
|
+
|
28
|
+
# If there were no consumer_groups declared in the server cli, it means that we will
|
29
|
+
# run all of them and no need to validate them here at all
|
30
|
+
next if value.empty?
|
31
|
+
next if (value - Karafka::App.consumer_groups.map(&:name)).empty?
|
32
|
+
|
33
|
+
# Found unknown consumer groups
|
34
|
+
[[[:"#{action}_consumer_groups"], :consumer_groups_inclusion]]
|
35
|
+
end
|
36
|
+
|
37
|
+
virtual do |data, errors|
|
38
|
+
next unless errors.empty?
|
39
|
+
|
40
|
+
value = data.fetch(:"#{action}_subscription_groups")
|
41
|
+
|
42
|
+
# If there were no subscription_groups declared in the server cli, it means that we will
|
43
|
+
# run all of them and no need to validate them here at all
|
44
|
+
next if value.empty?
|
45
|
+
|
46
|
+
subscription_groups = Karafka::App
|
47
|
+
.consumer_groups
|
48
|
+
.map(&:subscription_groups)
|
49
|
+
.flatten
|
50
|
+
.map(&:name)
|
51
|
+
|
52
|
+
next if (value - subscription_groups).empty?
|
20
53
|
|
21
|
-
|
22
|
-
|
23
|
-
# run all of them and no need to validate them here at all
|
24
|
-
if !value.nil? &&
|
25
|
-
!(value - Karafka::App.config.internal.routing_builder.map(&:name)).empty?
|
26
|
-
key(:consumer_groups).failure(:consumer_groups_inclusion)
|
54
|
+
# Found unknown subscription groups
|
55
|
+
[[[:"#{action}_subscription_groups"], :subscription_groups_inclusion]]
|
27
56
|
end
|
57
|
+
|
58
|
+
virtual do |data, errors|
|
59
|
+
next unless errors.empty?
|
60
|
+
|
61
|
+
value = data.fetch(:"#{action}_topics")
|
62
|
+
|
63
|
+
# If there were no topics declared in the server cli, it means that we will
|
64
|
+
# run all of them and no need to validate them here at all
|
65
|
+
next if value.empty?
|
66
|
+
|
67
|
+
topics = Karafka::App
|
68
|
+
.consumer_groups
|
69
|
+
.map(&:subscription_groups)
|
70
|
+
.flatten
|
71
|
+
.map(&:topics)
|
72
|
+
.map { |gtopics| gtopics.map(&:name) }
|
73
|
+
.flatten
|
74
|
+
|
75
|
+
next if (value - topics).empty?
|
76
|
+
|
77
|
+
# Found unknown topics
|
78
|
+
[[[:"#{action}_topics"], :topics_inclusion]]
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# Makes sure we have anything to subscribe to when we start the server
|
83
|
+
virtual do |_, errors|
|
84
|
+
next unless errors.empty?
|
85
|
+
|
86
|
+
next unless Karafka::App.subscription_groups.empty?
|
87
|
+
|
88
|
+
[[%i[include_topics], :topics_missing]]
|
28
89
|
end
|
29
90
|
end
|
30
91
|
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Karafka
|
4
|
+
module Contracts
|
5
|
+
# Consumer group topic validation rules.
|
6
|
+
class Topic < 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('topic')
|
13
|
+
end
|
14
|
+
|
15
|
+
required(:deserializer) { |val| !val.nil? }
|
16
|
+
required(:id) { |val| val.is_a?(String) && Contracts::TOPIC_REGEXP.match?(val) }
|
17
|
+
required(:kafka) { |val| val.is_a?(Hash) && !val.empty? }
|
18
|
+
required(:max_messages) { |val| val.is_a?(Integer) && val >= 1 }
|
19
|
+
required(:initial_offset) { |val| %w[earliest latest].include?(val) }
|
20
|
+
required(:max_wait_time) { |val| val.is_a?(Integer) && val >= 10 }
|
21
|
+
required(:name) { |val| val.is_a?(String) && Contracts::TOPIC_REGEXP.match?(val) }
|
22
|
+
required(:active) { |val| [true, false].include?(val) }
|
23
|
+
required(:subscription_group_name) { |val| val.is_a?(String) && !val.empty? }
|
24
|
+
|
25
|
+
# Consumer needs to be present only if topic is active
|
26
|
+
# We allow not to define consumer for non-active because they may be only used via admin
|
27
|
+
# api or other ways and not consumed with consumer
|
28
|
+
virtual do |data, errors|
|
29
|
+
next unless errors.empty?
|
30
|
+
next if data.fetch(:consumer)
|
31
|
+
next unless data.fetch(:active)
|
32
|
+
|
33
|
+
[[%w[consumer], :missing]]
|
34
|
+
end
|
35
|
+
|
36
|
+
virtual do |data, errors|
|
37
|
+
next unless errors.empty?
|
38
|
+
|
39
|
+
value = data.fetch(:kafka)
|
40
|
+
|
41
|
+
begin
|
42
|
+
# This will trigger rdkafka validations that we catch and re-map the info and use dry
|
43
|
+
# compatible format
|
44
|
+
Rdkafka::Config.new(value).send(:native_config)
|
45
|
+
|
46
|
+
nil
|
47
|
+
rescue Rdkafka::Config::ConfigError => e
|
48
|
+
[[%w[kafka], e.message]]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
virtual do |data, errors|
|
53
|
+
next unless errors.empty?
|
54
|
+
next unless ::Karafka::App.config.strict_topics_namespacing
|
55
|
+
|
56
|
+
value = data.fetch(:name)
|
57
|
+
namespacing_chars_count = value.chars.find_all { |c| ['.', '_'].include?(c) }.uniq.count
|
58
|
+
|
59
|
+
next if namespacing_chars_count <= 1
|
60
|
+
|
61
|
+
[[%w[name], :inconsistent_namespacing]]
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/lib/karafka/contracts.rb
CHANGED
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Karafka
|
4
|
+
# Allows to start and stop Karafka as part of a different process
|
5
|
+
module Embedded
|
6
|
+
class << self
|
7
|
+
# Starts Karafka without supervision and without ownership of signals in a background thread
|
8
|
+
# so it won't interrupt other things running
|
9
|
+
def start
|
10
|
+
Thread.new do
|
11
|
+
Karafka::Process.tags.add(:execution_mode, 'embedded')
|
12
|
+
Karafka::Server.start
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# Stops Karafka upon any event
|
17
|
+
#
|
18
|
+
# @note This method is blocking because we want to wait until Karafka is stopped with final
|
19
|
+
# process shutdown
|
20
|
+
def stop
|
21
|
+
# Stop needs to be blocking to wait for all the things to finalize
|
22
|
+
Karafka::Server.stop
|
23
|
+
end
|
24
|
+
|
25
|
+
# Quiets Karafka upon any event
|
26
|
+
#
|
27
|
+
# @note This method is not blocking and will not wait for Karafka to fully quiet.
|
28
|
+
# It will trigger the quiet procedure but won't wait.
|
29
|
+
#
|
30
|
+
# @note Please keep in mind you need to `#stop` to actually stop the server anyhow.
|
31
|
+
def quiet
|
32
|
+
Karafka::Server.quiet
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/karafka/env.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Karafka
|
4
|
+
# Env management class to get and set environment for Karafka
|
5
|
+
class Env < String
|
6
|
+
# Keys where we look for environment details for Karafka
|
7
|
+
LOOKUP_ENV_KEYS = %w[
|
8
|
+
KARAFKA_ENV
|
9
|
+
RACK_ENV
|
10
|
+
RAILS_ENV
|
11
|
+
].freeze
|
12
|
+
|
13
|
+
# Default fallback env
|
14
|
+
DEFAULT_ENV = 'development'
|
15
|
+
|
16
|
+
private_constant :LOOKUP_ENV_KEYS, :DEFAULT_ENV
|
17
|
+
|
18
|
+
# @return [Karafka::Env] env object
|
19
|
+
# @note Will load appropriate environment automatically
|
20
|
+
def initialize
|
21
|
+
super('')
|
22
|
+
|
23
|
+
LOOKUP_ENV_KEYS
|
24
|
+
.map { |key| ENV[key] }
|
25
|
+
.compact
|
26
|
+
.first
|
27
|
+
.then { |env| env || DEFAULT_ENV }
|
28
|
+
.then { |env| replace(env) }
|
29
|
+
end
|
30
|
+
|
31
|
+
# @param method_name [String] method name
|
32
|
+
# @param include_private [Boolean] should we include private methods as well
|
33
|
+
# @return [Boolean] true if we respond to a given missing method, otherwise false
|
34
|
+
def respond_to_missing?(method_name, include_private = false)
|
35
|
+
(method_name[-1] == '?') || super
|
36
|
+
end
|
37
|
+
|
38
|
+
# Reacts to missing methods, from which some might be the env checks.
|
39
|
+
# If the method ends with '?' we assume, that it is an env check
|
40
|
+
# @param method_name [String] method name for missing or env name with question mark
|
41
|
+
# @param arguments [Array] any arguments that we pass to the method
|
42
|
+
def method_missing(method_name, *arguments)
|
43
|
+
method_name[-1] == '?' ? self == method_name[0..-2] : super
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/karafka/errors.rb
CHANGED
@@ -6,12 +6,6 @@ module Karafka
|
|
6
6
|
# Base class for all the Karafka internal errors
|
7
7
|
BaseError = Class.new(StandardError)
|
8
8
|
|
9
|
-
# Should be raised when we have that that we cannot serialize
|
10
|
-
SerializationError = Class.new(BaseError)
|
11
|
-
|
12
|
-
# Should be raised when we tried to deserialize incoming data but we failed
|
13
|
-
DeserializationError = Class.new(BaseError)
|
14
|
-
|
15
9
|
# Raised when router receives topic name which does not correspond with any routes
|
16
10
|
# This can only happen in a case when:
|
17
11
|
# - you've received a message and we cannot match it with a consumer
|
@@ -24,28 +18,50 @@ module Karafka
|
|
24
18
|
# @see https://github.com/karafka/karafka/issues/135
|
25
19
|
NonMatchingRouteError = Class.new(BaseError)
|
26
20
|
|
27
|
-
# Raised when we don't use or use responder not in the way it expected to based on the
|
28
|
-
# topics usage definitions
|
29
|
-
InvalidResponderUsageError = Class.new(BaseError)
|
30
|
-
|
31
|
-
# Raised when options that we provide to the responder to respond aren't what the contract
|
32
|
-
# requires
|
33
|
-
InvalidResponderMessageOptionsError = Class.new(BaseError)
|
34
|
-
|
35
21
|
# Raised when configuration doesn't match with validation contract
|
36
22
|
InvalidConfigurationError = Class.new(BaseError)
|
37
23
|
|
38
24
|
# Raised when we try to use Karafka CLI commands (except install) without a boot file
|
39
25
|
MissingBootFileError = Class.new(BaseError)
|
40
26
|
|
41
|
-
# Raised when we want to read a persisted thread messages consumer but it is unavailable
|
42
|
-
# This should never happen and if it does, please contact us
|
43
|
-
MissingClientError = Class.new(BaseError)
|
44
|
-
|
45
|
-
# Raised when want to hook up to an event that is not registered and supported
|
46
|
-
UnregisteredMonitorEventError = Class.new(BaseError)
|
47
|
-
|
48
27
|
# Raised when we've waited enough for shutting down a non-responsive process
|
49
28
|
ForcefulShutdownError = Class.new(BaseError)
|
29
|
+
|
30
|
+
# Raised when the jobs queue receives a job that should not be received as it would cause
|
31
|
+
# the processing to go out of sync. We should never process in parallel data from the same
|
32
|
+
# topic partition (unless virtual partitions apply)
|
33
|
+
JobsQueueSynchronizationError = Class.new(BaseError)
|
34
|
+
|
35
|
+
# Raised when given topic is not found while expected
|
36
|
+
TopicNotFoundError = Class.new(BaseError)
|
37
|
+
|
38
|
+
# This should never happen. Please open an issue if it does.
|
39
|
+
UnsupportedCaseError = Class.new(BaseError)
|
40
|
+
|
41
|
+
# Raised when the license token is not valid
|
42
|
+
InvalidLicenseTokenError = Class.new(BaseError)
|
43
|
+
|
44
|
+
# Raised on attempt to deserializer a cleared message
|
45
|
+
MessageClearedError = Class.new(BaseError)
|
46
|
+
|
47
|
+
# This should never happen. Please open an issue if it does.
|
48
|
+
InvalidCoordinatorStateError = Class.new(BaseError)
|
49
|
+
|
50
|
+
# This should never happen. Please open an issue if it does.
|
51
|
+
StrategyNotFoundError = Class.new(BaseError)
|
52
|
+
|
53
|
+
# This should never happen. Please open an issue if it does.
|
54
|
+
InvalidRealOffsetUsageError = Class.new(BaseError)
|
55
|
+
|
56
|
+
# This should never happen. Please open an issue if it does.
|
57
|
+
InvalidTimeBasedOffsetError = Class.new(BaseError)
|
58
|
+
|
59
|
+
# For internal usage only
|
60
|
+
# Raised when we run operations that require certain result but despite successfully finishing
|
61
|
+
# it is not yet available due to some synchronization mechanisms and caches
|
62
|
+
ResultNotVisibleError = Class.new(BaseError)
|
63
|
+
|
64
|
+
# Raised when there is an attempt to run an unrecognized CLI command
|
65
|
+
UnrecognizedCommandError = Class.new(BaseError)
|
50
66
|
end
|
51
67
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Karafka
|
4
|
+
module Helpers
|
5
|
+
# Allows a given class to run async in a separate thread. Provides also few methods we may
|
6
|
+
# want to use to control the underlying thread
|
7
|
+
#
|
8
|
+
# @note Thread running code needs to manage it's own exceptions. If they leak out, they will
|
9
|
+
# abort thread on exception.
|
10
|
+
module Async
|
11
|
+
class << self
|
12
|
+
# Adds forwardable to redirect thread-based control methods to the underlying thread that
|
13
|
+
# runs the async operations
|
14
|
+
#
|
15
|
+
# @param base [Class] class we're including this module in
|
16
|
+
def included(base)
|
17
|
+
base.extend ::Forwardable
|
18
|
+
|
19
|
+
base.def_delegators :@thread, :join, :terminate, :alive?
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Runs the `#call` method in a new thread
|
24
|
+
def async_call
|
25
|
+
@thread = Thread.new do
|
26
|
+
Thread.current.abort_on_exception = true
|
27
|
+
|
28
|
+
call
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Karafka
|
4
|
+
module Helpers
|
5
|
+
# Simple wrapper for adding colors to strings
|
6
|
+
module Colorize
|
7
|
+
# @param string [String] string we want to have in green
|
8
|
+
# @return [String] green string
|
9
|
+
def green(string)
|
10
|
+
"\033[0;32m#{string}\033[0m"
|
11
|
+
end
|
12
|
+
|
13
|
+
# @param string [String] string we want to have in red
|
14
|
+
# @return [String] red string
|
15
|
+
def red(string)
|
16
|
+
"\033[0;31m#{string}\033[0m"
|
17
|
+
end
|
18
|
+
|
19
|
+
# @param string [String] string we want to have in yellow
|
20
|
+
# @return [String] yellow string
|
21
|
+
def yellow(string)
|
22
|
+
"\033[1;33m#{string}\033[0m"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Karafka
|
4
|
-
# Module containing classes and methods that provide some additional functionalities
|
4
|
+
# Module containing classes and methods that provide some additional helper functionalities.
|
5
5
|
module Helpers
|
6
6
|
# @note Taken from http://stackoverflow.com/questions/6407141
|
7
|
-
# Multidelegator is used to delegate calls to multiple targets
|
7
|
+
# Multidelegator is used to delegate calls to multiple targets.
|
8
8
|
class MultiDelegator
|
9
9
|
# @param targets to which we want to delegate methods
|
10
10
|
def initialize(*targets)
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Karafka
|
4
|
+
module Instrumentation
|
5
|
+
# Callbacks used to transport things from rdkafka
|
6
|
+
module Callbacks
|
7
|
+
# Callback that kicks in when consumer error occurs and is published in a background thread
|
8
|
+
class Error
|
9
|
+
# @param subscription_group_id [String] id of the current subscription group instance
|
10
|
+
# @param consumer_group_id [String] id of the current consumer group
|
11
|
+
# @param client_name [String] rdkafka client name
|
12
|
+
def initialize(subscription_group_id, consumer_group_id, client_name)
|
13
|
+
@subscription_group_id = subscription_group_id
|
14
|
+
@consumer_group_id = consumer_group_id
|
15
|
+
@client_name = client_name
|
16
|
+
end
|
17
|
+
|
18
|
+
# Runs the instrumentation monitor with error
|
19
|
+
# @param client_name [String] rdkafka client name
|
20
|
+
# @param error [Rdkafka::Error] error that occurred
|
21
|
+
# @note It will only instrument on errors of the client of our consumer
|
22
|
+
def call(client_name, error)
|
23
|
+
# Emit only errors related to our client
|
24
|
+
# Same as with statistics (mor explanation there)
|
25
|
+
return unless @client_name == client_name
|
26
|
+
|
27
|
+
::Karafka.monitor.instrument(
|
28
|
+
'error.occurred',
|
29
|
+
caller: self,
|
30
|
+
subscription_group_id: @subscription_group_id,
|
31
|
+
consumer_group_id: @consumer_group_id,
|
32
|
+
type: 'librdkafka.error',
|
33
|
+
error: error
|
34
|
+
)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Karafka
|
4
|
+
module Instrumentation
|
5
|
+
module Callbacks
|
6
|
+
# Callback that connects to the librdkafka rebalance callback and converts those events into
|
7
|
+
# our internal events
|
8
|
+
class Rebalance
|
9
|
+
# @param subscription_group_id [String] id of the current subscription group instance
|
10
|
+
# @param consumer_group_id [String] id of the current consumer group
|
11
|
+
def initialize(subscription_group_id, consumer_group_id)
|
12
|
+
@subscription_group_id = subscription_group_id
|
13
|
+
@consumer_group_id = consumer_group_id
|
14
|
+
end
|
15
|
+
|
16
|
+
# Publishes an event that partitions are going to be revoked.
|
17
|
+
# At this stage we can still commit offsets, etc.
|
18
|
+
#
|
19
|
+
# @param tpl [Rdkafka::Consumer::TopicPartitionList]
|
20
|
+
def on_partitions_revoke(tpl)
|
21
|
+
instrument('partitions_revoke', tpl)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Publishes an event that partitions are going to be assigned
|
25
|
+
#
|
26
|
+
# @param tpl [Rdkafka::Consumer::TopicPartitionList]
|
27
|
+
def on_partitions_assign(tpl)
|
28
|
+
instrument('partitions_assign', tpl)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Publishes an event that partitions were revoked. This is after we've lost them, so no
|
32
|
+
# option to commit offsets.
|
33
|
+
#
|
34
|
+
# @param tpl [Rdkafka::Consumer::TopicPartitionList]
|
35
|
+
def on_partitions_revoked(tpl)
|
36
|
+
instrument('partitions_revoked', tpl)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Publishes an event that partitions were assigned.
|
40
|
+
#
|
41
|
+
# @param tpl [Rdkafka::Consumer::TopicPartitionList]
|
42
|
+
def on_partitions_assigned(tpl)
|
43
|
+
instrument('partitions_assigned', tpl)
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
# Publishes info that a rebalance event of a given type has happened
|
49
|
+
#
|
50
|
+
# @param name [String] name of the event
|
51
|
+
# @param tpl [Rdkafka::Consumer::TopicPartitionList]
|
52
|
+
def instrument(name, tpl)
|
53
|
+
::Karafka.monitor.instrument(
|
54
|
+
"rebalance.#{name}",
|
55
|
+
caller: self,
|
56
|
+
subscription_group_id: @subscription_group_id,
|
57
|
+
consumer_group_id: @consumer_group_id,
|
58
|
+
tpl: tpl
|
59
|
+
)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Karafka
|
4
|
+
module Instrumentation
|
5
|
+
module Callbacks
|
6
|
+
# Statistics callback handler
|
7
|
+
# @see `WaterDrop::Instrumentation::Callbacks::Statistics` for details on why we decorate
|
8
|
+
# those statistics
|
9
|
+
class Statistics
|
10
|
+
# @param subscription_group_id [String] id of the current subscription group
|
11
|
+
# @param consumer_group_id [String] id of the current consumer group
|
12
|
+
# @param client_name [String] rdkafka client name
|
13
|
+
def initialize(subscription_group_id, consumer_group_id, client_name)
|
14
|
+
@subscription_group_id = subscription_group_id
|
15
|
+
@consumer_group_id = consumer_group_id
|
16
|
+
@client_name = client_name
|
17
|
+
@statistics_decorator = ::Karafka::Core::Monitoring::StatisticsDecorator.new
|
18
|
+
end
|
19
|
+
|
20
|
+
# Emits decorated statistics to the monitor
|
21
|
+
# @param statistics [Hash] rdkafka statistics
|
22
|
+
def call(statistics)
|
23
|
+
# Emit only statistics related to our client
|
24
|
+
# rdkafka does not have per-instance statistics hook, thus we need to make sure that we
|
25
|
+
# emit only stats that are related to current producer. Otherwise we would emit all of
|
26
|
+
# all the time.
|
27
|
+
return unless @client_name == statistics['name']
|
28
|
+
|
29
|
+
::Karafka.monitor.instrument(
|
30
|
+
'statistics.emitted',
|
31
|
+
subscription_group_id: @subscription_group_id,
|
32
|
+
consumer_group_id: @consumer_group_id,
|
33
|
+
statistics: @statistics_decorator.call(statistics)
|
34
|
+
)
|
35
|
+
# We need to catch and handle any potential errors coming from the instrumentation pipeline
|
36
|
+
# as otherwise, in case of statistics which run in the main librdkafka thread, any crash
|
37
|
+
# will hang the whole process.
|
38
|
+
rescue StandardError => e
|
39
|
+
::Karafka.monitor.instrument(
|
40
|
+
'error.occurred',
|
41
|
+
caller: self,
|
42
|
+
subscription_group_id: @subscription_group_id,
|
43
|
+
consumer_group_id: @consumer_group_id,
|
44
|
+
type: 'statistics.emitted.error',
|
45
|
+
error: e
|
46
|
+
)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|