deimos-kafka 1.0.0.pre.beta19 → 1.0.0.pre.beta20

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: b20ab1bd5462b9ebdd61c00c0e8b70e30e547a42860ece6509b2981f582547ef
4
- data.tar.gz: 25d2eb38bed18e090b5729ca7f217cf963fc9396f6ebf141546077597d421053
3
+ metadata.gz: c85c35c068b88ef2a45ae788e6361ab63ee71fbb27fa4b58f598330bef855de7
4
+ data.tar.gz: 70d2b1d9e0967d614c1ced30db4222dbeb56256b94ef5cfc8684b3589eb62a0a
5
5
  SHA512:
6
- metadata.gz: 9be9ce52caf3014dd496bfcbb8a2626f394b76d5af6bf7b5a4ce6dcd3ad5e2bc6af55c225e15d81c672ed653b2dd025d651035b48ffac175367683529d62e3a3
7
- data.tar.gz: 222d68c723d352559f79b4ba328dc5aad1ed85a8191dc08266ab7c3113a5853fe7125b2bfba549c4bab081a2082a3b8206f36699461d678eb2eb9d492a0ab8ab
6
+ metadata.gz: 6c7e5148a6129c9d418a59d9bd0ece9727003aa3df1d37feb05ca21f00d526e357905c20ad44e1b8776af8df4d3dece4f43330fecaa0fb1a2456d0648643d3f9
7
+ data.tar.gz: 3ddae38b0b3b3616f448f785432feb373d55b991b064c01b5e742ac0454e3f7ea5b6f12d9e16a41cdd542c0ebf9afa08165e7d234a0363a690e6d5a232dff9cd
data/CHANGELOG.md CHANGED
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.0.0-beta20] - 2019-08-07
9
+ - Catch buffer overflows when producing via the DB producer and split the
10
+ batch up.
11
+
8
12
  ## [1.0.0-beta19] - 2019-08-06
9
13
  - Fix for DB producer crashing on error in Rails 3.
10
14
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- deimos-kafka (1.0.0.pre.beta19)
4
+ deimos-kafka (1.0.0.pre.beta20)
5
5
  avro-patches (~> 0.3)
6
6
  avro_turf (~> 0.8)
7
7
  phobos (~> 1.8)
@@ -127,7 +127,7 @@ GEM
127
127
  unicode-display_width (>= 1.4.0, < 1.7)
128
128
  rubocop-rspec (1.32.0)
129
129
  rubocop (>= 0.60.0)
130
- ruby-kafka (0.7.9)
130
+ ruby-kafka (0.7.10)
131
131
  digest-crc
132
132
  ruby-progressbar (1.10.1)
133
133
  ruby_dep (1.5.0)
@@ -65,8 +65,7 @@ module Deimos
65
65
  attr_hash = { locked_by: nil,
66
66
  locked_at: Time.zone.now,
67
67
  error: true,
68
- retries: record.retries + 1
69
- }
68
+ retries: record.retries + 1 }
70
69
  if Rails::VERSION::MAJOR >= 4
71
70
  record.update!(attr_hash)
72
71
  else
@@ -81,14 +81,29 @@ module Deimos
81
81
 
82
82
  # @param batch [Array<Hash>]
83
83
  def produce_messages(batch)
