Skip to content

Commit

Permalink
Merge pull request #399 from alphagov/update-sidekiq-redis-to-work-wi…
Browse files Browse the repository at this point in the history
…th-sidekiq-7

Update SidekiqRedis healthcheck to work with Sidekiq 7
  • Loading branch information
davidgisbey authored Oct 8, 2024
2 parents b0dd13d + d6f52f6 commit 1b0b459
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 9.14.3

* Update SidekiqRedis healthcheck to work with Sidekiq 7 [#399](https://github.com/alphagov/govuk_app_config/pull/399)

# 9.14.2

* Update dependencies
Expand Down
9 changes: 8 additions & 1 deletion lib/govuk_app_config/govuk_healthcheck/sidekiq_redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ def name
end

def status
Sidekiq.redis_info ? OK : CRITICAL
# Sidekiq 7 introduced a default_configuration object which has .redis_info
# for querying Redis information. If the default_configuration object isn't present,
# we can fall back to the old method of querying it using 'Sidekiq.redis_info'.
if Sidekiq.respond_to?(:default_configuration)
Sidekiq.default_configuration.redis_info ? OK : CRITICAL
else
Sidekiq.redis_info ? OK : CRITICAL
end
rescue StandardError
# One would expect a Redis::BaseConnectionError, but this should be
# critical if any exception is raised when making a call to redis.
Expand Down
2 changes: 1 addition & 1 deletion lib/govuk_app_config/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module GovukAppConfig
VERSION = "9.14.2".freeze
VERSION = "9.14.3".freeze
end
65 changes: 49 additions & 16 deletions spec/lib/govuk_healthcheck/sidekiq_redis_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,68 @@
require_relative "shared_interface"

RSpec.describe GovukHealthcheck::SidekiqRedis do
let(:redis_info) { double(:redis_info) }
let(:sidekiq) { double(:sidekiq, redis_info:) }
before { stub_const("Sidekiq", sidekiq) }

context "when the database is connected" do
context "when Sidekiq responds to '.default_configuration'" do
let(:redis_info) { double(:redis_info) }
let(:default_configuration) { double(:default_configuration, redis_info:) }
let(:sidekiq) { double(:sidekiq, default_configuration:) }

it_behaves_like "a healthcheck"
context "and the database is connected" do
it_behaves_like "a healthcheck"

it "returns OK" do
expect(subject.status).to eq(GovukHealthcheck::OK)
it "returns OK" do
expect(subject.status).to eq(GovukHealthcheck::OK)
end
end
end

context "when the database is not connected" do
let(:redis_info) { nil }
context "when the database is not connected" do
let(:redis_info) { nil }

it_behaves_like "a healthcheck"

it "returns CRITICAL" do
expect(subject.status).to eq(GovukHealthcheck::CRITICAL)
end
end

it_behaves_like "a healthcheck"
context "and redis raises a connection error" do
it "returns CRITICAL" do
allow(default_configuration).to receive(:redis_info).and_raise StandardError

it "returns CRITICAL" do
expect(subject.status).to eq(GovukHealthcheck::CRITICAL)
expect(subject.status).to eq(GovukHealthcheck::CRITICAL)
end
end
end

context "when redis raises a connection error" do
it "returns CRITICAL" do
allow(sidekiq).to receive(:redis_info).and_raise StandardError
context "when Sidekiq doesn't respond to '.default_configuration'" do
let(:redis_info) { double(:redis_info) }
let(:sidekiq) { double(:sidekiq, redis_info:) }

context "and the database is connected" do
it_behaves_like "a healthcheck"

it "returns OK" do
expect(subject.status).to eq(GovukHealthcheck::OK)
end
end

context "when the database is not connected" do
let(:redis_info) { nil }

it_behaves_like "a healthcheck"

it "returns CRITICAL" do
expect(subject.status).to eq(GovukHealthcheck::CRITICAL)
end
end

context "and redis raises a connection error" do
it "returns CRITICAL" do
allow(sidekiq).to receive(:redis_info).and_raise StandardError

expect(subject.status).to eq(GovukHealthcheck::CRITICAL)
expect(subject.status).to eq(GovukHealthcheck::CRITICAL)
end
end
end
end

0 comments on commit 1b0b459

Please sign in to comment.