Skip to content

Commit

Permalink
Revert "Custom backend"
Browse files Browse the repository at this point in the history
This reverts commit 1bda33d.
  • Loading branch information
shalvah committed Feb 26, 2023
1 parent 1bda33d commit 3551891
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 73 deletions.
4 changes: 1 addition & 3 deletions lib/honeybadger/backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
require 'honeybadger/backend/test'
require 'honeybadger/backend/null'
require 'honeybadger/backend/debug'
require 'honeybadger/backend/events'

module Honeybadger
# @api private
Expand All @@ -17,8 +16,7 @@ def self.mapping
server: Server,
test: Test,
null: Null,
debug: Debug,
events: Events,
debug: Debug
}.freeze
end

Expand Down
42 changes: 0 additions & 42 deletions lib/honeybadger/backend/events.rb

This file was deleted.

1 change: 1 addition & 0 deletions lib/honeybadger/backend/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Server < Base
ENDPOINTS = {
notices: '/v1/notices'.freeze,
deploys: '/v1/deploys'.freeze,
logs: '/v1/events'.freeze,
}.freeze

CHECK_IN_ENDPOINT = '/v1/check_in'.freeze
Expand Down
17 changes: 0 additions & 17 deletions lib/honeybadger/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,6 @@ def backend
@backend
end

def logs_backend
init_logs_backend! unless @logs_backend
@logs_backend
end

def backend=(backend)
set(:backend, backend)
@backend = nil
Expand Down Expand Up @@ -338,18 +333,6 @@ def init_backend!
@backend = default_backend
end

def init_logs_backend!
if self[:logs_backend].is_a?(String) || self[:logs_backend].is_a?(Symbol)
@logs_backend = Backend.for(self[:logs_backend].to_sym).new(self)
return
end

if ruby[:logs_backend].respond_to?(:notify)
@logs_backend = ruby[:logs_backend]
return
end
end

def build_stdout_logger
logger = ::Logger.new($stdout)
logger.formatter = lambda do |severity, datetime, progname, msg|
Expand Down
5 changes: 0 additions & 5 deletions lib/honeybadger/config/defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,6 @@ class Boolean; end
default: nil,
type: String
},
logs_backend: {
description: 'An alternate backend to use for the logger feature.',
default: :events,
type: String
},
debug: {
description: 'Enables debug logging.',
default: false,
Expand Down
6 changes: 3 additions & 3 deletions lib/honeybadger/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ class HttpAppender < SemanticLogger::Subscriber

def initialize(*)
super
@backend = Honeybadger.config.logs_backend
@retry_queue = []
end

Expand All @@ -86,7 +85,8 @@ def default_formatter

def batch(logs)
payload = logs.map { |log| formatter.call(log, self) }.join("\n")
response = @backend.notify(:logs, payload)
def payload.to_json; self; end # The Server backend calls to_json
response = Honeybadger.config.backend.notify(:logs, payload)

if response.success?
retry_previous_failed_requests
Expand All @@ -104,7 +104,7 @@ def retry_previous_failed_requests
can_send = true
until @retry_queue.empty? || !can_send
payload = @retry_queue.shift
response = @backend.notify(:logs, payload)
response = Honeybadger.config.backend.notify(:logs, payload)
if !response.success?
@retry_queue.unshift(payload)
can_send = false
Expand Down
9 changes: 6 additions & 3 deletions spec/unit/honeybadger/logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
before do
Honeybadger.logger.instance_variable_set(:@appender, nil)
Honeybadger::Backend::Test.notifications[:logs] = []
Honeybadger.config[:logs_backend] = :test
Honeybadger.config[:backend] = :test
end

after do
Expand Down Expand Up @@ -54,7 +54,10 @@ def wait_for_other_thread(wait = 0.05)
Honeybadger.config[:"features.logger.batch_size"] = 200
Honeybadger.config[:"features.logger.batch_interval"] = 0.001

expect(Honeybadger.config.logs_backend).to receive(:notify).twice do
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
# Four messages across three batches, with the first two batches failing
Expand All @@ -66,7 +69,7 @@ def wait_for_other_thread(wait = 0.05)

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

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

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

0 comments on commit 3551891

Please sign in to comment.