84
- @logger.debug("Publishing #{batch.size} messages to #{@current_topic}")
85
- producer.publish_list(batch)
86
- Deimos.config.metrics&.increment(
87
- 'publish',
88
- tags: %W(status:success topic:#{@current_topic}),
89
- by: batch.size
90
- )
91
- @logger.info("Sent #{batch.size} messages to #{@current_topic}")
84
+ batch_size = batch.size
85
+ begin
86
+ batch.in_groups_of(batch_size, false).each do |group|
87
+ @logger.debug("Publishing #{group.size} messages to #{@current_topic}")
88
+ producer.publish_list(group)
89
+ Deimos.config.metrics&.increment(
90
+ 'publish',
91
+ tags: %W(status:success topic:#{@current_topic}),
92
+ by: group.size
93
+ )
94
+ @logger.info("Sent #{group.size} messages to #{@current_topic}")
95
+ end
96
+ rescue Kafka::BufferOverflow
97
+ raise if batch_size == 1
98
+
99
+ @logger.error("Buffer overflow when publishing #{batch.size} in groups of #{batch_size}, retrying...")
100
+ if batch_size < 10
101
+ batch_size = 1
102
+ else
103
+ batch_size /= 10
104
+ end
105
+ retry
106
+ end
92
107
  end
93
108
  end
94
109
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Deimos
4
- VERSION = '1.0.0-beta19'
4
+ VERSION = '1.0.0-beta20'
5
5
  end
@@ -4,12 +4,16 @@ each_db_config(Deimos::Utils::DbProducer) do
4
4
  let(:producer) do
5
5
  producer = described_class.new
6
6
  allow(producer).to receive(:sleep)
7
- phobos_producer = instance_double(Phobos::Producer::PublicAPI)
8
- allow(phobos_producer).to receive(:publish_list)
9
7
  allow(producer).to receive(:producer).and_return(phobos_producer)
10
8
  producer
11
9
  end
12
10
 
11
+ let(:phobos_producer) do
12
+ pp = instance_double(Phobos::Producer::PublicAPI)
13
+ allow(pp).to receive(:publish_list)
14
+ pp
15
+ end
16
+
13
17
  before(:each) do
14
18
  stub_const('Deimos::Utils::DbProducer::BATCH_SIZE', 2)
15
19
  end
@@ -44,6 +48,49 @@ each_db_config(Deimos::Utils::DbProducer) do
44
48
  expect(messages).to all(be_a_kind_of(Deimos::KafkaMessage))
45
49
  end
46
50
 
51
+ describe '#produce_messages' do
52
+
53
+ it 'should produce normally' do
54
+ batch = ['A'] * 1000
55
+ expect(phobos_producer).to receive(:publish_list).with(batch).once
56
+ expect(Deimos.config.metrics).to receive(:increment).with('publish',
57
+ tags: %w(status:success topic:),
58
+ by: 1000).once
59
+ producer.produce_messages(batch)
60
+ end
61
+
62
+ it 'should split the batch size on buffer overflow' do
63
+ count = 0
64
+ allow(phobos_producer).to receive(:publish_list) do
65
+ count += 1
66
+ raise Kafka::BufferOverflow if count < 3
67
+ end
68
+ allow(Deimos.config.metrics).to receive(:increment)
69
+ batch = ['A'] * 1000
70
+ producer.produce_messages(batch)
71
+ expect(phobos_producer).to have_received(:publish_list).with(batch)
72
+ expect(phobos_producer).to have_received(:publish_list).with(['A'] * 100)
73
+ expect(phobos_producer).to have_received(:publish_list).with(['A'] * 10).exactly(100).times
74
+ expect(Deimos.config.metrics).to have_received(:increment).with('publish',
75
+ tags: %w(status:success topic:),
76
+ by: 10).exactly(100).times
77
+ end
78
+
79
+ it "should raise an error if it can't split any more" do
80
+ allow(phobos_producer).to receive(:publish_list) do
81
+ raise Kafka::BufferOverflow
82
+ end
83
+ expect(Deimos.config.metrics).not_to receive(:increment)
84
+ batch = ['A'] * 1000
85
+ expect { producer.produce_messages(batch) }.to raise_error(Kafka::BufferOverflow)
86
+ expect(phobos_producer).to have_received(:publish_list).with(batch)
87
+ expect(phobos_producer).to have_received(:publish_list).with(['A'] * 100).once
88
+ expect(phobos_producer).to have_received(:publish_list).with(['A'] * 10).once
89
+ expect(phobos_producer).to have_received(:publish_list).with(['A']).once
90
+
91
+ end
92
+ end
93
+
47
94
  describe '#process_topic' do
48
95
  before(:each) do
49
96
  producer.id = 'abc'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deimos-kafka
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre.beta19
4
+ version: 1.0.0.pre.beta20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Orner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-06 00:00:00.000000000 Z
11
+ date: 2019-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: avro-patches