-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #161 from alphagov/new-healthchecks
Add a couple of new healthchecks
- Loading branch information
Showing
10 changed files
with
122 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module GovukHealthcheck | ||
class Mongoid | ||
def name | ||
:database_connectivity | ||
end | ||
|
||
def status | ||
::Mongoid.default_client.database_names.any? | ||
GovukHealthcheck::OK | ||
rescue StandardError | ||
GovukHealthcheck::CRITICAL | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module GovukHealthcheck | ||
class RailsCache | ||
def name | ||
:rails_cache | ||
end | ||
|
||
def status | ||
::Rails.cache.write("healthcheck-cache", true) | ||
raise unless ::Rails.cache.read("healthcheck-cache") | ||
|
||
GovukHealthcheck::OK | ||
rescue StandardError | ||
GovukHealthcheck::CRITICAL | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module GovukAppConfig | ||
VERSION = "2.3.0".freeze | ||
VERSION = "2.4.0".freeze | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require "spec_helper" | ||
require "govuk_app_config/govuk_healthcheck" | ||
require_relative "shared_interface" | ||
|
||
RSpec.describe GovukHealthcheck::Mongoid do | ||
let(:client) { double(:client, database_names: %w[db]) } | ||
let(:mongoid) { double(:mongoid, default_client: client) } | ||
before { stub_const("Mongoid", mongoid) } | ||
|
||
describe ".status" do | ||
context "when 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 | ||
before do | ||
allow(client).to receive(:database_names) { raise } | ||
end | ||
|
||
it_behaves_like "a healthcheck" | ||
|
||
it "returns CRITICAL" do | ||
expect(subject.status).to eq(GovukHealthcheck::CRITICAL) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require "spec_helper" | ||
require "govuk_app_config/govuk_healthcheck" | ||
require_relative "shared_interface" | ||
|
||
RSpec.describe GovukHealthcheck::RailsCache do | ||
let(:cache) { double(:cache, write: true, read: true) } | ||
let(:rails) { double(:mongoid, cache: cache) } | ||
before { stub_const("Rails", rails) } | ||
|
||
describe ".status" do | ||
context "when the cache is available" do | ||
it_behaves_like "a healthcheck" | ||
|
||
it "returns OK" do | ||
expect(subject.status).to eq(GovukHealthcheck::OK) | ||
end | ||
end | ||
|
||
context "when the cache is silently unavailable" do | ||
before do | ||
allow(cache).to receive(:read) { false } | ||
end | ||
|
||
it_behaves_like "a healthcheck" | ||
|
||
it "returns CRITICAL" do | ||
expect(subject.status).to eq(GovukHealthcheck::CRITICAL) | ||
end | ||
end | ||
|
||
context "when the cache is loudly unavailable" do | ||
before do | ||
allow(cache).to receive(:read) { raise } | ||
end | ||
|
||
it_behaves_like "a healthcheck" | ||
|
||
it "returns CRITICAL" do | ||
expect(subject.status).to eq(GovukHealthcheck::CRITICAL) | ||
end | ||
end | ||
end | ||
end |