Skip to content

Commit

Permalink
Disable Airbrake remote_config (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulDoyle-DEFRA committed Apr 14, 2023
1 parent e650a2d commit f7ece62
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 55 deletions.
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
inherit_gem:
defra_ruby_style:
- default.yml
require:
- rubocop-rails
- rubocop-rake
- rubocop-rspec
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ruby-2.7.1
ruby-3.1.2
23 changes: 23 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,26 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }

# Specify your gem's dependencies in defra_ruby_validators.gemspec
gemspec

group :development, :test do
gem "defra_ruby_style"
# Shim to load environment variables from a .env file into ENV
gem "dotenv"
# Allows us to automatically generate the change log from the tags, issues,
# labels and pull requests on GitHub. Added as a dependency so all dev's have
# access to it to generate a log, and so they are using the same version.
# New dev's should first create GitHub personal app token and add it to their
# ~/.bash_profile (or equivalent)
# https://github.com/github-changelog-generator/github-changelog-generator#github-token
gem "github_changelog_generator"
# Adds step-by-step debugging and stack navigation capabilities to pry using byebug
gem "pry-byebug"
gem "rake"
gem "rspec", "~> 3.0"
gem "rubocop"
gem "rubocop-rails"
gem "rubocop-rake"
gem "rubocop-rspec"
gem "simplecov", "~> 0.17.1"
gem "webmock", "~> 3.4"
end
34 changes: 6 additions & 28 deletions defra_ruby_alert.gemspec
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# rubocop:disable Gemspec/RequiredRubyVersion
# frozen_string_literal: true

$LOAD_PATH.push File.expand_path("lib", __dir__)
Expand All @@ -15,41 +14,20 @@ Gem::Specification.new do |spec|
spec.homepage = "https://github.com/DEFRA/defra-ruby-alert"
spec.summary = "Defra ruby on rails Alert gem"
spec.description = "Provides a single source of functionality for initialising and managing Alert in our apps."
spec.required_ruby_version = ">= 3.1"

spec.files = Dir["{bin,config,lib}/**/*", "LICENSE", "Rakefile", "README.md"]
spec.test_files = Dir["spec/**/*"]

spec.require_paths = ["lib"]

# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
# to allow pushing to a single host or delete this section to allow pushing to any host.
if spec.respond_to?(:metadata)
spec.metadata["allowed_push_host"] = "https://rubygems.org"
else
raise "RubyGems 2.0 or newer is required to protect against " \
"public gem pushes."
end
raise "RubyGems 2.0 or newer is required to protect against public gem pushes." unless spec.respond_to?(:metadata)

spec.metadata["allowed_push_host"] = "https://rubygems.org"

spec.metadata["rubygems_mfa_required"] = "true"

# Alert catches exceptions, sends them to our Errbit instances
spec.add_dependency "airbrake"

spec.add_development_dependency "defra_ruby_style"
# Shim to load environment variables from a .env file into ENV
spec.add_development_dependency "dotenv"
# Allows us to automatically generate the change log from the tags, issues,
# labels and pull requests on GitHub. Added as a dependency so all dev's have
# access to it to generate a log, and so they are using the same version.
# New dev's should first create GitHub personal app token and add it to their
# ~/.bash_profile (or equivalent)
# https://github.com/github-changelog-generator/github-changelog-generator#github-token
spec.add_development_dependency "github_changelog_generator"
# Adds step-by-step debugging and stack navigation capabilities to pry using
# byebug
spec.add_development_dependency "pry-byebug"
spec.add_development_dependency "rake"
spec.add_development_dependency "rspec", "~> 3.0"
spec.add_development_dependency "rubocop"
spec.add_development_dependency "simplecov", "~> 0.17.1"
spec.add_development_dependency "webmock", "~> 3.4"
end
# rubocop:enable Gemspec/RequiredRubyVersion
4 changes: 4 additions & 0 deletions lib/defra_ruby/alert/airbrake_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ def self.invoke
# errors in our logs. To prevent this we disable this feature.
# https://github.com/airbrake/airbrake-ruby#performance_stats
c.performance_stats = false

