rdkafka 0.13.0 → 0.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +388 -111
  3. data/{LICENSE → MIT-LICENSE} +2 -1
  4. data/README.md +90 -43
  5. data/Rakefile +21 -23
  6. data/bin/verify_kafka_warnings +44 -0
  7. data/dist/librdkafka-2.15.1.tar.gz +0 -0
  8. data/dist/patches/rdkafka_global_init.patch +15 -0
  9. data/docker-compose-ssl.yml +39 -0
  10. data/docker-compose.yml +22 -17
  11. data/ext/Rakefile +97 -30
  12. data/lib/rdkafka/abstract_handle.rb +113 -34
  13. data/lib/rdkafka/admin/acl_binding_result.rb +51 -0
  14. data/lib/rdkafka/admin/alter_consumer_group_offsets_handle.rb +31 -0
  15. data/lib/rdkafka/admin/alter_consumer_group_offsets_report.rb +50 -0
  16. data/lib/rdkafka/admin/config_binding_result.rb +30 -0
  17. data/lib/rdkafka/admin/config_resource_binding_result.rb +19 -0
  18. data/lib/rdkafka/admin/create_acl_handle.rb +32 -0
  19. data/lib/rdkafka/admin/create_acl_report.rb +26 -0
  20. data/lib/rdkafka/admin/create_partitions_handle.rb +28 -0
  21. data/lib/rdkafka/admin/create_partitions_report.rb +7 -0
  22. data/lib/rdkafka/admin/create_topic_handle.rb +8 -7
  23. data/lib/rdkafka/admin/create_topic_report.rb +4 -1
  24. data/lib/rdkafka/admin/delete_acl_handle.rb +31 -0
  25. data/lib/rdkafka/admin/delete_acl_report.rb +25 -0
  26. data/lib/rdkafka/admin/delete_consumer_group_offsets_handle.rb +31 -0
  27. data/lib/rdkafka/admin/delete_consumer_group_offsets_report.rb +50 -0
  28. data/lib/rdkafka/admin/delete_groups_handle.rb +31 -0
  29. data/lib/rdkafka/admin/delete_groups_report.rb +27 -0
  30. data/lib/rdkafka/admin/delete_records_handle.rb +31 -0
  31. data/lib/rdkafka/admin/delete_records_report.rb +25 -0
  32. data/lib/rdkafka/admin/delete_topic_handle.rb +8 -7
  33. data/lib/rdkafka/admin/delete_topic_report.rb +4 -1
  34. data/lib/rdkafka/admin/describe_acl_handle.rb +31 -0
  35. data/lib/rdkafka/admin/describe_acl_report.rb +27 -0
  36. data/lib/rdkafka/admin/describe_cluster_handle.rb +31 -0
  37. data/lib/rdkafka/admin/describe_cluster_report.rb +48 -0
  38. data/lib/rdkafka/admin/describe_configs_handle.rb +30 -0
  39. data/lib/rdkafka/admin/describe_configs_report.rb +56 -0
  40. data/lib/rdkafka/admin/describe_consumer_groups_handle.rb +31 -0
  41. data/lib/rdkafka/admin/describe_consumer_groups_report.rb +151 -0
  42. data/lib/rdkafka/admin/describe_result_parsing.rb +47 -0
  43. data/lib/rdkafka/admin/describe_topics_handle.rb +31 -0
  44. data/lib/rdkafka/admin/describe_topics_report.rb +118 -0
  45. data/lib/rdkafka/admin/incremental_alter_configs_handle.rb +30 -0
  46. data/lib/rdkafka/admin/incremental_alter_configs_report.rb +56 -0
  47. data/lib/rdkafka/admin/list_consumer_groups_handle.rb +31 -0
  48. data/lib/rdkafka/admin/list_consumer_groups_report.rb +83 -0
  49. data/lib/rdkafka/admin/list_offsets_handle.rb +31 -0
  50. data/lib/rdkafka/admin/list_offsets_report.rb +54 -0
  51. data/lib/rdkafka/admin.rb +1381 -38
  52. data/lib/rdkafka/bindings/admin/acls.rb +85 -0
  53. data/lib/rdkafka/bindings/admin/configs.rb +37 -0
  54. data/lib/rdkafka/bindings/admin/list_offsets.rb +26 -0
  55. data/lib/rdkafka/bindings/admin.rb +197 -0
  56. data/lib/rdkafka/bindings/callbacks.rb +100 -0
  57. data/lib/rdkafka/bindings/configuration.rb +50 -0
  58. data/lib/rdkafka/bindings/consumer.rb +83 -0
  59. data/lib/rdkafka/bindings/errors.rb +15 -0
  60. data/lib/rdkafka/bindings/handle.rb +16 -0
  61. data/lib/rdkafka/bindings/messages.rb +28 -0
  62. data/lib/rdkafka/bindings/metadata.rb +14 -0
  63. data/lib/rdkafka/bindings/polling.rb +17 -0
  64. data/lib/rdkafka/bindings/producer.rb +77 -0
  65. data/lib/rdkafka/bindings/structs.rb +62 -0
  66. data/lib/rdkafka/bindings.rb +69 -294
  67. data/lib/rdkafka/callbacks/alter_consumer_group_offsets_handler.rb +65 -0
  68. data/lib/rdkafka/callbacks/base_handler.rb +62 -0
  69. data/lib/rdkafka/callbacks/create_acl_handler.rb +37 -0
  70. data/lib/rdkafka/callbacks/create_partitions_handler.rb +37 -0
  71. data/lib/rdkafka/callbacks/create_topic_handler.rb +37 -0
  72. data/lib/rdkafka/callbacks/delete_acl_handler.rb +42 -0
  73. data/lib/rdkafka/callbacks/delete_consumer_group_offsets_handler.rb +65 -0
  74. data/lib/rdkafka/callbacks/delete_groups_handler.rb +37 -0
  75. data/lib/rdkafka/callbacks/delete_records_handler.rb +38 -0
  76. data/lib/rdkafka/callbacks/delete_topic_handler.rb +37 -0
  77. data/lib/rdkafka/callbacks/describe_acl_handler.rb +35 -0
  78. data/lib/rdkafka/callbacks/describe_cluster_handler.rb +36 -0
  79. data/lib/rdkafka/callbacks/describe_configs_handler.rb +42 -0
  80. data/lib/rdkafka/callbacks/describe_consumer_groups_handler.rb +36 -0
  81. data/lib/rdkafka/callbacks/describe_topics_handler.rb +36 -0
  82. data/lib/rdkafka/callbacks/incremental_alter_configs_handler.rb +42 -0
  83. data/lib/rdkafka/callbacks/list_consumer_groups_handler.rb +39 -0
  84. data/lib/rdkafka/callbacks/list_offsets_handler.rb +42 -0
  85. data/lib/rdkafka/callbacks.rb +273 -52
  86. data/lib/rdkafka/clients.rb +81 -0
  87. data/lib/rdkafka/config.rb +333 -91
  88. data/lib/rdkafka/consumer/allocator.rb +38 -0
  89. data/lib/rdkafka/consumer/headers.rb +39 -25
  90. data/lib/rdkafka/consumer/message.rb +18 -20
  91. data/lib/rdkafka/consumer/partition.rb +15 -4
  92. data/lib/rdkafka/consumer/topic_partition_list.rb +82 -48
  93. data/lib/rdkafka/consumer.rb +765 -192
  94. data/lib/rdkafka/defaults.rb +123 -0
  95. data/lib/rdkafka/error.rb +40 -14
  96. data/lib/rdkafka/helpers/list_offsets.rb +127 -0
  97. data/lib/rdkafka/helpers/metadata.rb +29 -0
  98. data/lib/rdkafka/helpers/oauth.rb +95 -0
  99. data/lib/rdkafka/helpers/time.rb +19 -0
  100. data/lib/rdkafka/metadata.rb +138 -26
  101. data/lib/rdkafka/native_kafka.rb +142 -22
  102. data/lib/rdkafka/producer/delivery_handle.rb +27 -7
  103. data/lib/rdkafka/producer/delivery_report.rb +71 -4
  104. data/lib/rdkafka/producer/partitions_count_cache.rb +212 -0
  105. data/lib/rdkafka/producer.rb +422 -81
  106. data/lib/rdkafka/version.rb +6 -3
  107. data/lib/rdkafka.rb +73 -1
  108. data/package-lock.json +331 -0
  109. data/package.json +9 -0
  110. data/rdkafka.gemspec +78 -25
  111. data/renovate.json +111 -0
  112. metadata +114 -134
  113. data/.gitignore +0 -8
  114. data/.rspec +0 -1
  115. data/.semaphore/semaphore.yml +0 -27
  116. data/.yardopts +0 -2
  117. data/Gemfile +0 -5
  118. data/Guardfile +0 -19
  119. data/ext/README.md +0 -18
  120. data/spec/rdkafka/abstract_handle_spec.rb +0 -115
  121. data/spec/rdkafka/admin/create_topic_handle_spec.rb +0 -54
  122. data/spec/rdkafka/admin/create_topic_report_spec.rb +0 -18
  123. data/spec/rdkafka/admin/delete_topic_handle_spec.rb +0 -54
  124. data/spec/rdkafka/admin/delete_topic_report_spec.rb +0 -18
  125. data/spec/rdkafka/admin_spec.rb +0 -204
  126. data/spec/rdkafka/bindings_spec.rb +0 -136
  127. data/spec/rdkafka/callbacks_spec.rb +0 -22
  128. data/spec/rdkafka/config_spec.rb +0 -197
  129. data/spec/rdkafka/consumer/headers_spec.rb +0 -62
  130. data/spec/rdkafka/consumer/message_spec.rb +0 -141
  131. data/spec/rdkafka/consumer/partition_spec.rb +0 -59
  132. data/spec/rdkafka/consumer/topic_partition_list_spec.rb +0 -225
  133. data/spec/rdkafka/consumer_spec.rb +0 -1106
  134. data/spec/rdkafka/error_spec.rb +0 -91
  135. data/spec/rdkafka/metadata_spec.rb +0 -80
  136. data/spec/rdkafka/native_kafka_spec.rb +0 -124
  137. data/spec/rdkafka/producer/delivery_handle_spec.rb +0 -47
  138. data/spec/rdkafka/producer/delivery_report_spec.rb +0 -23
  139. data/spec/rdkafka/producer_spec.rb +0 -557
  140. data/spec/spec_helper.rb +0 -155
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rdkafka
4
+ class Admin
5
+ # Handle for delete groups operation
6
+ class DeleteGroupsHandle < AbstractHandle
7
+ layout :pending, :bool,
8
+ :response, :int
9
+
10
+ # @return [String] the name of the operation
11
+ def operation_name
12
+ "delete groups"
13
+ end
14
+
15
+ # Creates the result report
16
+ # @return [DeleteGroupsReport]
17
+ def create_result
18
+ prepared_result
19
+ end
20
+
21
+ # Raises an error if the operation failed
22
+ # @raise [RdkafkaError]
23
+ def raise_error
24
+ raise RdkafkaError.new(
25
+ self[:response],
26
+ broker_message: broker_message
27
+ )
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rdkafka
4
+ class Admin
5
+ # Report for delete groups operation result
6
+ class DeleteGroupsReport
7
+ # Any error message generated from the DeleteTopic
8
+ # @return [String]
9
+ attr_reader :error_string
10
+
11
+ # The name of the topic deleted
12
+ # @return [String]
13
+ attr_reader :result_name
14
+
15
+ # @param error_string [FFI::Pointer] pointer to error string
16
+ # @param result_name [FFI::Pointer] pointer to group name
17
+ def initialize(error_string, result_name)
18
+ if error_string != FFI::Pointer::NULL
19
+ @error_string = error_string.read_string
20
+ end
21
+ if result_name != FFI::Pointer::NULL
22
+ @result_name = result_name.read_string
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rdkafka
4
+ class Admin
5
+ # Handle for delete records operation
6
+ class DeleteRecordsHandle < AbstractHandle
7
+ layout :pending, :bool,
8
+ :response, :int
9
+
10
+ # @return [String] the name of the operation
11
+ def operation_name
12
+ "delete records"
13
+ end
14
+
15
+ # @return [DeleteRecordsReport] report prepared by the background event callback, with the
16
+ # post-deletion low-watermark offsets (or per-partition errors)
17
+ def create_result
18
+ prepared_result
19
+ end
20
+
21
+ # Raises an error if the operation failed
22
+ # @raise [RdkafkaError]
23
+ def raise_error
24
+ raise RdkafkaError.new(
25
+ self[:response],
26
+ broker_message: broker_message
27
+ )
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rdkafka
4
+ class Admin
5
+ # Report for delete records operation result
6
+ class DeleteRecordsReport
7
+ # Per-partition results. Each partition's `offset` is the post-deletion low-watermark (the
8
+ # smallest available offset of all live replicas) and its `err` carries the per-partition
9
+ # error code, if deletion failed for that partition.
10
+ # @return [Rdkafka::Consumer::TopicPartitionList]
11
+ attr_reader :offsets
12
+
13
+ # @param result_ptr [FFI::Pointer] pointer to the `rd_kafka_DeleteRecords_result_t`
14
+ def initialize(result_ptr)
15
+ @offsets = Rdkafka::Consumer::TopicPartitionList.new
16
+
17
+ return if result_ptr.null?
18
+
19
+ native_tpl = Bindings.rd_kafka_DeleteRecords_result_offsets(result_ptr)
20
+
21
+ @offsets = Rdkafka::Consumer::TopicPartitionList.from_native_tpl(native_tpl)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -2,26 +2,27 @@
2
2
 
