Skip to content

Commit

Permalink
Rename settings
Browse files Browse the repository at this point in the history
  • Loading branch information
shalvah committed Feb 22, 2023
1 parent 1cc9c2b commit bf59d10
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
8 changes: 4 additions & 4 deletions lib/honeybadger/config/defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -334,12 +334,12 @@ class Boolean; end
default: false,
type: Boolean
},
:'logger.batch_size' => {
description: 'Maximum number of logs to send in one batch.',
default: 20,
:'features.logger.batch_size' => {
description: 'Maximum number of logs to include in one batch.',
default: 300,
type: Integer
},
:'logger.batch_interval' => {
:'features.logger.batch_interval' => {
description: 'Send a log batch immediately if it has been this long (in seconds) since the last batch was sent.',
default: 5,
type: Integer
Expand Down
4 changes: 2 additions & 2 deletions lib/honeybadger/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def batch_appender
@batch_appender = ::SemanticLogger::Appender.factory(
appender: http_appender,
batch: true,
batch_size: ::Honeybadger.config[:'logger.batch_size'],
batch_seconds: ::Honeybadger.config[:'logger.batch_interval'],
batch_size: ::Honeybadger.config[:'features.logger.batch_size'],
batch_seconds: ::Honeybadger.config[:'features.logger.batch_interval'],
)
at_exit { shutdown! }
@batch_appender
Expand Down
36 changes: 20 additions & 16 deletions spec/unit/honeybadger/logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def wait_for_other_thread(wait = 0.05)
end

it 'waits until the batch is full before sending messages' do
Honeybadger.config[:"logger.batch_size"] = 2
Honeybadger.config[:"logger.batch_interval"] = 60
Honeybadger.config[:"features.logger.batch_size"] = 2
Honeybadger.config[:"features.logger.batch_interval"] = 60

wait_for_other_thread { Honeybadger.logger.info("A message", some: 'data') }
wait_for_other_thread { Honeybadger.logger.info("Another message", some: 'data') }
Expand All @@ -37,43 +37,47 @@ def wait_for_other_thread(wait = 0.05)
end

it 'sends a batch which is not full if the batch timeout is reached' do
Honeybadger.config[:"logger.batch_size"] = 200
Honeybadger.config[:"logger.batch_interval"] = 0.001
Honeybadger.config[:"features.logger.batch_size"] = 200
Honeybadger.config[:"features.logger.batch_interval"] = 0.001

wait_for_other_thread { Honeybadger.logger.warn("A message", some: 'data') }
wait_for_other_thread { Honeybadger.logger.info("Another message", some: 'data') }

expect(received_batches.size).to eq(2)

logs = received_batches.first.split("\n").map { |log| JSON[log] }
expect(logs.size).to eq(1)
expect(logs[0]["message"]).to eq("A message")
expect(logs[0]["level"]).to eq("warn")
expect(logs[0]["payload"]).to eq({"some" => "data"})
batch_1, batch_2 = received_batches
expect(JSON[batch_1]["message"]).to eq("A message")
expect(JSON[batch_2]["message"]).to eq("Another message")
end

it 'retries a failed batch when another batch succeeds' do
Honeybadger.config[:"logger.batch_size"] = 200
Honeybadger.config[:"logger.batch_interval"] = 0.001
Honeybadger.config[:"features.logger.batch_size"] = 200
Honeybadger.config[:"features.logger.batch_interval"] = 0.001

backend = Honeybadger::Backend::Test.new(Honeybadger.config)
Honeybadger.config[:backend] = backend

expect(backend).to receive(:notify).twice do
Honeybadger::Backend::Null::StubbedResponse.new(successful: false)
end
wait_for_other_thread { Honeybadger.logger.debug("First - fails") }
wait_for_other_thread { Honeybadger.logger.debug("Second - fails") }
# Four messages across three batches, with the first two batches failing
wait_for_other_thread do
Honeybadger.logger.debug("First - fails")
Honeybadger.logger.debug("Second - fails")
end
wait_for_other_thread { Honeybadger.logger.debug("Third - fails") }

expect(received_batches.size).to eq(0)

expect(backend).to receive(:notify).exactly(3).times.and_call_original
wait_for_other_thread { Honeybadger.logger.error("Third - succeeds") }
wait_for_other_thread { Honeybadger.logger.error("Fourth - succeeds") }

expect(received_batches.size).to eq(3)

logs = received_batches.flat_map { |batch| batch.split("\n").map { |log| JSON[log] } }
expect(logs.size).to eq(3)
expect(logs.map { |l| l["message"] }).to eq(["Third - succeeds", "First - fails", "Second - fails"])
expect(logs.size).to eq(4)
expect(logs.map { |l| l["message"] }).to eq(
["Fourth - succeeds", "First - fails", "Second - fails", "Third - fails"]
)
end
end

0 comments on commit bf59d10

Please sign in to comment.