fluent-plugin-kafka 0.19.0 → 0.19.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b4a8c37b041fedc3f95046620413e5f7da437557fc19294439585fa89fd5b244
4
- data.tar.gz: fe4c8cc8df6b8b5b105fbf709044e10752d8b64f321b5a4e290cb7e316e10fe1
3
+ metadata.gz: 342b66e96b3175aed8f7fe9bc0f29bb03f2737924229eaa63d7ffd408f5209cf
4
+ data.tar.gz: 89a9361a2c599eca1419668136ecb722c6eaa95e9ebc55f2e2a2be3f1346cafc
5
5
  SHA512:
6
- metadata.gz: 2ff333ee092e0ffd653ab476acf8b2656b4ca59ea32d6dcc846eb8a174f69d98811272e8a735bfa3bdfac3d5b3753ce499adb5c8a215b3197310b1f4d822364e
7
- data.tar.gz: ebf6cafbde9635cfc886ee4dce84495353b2d389e447e6188f6a88eb4ca11b19086ce5a12565bac550ef26936f424e4ec5a0fe908fad4b39bea984758ac44720
6
+ metadata.gz: '0172977463edc0ff6085588bcded5bf3d33412e088422bf48954672507d7661bda68735d1415fcc9dcaebd132eff355cc714be619c15a107962e12dc69eba4e1'
7
+ data.tar.gz: 00054cf6be46a6041fd6f8712f3159f832f91deffcf34feef45fff919d2301b2e04b5ec0493a2d9086af87c3ce9ec37ca0f004a9fac006ee4e3c17d20b372984
data/ChangeLog CHANGED
@@ -1,3 +1,6 @@
1
+ Release 0.19.1 - 2023/09/20
2
+ * out_rdkafka2: Add `use_default_for_unknown_topic` & `use_default_for_unknown_partition_error`
3
+
1
4
  Release 0.19.0 - 2023/04/26
2
5
  * out_kafka2: Add support for AWS IAM authentication
3
6
  * in_kafka, in_kafka_group, out_kafka2: Add support for ssl client cert key password
data/README.md CHANGED
@@ -510,6 +510,8 @@ You need to install rdkafka gem.
510
510
  partition_key_key (string) :default => 'partition_key'
511
511
  message_key_key (string) :default => 'message_key'
512
512
  default_topic (string) :default => nil
513
+ use_default_for_unknown_topic (bool) :default => false
514
+ use_default_for_unknown_partition_error (bool) :default => false
513
515
  default_partition_key (string) :default => nil
514
516
  default_message_key (string) :default => nil
515
517
  exclude_topic_key (bool) :default => false
@@ -13,7 +13,7 @@ Gem::Specification.new do |gem|
13
13
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
14
  gem.name = "fluent-plugin-kafka"
15
15
  gem.require_paths = ["lib"]
16
- gem.version = '0.19.0'
16
+ gem.version = '0.19.1'
17
17
  gem.required_ruby_version = ">= 2.1.0"
18
18
 
19
19
  gem.add_dependency "fluentd", [">= 0.10.58", "< 2"]
@@ -65,6 +65,8 @@ DESC
65
65
  config_param :topic_key, :string, :default => 'topic', :desc => "Field for kafka topic"
66
66
  config_param :default_topic, :string, :default => nil,
67
67
  :desc => "Default output topic when record doesn't have topic field"
68
+ config_param :use_default_for_unknown_topic, :bool, :default => false, :desc => "If true, default_topic is used when topic not found"
69
+ config_param :use_default_for_unknown_partition_error, :bool, :default => false, :desc => "If true, default_topic is used when received unknown_partition error"
68
70
  config_param :message_key_key, :string, :default => 'message_key', :desc => "Field for kafka message key"
69
71
  config_param :default_message_key, :string, :default => nil
70
72
  config_param :partition_key, :string, :default => 'partition', :desc => "Field for kafka partition"
