Skip to content

Commit

Permalink
Update SidekiqRedis to work with Sidekiq 7
Browse files Browse the repository at this point in the history
This healthcheck has been failing for applications that have upgraded to Sidekiq 7.
Sidekiq 7 uses 'redis-client' which has a different API to 'redis'
which was used in Sidekiq 6.

To access redis_info you now have to call

```
Sidekiq.default_configration.redis_info
```

while in Sidekiq 6 you call

```
Sidekiq.redis_info
```

This updates the healthcheck to work with both versions of Sidekiq checking
if Sidekiq.responds to :redis_info.

If it does it calls that, otherwise it calls Sidekiq.default_configration.redis_info.

It's not missively clear these healthchecks are actually being used
for anything since this has been failing on production applications for
a couple of weeks without anyone noticing.

We're in the process of speaking to the platform team to see if they're
actually being used for anything and if not whether they should be removed.

But for now i'm just updating it to work with Sidekiq 7.
  • Loading branch information
davidgisbey committed Oct 8, 2024
1 parent b0dd13d commit a5bc90e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 17 deletions.
6 changes: 5 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,11 @@ def name
end

def status
Sidekiq.redis_info ? OK : CRITICAL
if Sidekiq.respond_to?(:redis_info)
Sidekiq.redis_info ? OK : CRITICAL
else
Sidekiq.default_configuration.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
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 the Sidekiq version is >= 7.0.0" 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 the Sidekiq version is < 7.0.0" 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 a5bc90e

Please sign in to comment.