deimos-ruby 1.10.0 → 1.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a614febc556860a51e870e89beb90fde63201fffae3ba7ca78c53d423a65a7b6
4
- data.tar.gz: e4676b33fbaf9c105ffd12b89a0090a86b8befd7cf0e09b39078a70e213f72dc
3
+ metadata.gz: 4c2fe121d207349905ce908ee4bdb3a2d420a545135c25b47aa4c99e5b5153ef
4
+ data.tar.gz: e28688edca132bd6d67ad4414d5e3616eb2f217274a6c27dd701816520241a76
5
5
  SHA512:
6
- metadata.gz: 0d418e1d0b27008392da829980c6bdf754111a1f103965dce6882f97d3a02f0220d58756f6f1f0682df12944eac1a012516b0a3612c257342509b6e0b4c3da57
7
- data.tar.gz: 1be3de2310297dc6b75a8f98b6c3f84483c6c401d6395dc6752cc57c342f8935911ba1ad11e8eb69e6bfcb19720e8540985c42976033401c39e137a3ab8fbc40
6
+ metadata.gz: 7ab87d73ff46dcbf415f65579f3a13202f9e7d0e61918672ef0f9e100babbeb4a27bfd1dce791bf5f36d38cea775881bd38ef424df8317cfaf440ce5b44414ed
7
+ data.tar.gz: 252d9a2a0e65a78c3faa5b420a1504230cd7d621714387930b369183724c33936240ec534181df024e6d4b5688ba8bca6bae2e0ca1572487dd1aadaf1960b97d
data/CHANGELOG.md CHANGED
@@ -7,6 +7,28 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## UNRELEASED
9
9
 