3
3
  module Rdkafka
4
4
  class Admin
5
+ # Handle for delete topic operation
5
6
  class DeleteTopicHandle < AbstractHandle
6
7
  layout :pending, :bool,
7
- :response, :int,
8
- :error_string, :pointer,
9
- :result_name, :pointer
8
+ :response, :int
10
9
 
11
10
  # @return [String] the name of the operation
12
11
  def operation_name
13
12
  "delete topic"
14
13
  end
15
14
 
16
- # @return [Boolean] whether the delete topic was successful
15
+ # @return [DeleteTopicReport] report prepared by the background event callback
17
16
  def create_result
18
- DeleteTopicReport.new(self[:error_string], self[:result_name])
17
+ prepared_result
19
18
  end
20
19
 
20
+ # Raises an error if the operation failed
21
+ # @raise [RdkafkaError]
21
22
  def raise_error
22
23
  raise RdkafkaError.new(
23
- self[:response],
24
- broker_message: DeleteTopicReport.new(self[:error_string], self[:result_name]).error_string
24
+ self[:response],
25
+ broker_message: broker_message
25
26
  )
26
27
  end
27
28
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  module Rdkafka
4
4
  class Admin
5
+ # Report for delete topic operation result
5
6
  class DeleteTopicReport
6
7
  # Any error message generated from the DeleteTopic