@@ -233,6 +235,9 @@ DESC
233
235
  @rdkafka = Rdkafka::Config.new(config)
234
236
 
235
237
  if @default_topic.nil?
238
+ if @use_default_for_unknown_topic || @use_default_for_unknown_partition_error
239
+ raise Fluent::ConfigError, "default_topic must be set when use_default_for_unknown_topic or use_default_for_unknown_partition_error is true"
240
+ end
236
241
  if @chunk_keys.include?(@topic_key) && !@chunk_key_tag
237
242
  log.warn "Use '#{@topic_key}' field of event record for topic but no fallback. Recommend to set default_topic or set 'tag' in buffer chunk keys like <buffer #{@topic_key},tag>"
238
243
  end
@@ -466,17 +471,25 @@ DESC
466
471
 
467
472
  def enqueue_with_retry(producer, topic, record_buf, message_key, partition, headers, time)
468
473
  attempt = 0
474
+ actual_topic = topic
475
+
469
476
  loop do
470
477
  begin
471
478
  @enqueue_rate.raise_if_limit_exceeded(record_buf.bytesize) if @enqueue_rate
472
- return producer.produce(topic: topic, payload: record_buf, key: message_key, partition: partition, headers: headers, timestamp: @use_event_time ? Time.at(time) : nil)
479
+ return producer.produce(topic: actual_topic, payload: record_buf, key: message_key, partition: partition, headers: headers, timestamp: @use_event_time ? Time.at(time) : nil)
473
480
  rescue EnqueueRate::LimitExceeded => e
474
481
  @enqueue_rate.revert if @enqueue_rate
475
482
  duration = e.next_retry_clock - Fluent::Clock.now
476
483
  sleep(duration) if duration > 0.0
477
484
  rescue Exception => e
478
485
  @enqueue_rate.revert if @enqueue_rate
479
- if e.respond_to?(:code) && e.code == :queue_full
486
+
487
+ if !e.respond_to?(:code)
488
+ raise e
489
+ end
490
+
491
+ case e.code
492
+ when :queue_full
480
493
  if attempt <= @max_enqueue_retries
481
494
  log.warn "Failed to enqueue message; attempting retry #{attempt} of #{@max_enqueue_retries} after #{@enqueue_retry_backoff}s"
482
495
  sleep @enqueue_retry_backoff
@@ -484,6 +497,25 @@ DESC
484
497
  else
485
498
  raise "Failed to enqueue message although tried retry #{@max_enqueue_retries} times"
486
499
  end
500
+ # https://github.com/confluentinc/librdkafka/blob/c282ba2423b2694052393c8edb0399a5ef471b3f/src/rdkafka.h#LL309C9-L309C41
501
+ # RD_KAFKA_RESP_ERR__UNKNOWN_TOPIC
502
+ when :unknown_topic
503
+ if @use_default_for_unknown_topic && actual_topic != @default_topic
504
+ log.debug "'#{actual_topic}' topic not found. Retry with '#{@default_topic}' topic"
505
+ actual_topic = @default_topic
506
+ retry
507
+ end
508
+ raise e
509
+ # https://github.com/confluentinc/librdkafka/blob/c282ba2423b2694052393c8edb0399a5ef471b3f/src/rdkafka.h#L305
510
+ # RD_KAFKA_RESP_ERR__UNKNOWN_PARTITION
511
+ when :unknown_partition
512
+ if @use_default_for_unknown_partition_error && actual_topic != @default_topic
513
+ log.debug "failed writing to topic '#{actual_topic}' with error '#{e.to_s}'. Writing message to topic '#{@default_topic}'"
514
+ actual_topic = @default_topic
515
+ retry
516
+ end
517
+
518
+ raise e
487
519
  else
488
520
  raise e
489
521
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-kafka
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.19.0
4
+ version: 0.19.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hidemasa Togashi
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-04-26 00:00:00.000000000 Z
12
+ date: 2023-09-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fluentd