10
+ ## 1.11.1 - 2021-08-27
11
+
12
+ - ### Fixes :wrench:
13
+ - Fixed issue where ActiveRecord batch consumption would try to decode keys twice.
14
+
15
+ - ### Roadmap :car:
16
+ - TestHelper does not automatically reset Deimos config before each test. [#120](https://github.com/flipp-oss/deimos/pull/120).
17
+ **Please note that this is a breaking change**
18
+
19
+
20
+ ## 1.10.2 - 2021-07-20
21
+
22
+ - ### Fixes :wrench:
23
+
24
+ - Fixed issue where producers would stay in an error state after e.g. authorization failures for one topic that wouldn't apply to other topics.
25
+
26
+ ## 1.10.1 - 2021-06-21
27
+
28
+ - ### Fixes :wrench:
29
+
30
+ - Fixed crash when trying to decode a nil payload (e.g. during instrumentation of `send_produce_error`.)
31
+
10
32
  ## 1.10.0 - 2021-03-22
11
33
 
12
34
  - ### Roadmap :car:
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- deimos-ruby (1.9.2)
4
+ deimos-ruby (1.11.0)
5
5
  avro_turf (~> 0.11)
6
6
  fig_tree (~> 0.0.2)
7
7
  phobos (>= 1.9, < 3.0)
@@ -92,7 +92,7 @@ GEM
92
92
  rake (>= 12.0.0, < 14.0.0)
93
93
  dogstatsd-ruby (4.8.3)
94
94
  erubi (1.10.0)
95
- excon (0.79.0)
95
+ excon (0.81.0)
96
96
  exponential-backoff (0.0.4)
97
97
  ffi (1.15.0)
98
98
  fig_tree (0.0.2)
@@ -135,16 +135,18 @@ GEM
135
135
  marcel (0.3.3)
136
136
  mimemagic (~> 0.3.2)
137
137
  method_source (1.0.0)
138
- mimemagic (0.3.5)
138
+ mimemagic (0.3.10)
139
+ nokogiri (~> 1)
140
+ rake
139
141
  mini_mime (1.0.2)
140
- mini_portile2 (2.5.0)
142
+ mini_portile2 (2.5.1)
141
143
  minitest (5.14.4)
142
144
  msgpack (1.4.2)
143
145
  multi_json (1.15.0)
144
146
  mysql2 (0.5.3)
145
147
  nenv (0.3.0)
146
148
  nio4r (2.5.7)
147
- nokogiri (1.11.1)
149
+ nokogiri (1.11.5)
148
150
  mini_portile2 (~> 2.5.0)
149
151
  racc (~> 1.4)
150
152
  notiffany (0.1.3)
@@ -201,7 +203,7 @@ GEM
201
203
  rb-inotify (0.10.1)
202
204
  ffi (~> 1.0)
203
205
  regexp_parser (2.1.1)
204
- rexml (3.2.4)
206
+ rexml (3.2.5)
205
207
  rspec (3.10.0)
206
208
  rspec-core (~> 3.10.0)
207
209
  rspec-expectations (~> 3.10.0)
@@ -287,4 +289,4 @@ DEPENDENCIES
287
289
  sqlite3 (~> 1.3)
288
290
 
289
291
  BUNDLED WITH
290
- 2.2.5
292
+ 2.2.17
data/README.md CHANGED
@@ -29,6 +29,7 @@ Built on Phobos and hence Ruby-Kafka.
29
29
  * [Running Consumers](#running-consumers)
30
30
  * [Metrics](#metrics)
31
31
  * [Testing](#testing)
32
+ * [Test Helpers](#test-helpers)
32
33
  * [Integration Test Helpers](#integration-test-helpers)
33
34
  * [Utilities](#utilities)
34
35
  * [Contributing](#contributing)
@@ -879,8 +880,7 @@ Also see [deimos.rb](lib/deimos.rb) under `Configure tracing` to see how the tra
879
880
 
880
881
  # Testing
881
882
 
882
- Deimos comes with a test helper class which sets the various backends
883
- to mock versions, and provides useful methods for testing consumers.
883
+ Deimos comes with a test helper class which provides useful methods for testing consumers.
884
884
 
885
885
  In `spec_helper.rb`:
886
886
  ```ruby
@@ -889,7 +889,56 @@ RSpec.configure do |config|
889
889
  end
890
890
  ```
891
891
 
892
- In your test, you now have the following methods available:
892
+ ## Test Configuration
893
+
894
+ ```ruby
895
+ # The following can be added to a rpsec file so that each unit
896
+ # test can have the same settings every time it is run
897
+ around(:each) do |example|
898
+ Deimos::TestHelpers.unit_test!
899
+ example.run
900
+ Deimos.config.reset!
901
+ end
902
+
903
+ # Similarly you can use the Kafka test helper
904
+ around(:each) do |example|
905
+ Deimos::TestHelpers.kafka_test!
906
+ example.run
907
+ Deimos.config.reset!
908
+ end
909
+
910
+ # Kakfa test helper using schema registry
911
+ around(:each) do |example|
912
+ Deimos::TestHelpers.full_integration_test!
913
+ example.run
914
+ Deimos.config.reset!
915
+ end
916
+ ```
917
+
918
+ With the help of these helper methods, rspec examples can be written without having to tinker with Deimos settings.
919
+ This also prevents Deimos setting changes from leaking in to other examples.
920
+
921
+ This does not take away the ability to configure Deimos manually in individual examples. Deimos can still be configured like so:
922
+ ```ruby
923
+ it 'should not fail this random test' do
924
+
925
+ Deimos.configure do |config|
926
+ config.consumers.fatal_error = proc { true }
927
+ config.consumers.reraise_errors = false
928
+ end
929
+ ...
930
+ expect(some_object).to be_truthy
931
+ ...
932
+ Deimos.config.reset!
933
+ end
934
+ ```
935
+ If you are using one of the test helpers in an `around(:each)` block and want to override few settings for one example,
936
+ you can do it like in the example shown above. These settings would only apply to that specific example and the Deimos config should
937
+ reset once the example has finished running.
938
+
939
+ ## Test Usage
940
+
941
+ In your tests, you now have the following methods available:
893
942
  ```ruby
894
943
  # Pass a consumer class (not instance) to validate a payload against it.
895
944
  # This will fail if the payload does not match the schema the consumer
@@ -937,6 +986,8 @@ expect(message).to eq({
937
986
  })
938
987
  ```
939
988
 
989
+ ### Test Utilities
990
+
940
991
  There is also a helper method that will let you test if an existing schema
941
992
  would be compatible with a new version of it. You can use this in your
942
993
  Ruby console but it would likely not be part of your RSpec test:
@@ -947,19 +998,6 @@ require 'deimos/test_helpers'
947
998
  Deimos::TestHelpers.schemas_compatible?(schema1, schema2)
948
999
  ```
949
1000
 
950
- ### Integration Test Helpers
951
-
952
- When running integration tests, you'll want to override the default test helper settings:
953
-
954
- ```ruby
955
- config.before(:each, :my_integration_metadata) do
956
- Deimos.configure do
957
- producers.backend :kafka
958
- schema.backend :avro_schema_registry
959
- end
960
- end
961
- ```
962
-
963
1001
  You can use the `InlineConsumer` class to help with integration testing,
964
1002
  with a full external Kafka running.
965
1003
 
@@ -44,14 +44,12 @@ module Deimos
44
44
  # @param key [String] The encoded key.
45
45
  # @return [Hash] The key attributes.
46
46
  def record_key(key)
47
- decoded_key = decode_key(key)
48
-
49
- if decoded_key.nil?
47
+ if key.nil?
50
48
  {}
51
- elsif decoded_key.is_a?(Hash)
52
- @key_converter.convert(decoded_key)
49
+ elsif key.is_a?(Hash)
50
+ @key_converter.convert(key)
53
51
  else
54
- { @klass.primary_key => decoded_key }
52
+ { @klass.primary_key => key }
55
53
  end
56
54
  end
57
55
 
@@ -40,8 +40,9 @@ module Deimos
40
40
  # Decode a payload with a schema. Public method.
41
41
  # @param payload [String]
42
42
  # @param schema [Symbol|String]
43
- # @return [Hash]
43
+ # @return [Hash,nil]
44
44
  def decode(payload, schema: nil)
45
+ return nil if payload.nil?
45
46
  decode_payload(payload, schema: schema || @schema)
46
47
  end
47
48
 
@@ -18,22 +18,39 @@ module Deimos
18
18
  def sent_messages
19
19
  Deimos::Backends::Test.sent_messages
20
20
  end
21
+
22
+ # Set the config to the right settings for a unit test
23
+ def unit_test!
24
+ Deimos.configure do |deimos_config|
25
+ deimos_config.logger = Logger.new(STDOUT)
26
+ deimos_config.consumers.reraise_errors = true
27
+ deimos_config.kafka.seed_brokers ||= ['test_broker']
28
+ deimos_config.schema.backend = Deimos.schema_backend_class.mock_backend
29
+ deimos_config.producers.backend = :test
30
+ end
31
+ end
32
+
33
+ # Kafka test config with avro schema registry
34
+ def full_integration_test!
35
+ Deimos.configure do |deimos_config|
36
+ deimos_config.producers.backend = :kafka
37
+ deimos_config.schema.backend = :avro_schema_registry
38
+ end
39
+ end
40
+
41
+ # Set the config to the right settings for a kafka test
42
+ def kafka_test!
43
+ Deimos.configure do |deimos_config|
44
+ deimos_config.producers.backend = :kafka
45
+ deimos_config.schema.backend = :avro_validation
46
+ end
47
+ end
21
48
  end
22
49
 
23
50
  included do
24
51
 
25
52
  RSpec.configure do |config|
26
53
 
27
- config.before(:suite) do
28
- Deimos.configure do |d_config|
29
- d_config.logger = Logger.new(STDOUT)
30
- d_config.consumers.reraise_errors = true
31
- d_config.kafka.seed_brokers ||= ['test_broker']
32
- d_config.schema.backend = Deimos.schema_backend_class.mock_backend
33
- d_config.producers.backend = :test
34
- end
35
- end
36
-
37
54
  config.prepend_before(:each) do
38
55
  client = double('client').as_null_object
39
56
  allow(client).to receive(:time) do |*_args, &block|
@@ -60,7 +60,7 @@ module Deimos
60
60
  end
61
61
 
62
62
  # @param topic [String]
63
- # @return [String] the topic that was locked, or nil if none were.
63
+ # @return [String, nil] the topic that was locked, or nil if none were.
64
64
  def process_topic(topic)
65
65
  # If the topic is already locked, another producer is currently
66
66
  # working on it. Move on to the next one.
@@ -76,6 +76,7 @@ module Deimos
76
76
  rescue StandardError => e
77
77
  @logger.error("Error processing messages for topic #{@current_topic}: #{e.class.name}: #{e.message} #{e.backtrace.join("\n")}")
78
78
  KafkaTopicInfo.register_error(@current_topic, @id)
79
+ shutdown_producer
79
80
  end
80
81
 
81
82
  # Process a single batch in a topic.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Deimos
4
- VERSION = '1.10.0'
4
+ VERSION = '1.11.1'
5
5
  end
@@ -26,4 +26,8 @@ describe Deimos::SchemaBackends::Base do
26
26
  backend.decode(payload, schema: 'schema2')
27
27
  end
28
28
 
29
+ it 'should return nil if passed nil' do
30
+ expect(backend.decode(nil, schema: 'schema2')).to be_nil
31
+ end
32
+
29
33
  end
@@ -262,11 +262,13 @@ each_db_config(Deimos::Utils::DbProducer) do
262
262
  end
263
263
 
264
264
  it 'should register an error if it gets an error' do
265
+ allow(producer).to receive(:shutdown_producer)
265
266
  expect(producer).to receive(:retrieve_messages).and_raise('OH NOES')
266
267
  expect(Deimos::KafkaTopicInfo).to receive(:register_error).
267
268
  with('my-topic', 'abc')
268
269
  expect(producer).not_to receive(:produce_messages)
269
270
  producer.process_topic('my-topic')
271
+ expect(producer).to have_received(:shutdown_producer)
270
272
  end
271
273
 
272
274
  it 'should move on if it gets a partial batch' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deimos-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.10.0
4
+ version: 1.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Orner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-22 00:00:00.000000000 Z
11
+ date: 2021-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: avro_turf