7
8
  # @return [String]
@@ -11,12 +12,14 @@ module Rdkafka
11
12
  # @return [String]
12
13
  attr_reader :result_name
13
14
 
15
+ # @param error_string [FFI::Pointer] pointer to error string
16
+ # @param result_name [FFI::Pointer] pointer to topic name
14
17
  def initialize(error_string, result_name)
15
18
  if error_string != FFI::Pointer::NULL
16
19
  @error_string = error_string.read_string
17
20
  end
18
21
  if result_name != FFI::Pointer::NULL
19
- @result_name = @result_name = result_name.read_string
22
+ @result_name = result_name.read_string
20
23
  end
21
24
  end
22
25
  end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rdkafka
4
+ class Admin
5
+ # Handle for describe ACL operation
6
+ class DescribeAclHandle < AbstractHandle
7
+ layout :pending, :bool,
8
+ :response, :int
9
+
10
+ # @return [String] the name of the operation.
11
+ def operation_name
12
+ "describe acl"
13
+ end
14
+
15
+ # @return [DescribeAclReport] report prepared by the background event callback, with an
16
+ # array of acls that matches the request filters.
17
+ def create_result
18
+ prepared_result
19
+ end
20
+
21
+ # Raises an error if the operation failed
22
+ # @raise [RdkafkaError]
23
+ def raise_error
24
+ raise RdkafkaError.new(
25
+ self[:response],
26
+ broker_message: broker_message
27
+ )
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rdkafka
4
+ class Admin
5
+ # Report for describe ACL operation result
6
+ class DescribeAclReport
7
+ # acls that exists in the cluster for the resource_type, resource_name and pattern_type
8
+ # filters provided in the request.
9
+ # @return [Rdkafka::Bindings::AclBindingResult] array of matching acls.
10
+ attr_reader :acls
11
+
12
+ # @param acls [FFI::Pointer] pointer to ACLs array
13
+ # @param acls_count [Integer] number of ACLs
14
+ def initialize(acls:, acls_count:)
15
+ @acls = []
16
+
17
+ if acls != FFI::Pointer::NULL
18
+ acl_binding_result_pointers = acls.read_array_of_pointer(acls_count)
19
+ (1..acls_count).map do |acl_index|
20
+ acl_binding_result = AclBindingResult.new(acl_binding_result_pointers[acl_index - 1])
21
+ @acls << acl_binding_result
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rdkafka
4
+ class Admin
5
+ # Handle for describe cluster operation
6
+ class DescribeClusterHandle < AbstractHandle
7
+ layout :pending, :bool,
8
+ :response, :int
9
+
10
+ # @return [String] the name of the operation
11
+ def operation_name
12
+ "describe cluster"
13
+ end
14
+
15
+ # @return [DescribeClusterReport] report prepared by the background event callback, with
16
+ # the cluster id, controller and broker nodes.
17
+ def create_result
18
+ prepared_result
19
+ end
20
+
21
+ # Raises an error if the operation failed
22
+ # @raise [RdkafkaError]
23
+ def raise_error
24
+ raise RdkafkaError.new(
25
+ self[:response],
26
+ broker_message: broker_message
27
+ )
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rdkafka
4
+ class Admin
5
+ # Report for describe cluster operation result
6
+ class DescribeClusterReport
7
+ include DescribeResultParsing
8
+
9
+ # @return [String, nil] the cluster id
10
+ attr_reader :cluster_id
11
+
12
+ # The current controller node, as a hash with `:id` [Integer], `:host` [String],
13
+ # `:port` [Integer] and `:rack` [String, nil]
14
+ # @return [Hash, nil]
15
+ attr_reader :controller
16
+
17
+ # Broker nodes of the cluster, each in the same shape as {#controller}
18
+ # @return [Array<Hash>]
19
+ attr_reader :nodes
20
+
21
+ # Operations the client is authorized to perform on the cluster, as
22
+ # `Bindings::RD_KAFKA_ACL_OPERATION_*` codes. `nil` unless requested with
23
+ # `include_authorized_operations: true`.
24
+ # @return [Array<Integer>, nil]
25
+ attr_reader :authorized_operations
26
+
27
+ # @param result_ptr [FFI::Pointer] pointer to the `rd_kafka_DescribeCluster_result_t`
28
+ def initialize(result_ptr)
29
+ @nodes = []
30
+
31
+ return if result_ptr.null?
32
+
33
+ cluster_id_ptr = Bindings.rd_kafka_DescribeCluster_result_cluster_id(result_ptr)
34
+ @cluster_id = cluster_id_ptr.null? ? nil : cluster_id_ptr.read_string
35
+ @controller = extract_node(Bindings.rd_kafka_DescribeCluster_result_controller(result_ptr))
36
+
37
+ count_ptr = FFI::MemoryPointer.new(:size_t)
38
+ @nodes = extract_nodes(Bindings.rd_kafka_DescribeCluster_result_nodes(result_ptr, count_ptr), count_ptr)
39
+
40
+ count_ptr = FFI::MemoryPointer.new(:size_t)
41
+ @authorized_operations = extract_authorized_operations(
42
+ Bindings.rd_kafka_DescribeCluster_result_authorized_operations(result_ptr, count_ptr),
43
+ count_ptr
44
+ )
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rdkafka
4
+ class Admin
5
+ # Handle for describe configs operation
6
+ class DescribeConfigsHandle < AbstractHandle
7
+ layout :pending, :bool,
8
+ :response, :int
9
+
10
+ # @return [String] the name of the operation.
11
+ def operation_name
12
+ "describe configs"
13
+ end
14
+
15
+ # @return [DescribeConfigsReport] report prepared by the background event callback
16
+ def create_result
17
+ prepared_result
18
+ end
19
+
20
+ # Raises an error if the operation failed
21
+ # @raise [RdkafkaError]
22
+ def raise_error
23
+ raise RdkafkaError.new(
24
+ self[:response],
25
+ broker_message: broker_message
26
+ )
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rdkafka
4
+ class Admin
5
+ # Report for describe configs operation result
6
+ class DescribeConfigsReport
7
+ attr_reader :resources
8
+
9
+ # @param config_entries [FFI::Pointer] pointer to config entries array
10
+ # @param entry_count [Integer] number of config entries
11
+ def initialize(config_entries:, entry_count:)
12
+ @resources = []
13
+
14
+ return if config_entries == FFI::Pointer::NULL
15
+
16
+ config_entries
17
+ .read_array_of_pointer(entry_count)
18
+ .each { |config_resource_result_ptr| validate!(config_resource_result_ptr) }
19
+ .each do |config_resource_result_ptr|
20
+ config_resource_result = ConfigResourceBindingResult.new(config_resource_result_ptr)
21
+
22
+ pointer_to_size_t = FFI::MemoryPointer.new(:size_t)
23
+ configs_ptr = Bindings.rd_kafka_ConfigResource_configs(
24
+ config_resource_result_ptr,
25
+ pointer_to_size_t
26
+ )
27
+
28
+ configs_ptr
29
+ .read_array_of_pointer(pointer_to_size_t.read_int)
30
+ .map { |config_ptr| ConfigBindingResult.new(config_ptr) }
31
+ .each { |config_binding| config_resource_result.configs << config_binding }
32
+
33
+ @resources << config_resource_result
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ # Validates the config resource result and raises an error if invalid
40
+ # @param config_resource_result_ptr [FFI::Pointer] pointer to the config resource result
41
+ # @raise [RdkafkaError] when the config resource has an error
42
+ def validate!(config_resource_result_ptr)
43
+ code = Bindings.rd_kafka_ConfigResource_error(config_resource_result_ptr)
44
+
45
+ return if code.zero?
46
+
47
+ raise(
48
+ RdkafkaError.new(
49
+ code,
50
+ Bindings.rd_kafka_ConfigResource_error_string(config_resource_result_ptr)
51
+ )
52
+ )
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rdkafka
4
+ class Admin
5
+ # Handle for describe consumer groups operation
6
+ class DescribeConsumerGroupsHandle < AbstractHandle
7
+ layout :pending, :bool,
8
+ :response, :int
9
+
10
+ # @return [String] the name of the operation
11
+ def operation_name
12
+ "describe consumer groups"
13
+ end
14
+
15
+ # @return [DescribeConsumerGroupsReport] report prepared by the background event callback,
16
+ # with the described consumer groups.
17
+ def create_result
18
+ prepared_result
19
+ end
20
+
21
+ # Raises an error if the operation failed
22
+ # @raise [RdkafkaError]
23
+ def raise_error
24
+ raise RdkafkaError.new(
25
+ self[:response],
26
+ broker_message: broker_message
27
+ )
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,151 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rdkafka
4
+ class Admin
5
+ # Report for describe consumer groups operation result
6
+ class DescribeConsumerGroupsReport
7
+ include DescribeResultParsing
8
+
9
+ # Described consumer groups, one per requested group id. Each entry is a hash with:
10
+ # - `:group_id` [String] the consumer group id
11
+ # - `:error` [RdkafkaError, nil] error describing this group, or `nil` on success. The
12
+ # other fields are not meaningful when it is set.
13
+ # - `:is_simple_consumer_group` [Boolean] `true` for a group that assigns partitions
14
+ # manually and uses Kafka only for offset storage
15
+ # - `:state` [Integer] the group state as a `Bindings::RD_KAFKA_CONSUMER_GROUP_STATE_*`
16
+ # code. A group id the cluster does not know is reported as
17
+ # `RD_KAFKA_CONSUMER_GROUP_STATE_DEAD` with no members.
18
+ # - `:state_name` [String] human-readable name of that state (e.g. `"Stable"`, `"Empty"`)
19
+ # - `:type` [Integer] the group protocol type as a
20
+ # `Bindings::RD_KAFKA_CONSUMER_GROUP_TYPE_*` code, one of:
21
+ # `RD_KAFKA_CONSUMER_GROUP_TYPE_CLASSIC`,
22
+ # `RD_KAFKA_CONSUMER_GROUP_TYPE_CONSUMER` (KIP-848),
23
+ # `RD_KAFKA_CONSUMER_GROUP_TYPE_UNKNOWN`
24
+ # - `:type_name` [String] human-readable name of that type (e.g. `"Classic"`, `"Consumer"`)
25
+ # - `:partition_assignor` [String, nil] partition assignor in use (e.g. `"range"`)
26
+ # - `:coordinator` [Hash, nil] the group coordinator broker as
27
+ # `{ id:, host:, port:, rack: }`
28
+ # - `:authorized_operations` [Array<Integer>, nil] ACL operations the client may perform on
29
+ # the group, as `Bindings::RD_KAFKA_ACL_OPERATION_*` codes. `nil` unless requested with
30
+ # `include_authorized_operations: true`.
31
+ # - `:members` [Array<Hash>] current group members, each with:
32
+ # - `:member_id` [String] the member (consumer) id
33
+ # - `:client_id` [String] the member's `client.id`
34
+ # - `:group_instance_id` [String, nil] the static membership instance id, if any
35
+ # - `:host` [String] the host the member connects from
36
+ # - `:assignment` [Hash{String => Array<Integer>}] assigned partitions, by topic
37
+ # - `:target_assignment` [Hash{String => Array<Integer>}, nil] partitions the member is
38
+ # moving to during a rebalance, by topic. Only `consumer` (KIP-848) groups have it;
39
+ # `nil` for `classic` groups.
40
+ # @return [Array<Hash>]
41
+ attr_reader :groups
42
+
43
+ # @param result_ptr [FFI::Pointer] pointer to the `rd_kafka_DescribeConsumerGroups_result_t`
44
+ def initialize(result_ptr)
45
+ @groups = []
46
+
47
+ return if result_ptr.null?
48
+
49
+ count_ptr = FFI::MemoryPointer.new(:size_t)
50
+ array_ptr = Bindings.rd_kafka_DescribeConsumerGroups_result_groups(result_ptr, count_ptr)
51
+
52
+ return if array_ptr.null?
53
+
54
+ array_ptr.read_array_of_pointer(count_ptr.read(:size_t)).each do |group_ptr|
55
+ @groups << build_group(group_ptr)
56
+ end
57
+ end
58
+
59
+ private
60
+
61
+ # @param group_ptr [FFI::Pointer] pointer to the `rd_kafka_ConsumerGroupDescription_t`
62
+ # @return [Hash]
63
+ def build_group(group_ptr)
64
+ state = Bindings.rd_kafka_ConsumerGroupDescription_state(group_ptr)
65
+ type = Bindings.rd_kafka_ConsumerGroupDescription_type(group_ptr)
66
+
67
+ {
68
+ group_id: read_string(Bindings.rd_kafka_ConsumerGroupDescription_group_id(group_ptr)),
69
+ error: build_error(Bindings.rd_kafka_ConsumerGroupDescription_error(group_ptr)),
70
+ is_simple_consumer_group:
71
+ Bindings.rd_kafka_ConsumerGroupDescription_is_simple_consumer_group(group_ptr) != 0,
72
+ state: state,
73
+ state_name: read_string(Bindings.rd_kafka_consumer_group_state_name(state)),
74
+ type: type,
75
+ type_name: read_string(Bindings.rd_kafka_consumer_group_type_name(type)),
76
+ partition_assignor:
77
+ read_string(Bindings.rd_kafka_ConsumerGroupDescription_partition_assignor(group_ptr)),
78
+ coordinator: extract_node(Bindings.rd_kafka_ConsumerGroupDescription_coordinator(group_ptr)),
79
+ authorized_operations: build_authorized_operations(group_ptr),
80
+ members: Array.new(Bindings.rd_kafka_ConsumerGroupDescription_member_count(group_ptr)) do |index|
81
+ build_member(Bindings.rd_kafka_ConsumerGroupDescription_member(group_ptr, index))
82
+ end
83
+ }
84
+ end
85
+
86
+ # @param member_ptr [FFI::Pointer] pointer to the `rd_kafka_MemberDescription_t`
87
+ # @return [Hash]
88
+ def build_member(member_ptr)
89
+ {
90
+ member_id: read_string(Bindings.rd_kafka_MemberDescription_consumer_id(member_ptr)),
91
+ client_id: read_string(Bindings.rd_kafka_MemberDescription_client_id(member_ptr)),
92
+ group_instance_id: read_string(Bindings.rd_kafka_MemberDescription_group_instance_id(member_ptr)),
93
+ host: read_string(Bindings.rd_kafka_MemberDescription_host(member_ptr)),
94
+ assignment: build_assignment(Bindings.rd_kafka_MemberDescription_assignment(member_ptr)),
95
+ target_assignment: build_target_assignment(member_ptr)
96
+ }
97
+ end
98
+
99
+ # @param assignment_ptr [FFI::Pointer] pointer to the `rd_kafka_MemberAssignment_t`
100
+ # @return [Hash{String => Array<Integer>}]
101
+ def build_assignment(assignment_ptr)
102
+ return {} if assignment_ptr.null?
103
+
104
+ tpl_ptr = Bindings.rd_kafka_MemberAssignment_partitions(assignment_ptr)
105
+
106
+ return {} if tpl_ptr.null?
107
+
108
+ Consumer::TopicPartitionList
109
+ .from_native_tpl(tpl_ptr)
110
+ .to_h
111
+ .transform_values { |partitions| (partitions || []).map(&:partition) }
112
+ end
113
+
114
+ # @param member_ptr [FFI::Pointer] pointer to the `rd_kafka_MemberDescription_t`
115
+ # @return [Hash{String => Array<Integer>}, nil]
116
+ def build_target_assignment(member_ptr)
117
+ assignment_ptr = Bindings.rd_kafka_MemberDescription_target_assignment(member_ptr)
118
+
119
+ assignment_ptr.null? ? nil : build_assignment(assignment_ptr)
120
+ end
121
+
122
+ # @param group_ptr [FFI::Pointer] pointer to the `rd_kafka_ConsumerGroupDescription_t`
123
+ # @return [Array<Integer>, nil]
124
+ def build_authorized_operations(group_ptr)
125
+ count_ptr = FFI::MemoryPointer.new(:size_t)
126
+
127
+ extract_authorized_operations(
128
+ Bindings.rd_kafka_ConsumerGroupDescription_authorized_operations(group_ptr, count_ptr),
129
+ count_ptr
130
+ )
131
+ end
132
+
133
+ # @param error_ptr [FFI::Pointer] pointer to the `rd_kafka_error_t`
134
+ # @return [RdkafkaError, nil]
135
+ def build_error(error_ptr)
136
+ return nil if error_ptr.null?
137
+
138
+ RdkafkaError.new(
139
+ Bindings.rd_kafka_error_code(error_ptr),
140
+ broker_message: read_string(Bindings.rd_kafka_error_string(error_ptr))
141
+ )
142
+ end
143
+
144
+ # @param ptr [FFI::Pointer] pointer to a C string
145
+ # @return [String, nil]
146
+ def read_string(ptr)
147
+ ptr.null? ? nil : ptr.read_string
148
+ end
149
+ end
150
+ end
151
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rdkafka
4
+ class Admin
5
+ # Helpers shared by the describe-topics and describe-cluster reports to copy nodes and
6
+ # authorized operations out of event-owned memory.
7
+ # @private
8
+ module DescribeResultParsing
9
+ private
10
+
11
+ # @param node_ptr [FFI::Pointer] pointer to a `rd_kafka_Node_t`
12
+ # @return [Hash, nil] node with `:id`, `:host`, `:port` and `:rack` or nil when NULL
13
+ def extract_node(node_ptr)
14
+ return nil if node_ptr.null?
15
+
16
+ host_ptr = Bindings.rd_kafka_Node_host(node_ptr)
17
+ rack_ptr = Bindings.rd_kafka_Node_rack(node_ptr)
18
+
19
+ {
20
+ id: Bindings.rd_kafka_Node_id(node_ptr),
21
+ host: host_ptr.null? ? nil : host_ptr.read_string,
22
+ port: Bindings.rd_kafka_Node_port(node_ptr),
23
+ rack: rack_ptr.null? ? nil : rack_ptr.read_string
24
+ }
25
+ end
26
+
27
+ # @param array_ptr [FFI::Pointer] pointer to a `rd_kafka_Node_t*` array
28
+ # @param count_ptr [FFI::MemoryPointer] size_t holding the array length
29
+ # @return [Array<Hash>] nodes as returned by {#extract_node}
30
+ def extract_nodes(array_ptr, count_ptr)
31
+ return [] if array_ptr.null?
32
+
33
+ array_ptr.read_array_of_pointer(count_ptr.read(:size_t)).map { |node_ptr| extract_node(node_ptr) }
34
+ end
35
+
36
+ # @param array_ptr [FFI::Pointer] pointer to a `rd_kafka_AclOperation_t` array
37
+ # @param count_ptr [FFI::MemoryPointer] size_t holding the array length
38
+ # @return [Array<Integer>, nil] `Bindings::RD_KAFKA_ACL_OPERATION_*` codes or nil when the
39
+ # authorized operations were not requested
40
+ def extract_authorized_operations(array_ptr, count_ptr)
41
+ return nil if array_ptr.null?
42
+
43
+ array_ptr.read_array_of_int(count_ptr.read(:size_t))
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rdkafka
4
+ class Admin
5
+ # Handle for describe topics operation
6
+ class DescribeTopicsHandle < AbstractHandle
7
+ layout :pending, :bool,
8
+ :response, :int
9
+
10
+ # @return [String] the name of the operation
11
+ def operation_name
12
+ "describe topics"
13
+ end
14
+
15
+ # @return [DescribeTopicsReport] report prepared by the background event callback, with
16
+ # the described topics.
17
+ def create_result
18
+ prepared_result
19
+ end
20
+
21
+ # Raises an error if the operation failed
22
+ # @raise [RdkafkaError]
23
+ def raise_error
24
+ raise RdkafkaError.new(
25
+ self[:response],
26
+ broker_message: broker_message
27
+ )
28
+ end
29
+ end
30
+ end
31
+ end