# Prevent Airbrake from trying to auto-load remote config from Airbrake servers
# as this fails (our projects are not on Airbrake) and disables Airbrake in the app
c.remote_config = false
end
end
end
Expand Down
29 changes: 20 additions & 9 deletions spec/defra_ruby/alert/airbrake_runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,43 +21,54 @@ module Alert
:environment= => nil,
:ignore_environments= => nil,
:blocklist_keys= => nil,
:performance_stats= => nil
:performance_stats= => nil,
:remote_config= => nil
)
allow(configuration).to receive(:performance_stats)

allow(Airbrake).to receive(:configure).and_yield(configuration)
end

let(:configuration) { double("Configuration") }
let(:configuration) { instance_double("Configuration") } # rubocop:disable RSpec/VerifiedDoubleReference

let(:enabled) { true }
let(:host) { "http://localhost:8005" }
let(:project_key) { "ABC123456789" }

describe ".invoke" do
it "configures Airbrake" do
expect(configuration).to receive(:host=).with(host)
expect(configuration).to receive(:project_key=).with(project_key)
before { allow(Airbrake).to receive(:add_filter) }

it "configures Airbrake with host" do
described_class.invoke

expect(configuration).to have_received(:host=).with(host)
end

it "configures Airbrake with project_key" do
described_class.invoke

expect(configuration).to have_received(:project_key=).with(project_key)
end

context "when airbrake is enabled" do
it "does not tell Airbrake to ignore everything" do
expect(Airbrake).not_to receive(:add_filter)

described_class.invoke

expect(Airbrake).not_to have_received(:add_filter)
end
end

context "when airbrake is not enabled" do
let(:enabled) { false }

# rubocop:disable RSpec/MultipleExpectations
it "tells Airbrake to ignore everything" do
expect(Airbrake).to receive(:add_filter) { |&block| expect(block).to be(&:ignore!) }

described_class.invoke

expect(Airbrake).to have_received(:add_filter) { |&block| expect(block).to be(&:ignore!) }
end
# rubocop:enable RSpec/MultipleExpectations

end
end

Expand Down
18 changes: 8 additions & 10 deletions spec/defra_ruby/alert/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@
module DefraRuby
module Alert
RSpec.describe Configuration do
it "sets the appropriate default config settings" do
fresh_config = described_class.new

expect(fresh_config.root_directory).to be_nil
expect(fresh_config.logger).to be_nil
expect(fresh_config.environment).to be_nil
subject(:fresh_config) { described_class.new }

expect(fresh_config.host).to be_nil
expect(fresh_config.project_key).to be_nil
expect(fresh_config.blocklist).to eq([])
expect(fresh_config.enabled).to eq(false)
end
it { expect(fresh_config.root_directory).to be_nil }
it { expect(fresh_config.logger).to be_nil }
it { expect(fresh_config.environment).to be_nil }
it { expect(fresh_config.host).to be_nil }
it { expect(fresh_config.project_key).to be_nil }
it { expect(fresh_config.blocklist).to eq([]) }
it { expect(fresh_config.enabled).to be(false) }
end
end
end
15 changes: 8 additions & 7 deletions spec/defra_ruby/alert_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

RSpec.describe DefraRuby::Alert do
describe "VERSION" do
it "is a version string in the correct format" do
expect(DefraRuby::Alert::VERSION).to be_a(String)
expect(DefraRuby::Alert::VERSION).to match(/\d+\.\d+\.\d+/)
end
it { expect(DefraRuby::Alert::VERSION).to be_a(String) }
it { expect(DefraRuby::Alert::VERSION).to match(/\d+\.\d+\.\d+/) }
end

describe ".configuration" do
Expand All @@ -30,16 +28,19 @@

describe ".start" do
before do
DefraRuby::Alert.configure do |c|
allow(DefraRuby::Alert::AirbrakeRunner).to receive(:invoke)

described_class.configure do |c|
c.enabled = false
c.host = "http://localhost:8005"
c.project_key = "ABC123456789"
end
end
it "invokes 'AirbrakeRunner'" do
expect(DefraRuby::Alert::AirbrakeRunner).to receive(:invoke)

it "invokes 'AirbrakeRunner'" do
described_class.start

expect(DefraRuby::Alert::AirbrakeRunner).to have_received(:invoke)
end
end
end

0 comments on commit f7ece62

Please sign in to comment.