-
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 #205 from pulibrary/i176-jrgriffiniii-health-endpoint
Integrates a health endpoint which ensures that Solr availability can be determined by HTTP request
- Loading branch information
Showing
8 changed files
with
100 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
Rails.application.config.after_initialize do | ||
HealthMonitor.configure do |config| | ||
config.cache | ||
|
||
config.solr.configure do |c| | ||
url = Sunspot.config.solr.url | ||
uri = URI(url) | ||
status_uri = URI("#{uri.scheme}://#{uri.hostname}:#{uri.port}/solr/admin/cores?action=STATUS") | ||
|
||
c.url = status_uri.to_s | ||
end | ||
|
||
config.path = :health | ||
|
||
config.error_callback = proc do |e| | ||
Rails.logger.error "Health check failed with: #{e.message}" | ||
Honeybadger.notify(e) | ||
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# frozen_string_literal: true | ||
require "rails_helper" | ||
|
||
RSpec.describe "Health Check", type: :request do | ||
describe "GET /health" do | ||
context "when the service is up" do | ||
before do | ||
url = Sunspot.config.solr.url | ||
uri = URI(url) | ||
|
||
response_body = { | ||
responseHeader: { status: 0 } | ||
} | ||
stub_request(:get, "#{uri.scheme}://#{uri.hostname}:#{uri.port}/solr/admin/cores?action=STATUS").to_return(status: 200, body: response_body.to_json) | ||
end | ||
|
||
it "has a health check" do | ||
get "/health.json" | ||
|
||
expect(response).to be_successful | ||
end | ||
end | ||
|
||
context "when the service is down" do | ||
before do | ||
url = Sunspot.config.solr.url | ||
uri = URI(url) | ||
|
||
response_body = { | ||
responseHeader: { status: 500 } | ||
} | ||
stub_request(:get, "#{uri.scheme}://#{uri.hostname}:#{uri.port}/solr/admin/cores?action=STATUS").to_return(status: 200, body: response_body.to_json) | ||
end | ||
|
||
it "errors when a service is down" do | ||
get "/health.json" | ||
|
||
expect(response).not_to be_successful | ||
expect(response.status).to eq 503 | ||
json_response = JSON.parse(response.body) | ||
results = json_response["results"] | ||
solr_response = results.find { |x| x["name"] == "Solr" } | ||
expect(solr_response["message"]).to start_with "The solr has an invalid status" | ||
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
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