-
Notifications
You must be signed in to change notification settings - Fork 0
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 #86 from psu-libraries/healthchecks
version and solr checks
- Loading branch information
Showing
11 changed files
with
153 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
OkComputer.mount_at = false | ||
|
||
OkComputer::Registry.register( | ||
'version', | ||
HealthChecks::VersionCheck.new | ||
) | ||
|
||
OkComputer::Registry.register( | ||
'solr', | ||
HealthChecks::SolrCheck.new | ||
) | ||
|
||
OkComputer.make_optional %w(version) |
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,6 @@ | ||
# frozen_string_literal: true | ||
|
||
module Healthchecks | ||
require 'healthchecks/version_check' | ||
require 'healthchecks/solr_check' | ||
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,18 @@ | ||
# frozen_string_literal: true | ||
|
||
module HealthChecks | ||
class SolrCheck < OkComputer::Check | ||
def check | ||
solr = RSolr.connect(url: Rails.configuration.solr.query_url) | ||
resp = solr.get('admin/ping') | ||
status = resp&.dig('status') | ||
zk_connected = resp&.dig('responseHeader')&.dig('zkConnected') | ||
@message = Hash.new | ||
@message['zkConnected'] = zk_connected | ||
@message['status'] = status | ||
mark_message(@message) | ||
mark_failure unless status == 'OK' | ||
mark_failure unless zk_connected == true | ||
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,10 @@ | ||
# frozen_string_literal: true | ||
|
||
module HealthChecks | ||
class VersionCheck < OkComputer::Check | ||
def check | ||
version = ENV.fetch('APP_VERSION', 'unknown') | ||
mark_message version.to_s | ||
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,51 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe HealthChecks::SolrCheck do | ||
describe '#check' do | ||
before(:all) do | ||
WebMock.disable_net_connect! | ||
end | ||
|
||
after(:all) do | ||
WebMock.enable_net_connect! | ||
end | ||
|
||
context 'when we can connect to solr' do | ||
before do | ||
stub_request(:get, /admin\/ping/) | ||
.to_return(status: 200, body: { | ||
responseHeader: { | ||
zkConnected: true | ||
}, | ||
status: 'OK' | ||
}.to_json) | ||
end | ||
|
||
it 'returns no failure' do | ||
hc = described_class.new | ||
hc.check | ||
expect(hc.failure_occurred).to be_nil | ||
end | ||
end | ||
|
||
context 'when zk is not connected' do | ||
before do | ||
stub_request(:get, /admin\/ping/) | ||
.to_return(status: 200, body: { | ||
responseHeader: { | ||
zkConnected: false | ||
}, | ||
status: 'OK' | ||
}.to_json) | ||
end | ||
|
||
it 'returns a failure' do | ||
hc = described_class.new | ||
hc.check | ||
expect(hc.failure_occurred).to be true | ||
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,37 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe HealthChecks::VersionCheck do | ||
describe '#check' do | ||
context 'when version' do | ||
before do | ||
ENV['APP_VERSION'] = '3' | ||
end | ||
|
||
it 'returns no failure' do | ||
hc = described_class.new | ||
hc.check | ||
expect(hc.failure_occurred).to be_nil | ||
end | ||
|
||
it 'writes a message' do | ||
hc = described_class.new | ||
hc.check | ||
expect(hc.message).to eq('3') | ||
end | ||
end | ||
|
||
context 'when no version' do | ||
before do | ||
ENV['APP_VERSION'] = nil | ||
end | ||
|
||
it 'writes unknown' do | ||
hc = described_class.new | ||
hc.check | ||
expect(hc.message).to eq('unknown') | ||
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