-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add solr monitor #121
Merged
Merged
Add solr monitor #121
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,5 +24,6 @@ gem 'sidekiq', '>= 3.0' | |
gem 'spork' | ||
gem 'sqlite3', '~> 1.3' | ||
gem 'timecop' | ||
gem 'webmock' | ||
|
||
gemspec |
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 |
---|---|---|
|
@@ -176,6 +176,7 @@ The following services are currently supported: | |
* Sidekiq | ||
* Resque | ||
* Delayed Job | ||
* Solr | ||
|
||
## Configuration | ||
|
||
|
@@ -312,6 +313,10 @@ Please note that `url` or `connection` can't be used at the same time. | |
|
||
* `queue_size`: the size (maximum) of a queue which is considered unhealthy (the default is 100). | ||
|
||
### Solr | ||
|
||
* `url`: the URL used to connect to your Solr instance - must be a string. You can also use `url` to explicitly configure authentication (e.g., `'https://user:[email protected]:8983/'`) | ||
|
||
### Adding a Custom Provider | ||
|
||
It's also possible to add custom health check providers suited for your needs (of course, it's highly appreciated and encouraged if you'd contribute useful providers to the project). | ||
|
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 |
---|---|---|
|
@@ -27,5 +27,6 @@ gem 'sidekiq', '>= 3.0' | |
gem 'spork' | ||
gem 'sqlite3', '~> 1.3' | ||
gem 'timecop' | ||
gem 'webmock' | ||
|
||
gemspec path: '../' |
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 |
---|---|---|
|
@@ -27,5 +27,6 @@ gem 'sidekiq', '>= 3.0' | |
gem 'spork' | ||
gem 'sqlite3', '~> 1.3' | ||
gem 'timecop' | ||
gem 'webmock' | ||
|
||
gemspec path: '../' |
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,60 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'health_monitor/providers/base' | ||
|
||
module HealthMonitor | ||
module Providers | ||
class SolrException < StandardError; end | ||
|
||
class Solr < Base | ||
class Configuration < Base::Configuration | ||
DEFAULT_URL = nil | ||
attr_accessor :url | ||
|
||
def initialize(provider) | ||
super(provider) | ||
|
||
@url = DEFAULT_URL | ||
end | ||
end | ||
|
||
def check! | ||
check_solr_connection! | ||
rescue Exception => e | ||
raise SolrException.new(e.message) | ||
end | ||
|
||
private | ||
|
||
def configuration_class | ||
::HealthMonitor::Providers::Solr::Configuration | ||
end | ||
|
||
def check_solr_connection! | ||
json = JSON.parse(solr_response.body) | ||
raise "The solr has an invalid status #{status_uri}" if json['responseHeader']['status'] != 0 | ||
end | ||
|
||
def status_uri | ||
@status_uri ||= begin | ||
uri = URI(configuration.url) | ||
uri.path = '/solr/admin/cores' | ||
uri.query = 'action=STATUS' | ||
uri | ||
end | ||
end | ||
|
||
def solr_request | ||
@solr_request ||= begin | ||
req = Net::HTTP::Get.new(status_uri) | ||
req.basic_auth(status_uri.user, status_uri.password) if status_uri.user && status_uri.password | ||
req | ||
end | ||
end | ||
|
||
def solr_response | ||
Net::HTTP.start(status_uri.hostname, status_uri.port) { |http| http.request(solr_request) } | ||
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,121 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe HealthMonitor::Providers::Solr do | ||
subject { described_class.new } | ||
|
||
context 'with defaults' do | ||
it { expect(subject.configuration.name).to eq('Solr') } | ||
it { expect(subject.configuration.url).to eq(HealthMonitor::Providers::Solr::Configuration::DEFAULT_URL) } | ||
end | ||
|
||
describe '#name' do | ||
it { expect(subject.name).to eq('Solr') } | ||
end | ||
|
||
describe '#check!' do | ||
let(:solr_url_config) { 'http://www.example-solr.com:8983' } | ||
|
||
before do | ||
subject.request = test_request | ||
subject.configure do |config| | ||
config.url = solr_url_config | ||
end | ||
Providers.stub_solr | ||
end | ||
|
||
context 'with a standard connection' do | ||
it 'checks against the configured solr url' do | ||
subject.check! | ||
expect(Providers.stub_solr).to have_been_requested | ||
end | ||
|
||
it 'succesfully checks' do | ||
expect { | ||
subject.check! | ||
}.not_to raise_error | ||
end | ||
|
||
context 'when failing' do | ||
before do | ||
Providers.stub_solr_failure | ||
end | ||
|
||
it 'fails check!' do | ||
expect { | ||
subject.check! | ||
}.to raise_error(HealthMonitor::Providers::SolrException) | ||
end | ||
|
||
it 'checks against the configured solr url' do | ||
expect { | ||
subject.check! | ||
}.to raise_error(HealthMonitor::Providers::SolrException) | ||
expect(Providers.stub_solr_failure).to have_been_requested | ||
end | ||
end | ||
end | ||
|
||
context 'with a configured url that includes a path' do | ||
let(:solr_url_config) { 'http://www.example-solr.com:8983/solr/blacklight-core-development' } | ||
|
||
it 'checks against the configured solr url' do | ||
subject.check! | ||
expect(Providers.stub_solr).to have_been_requested | ||
end | ||
end | ||
|
||
context 'with a connection with authentication' do | ||
let(:solr_url_config) { 'http://solr:SolrRocks@localhost:8888' } | ||
|
||
before { Providers.stub_solr_with_auth } | ||
|
||
it 'checks against the configured solr url' do | ||
subject.check! | ||
expect(Providers.stub_solr_with_auth).to have_been_requested | ||
end | ||
|
||
it 'succesfully checks' do | ||
expect { | ||
subject.check! | ||
}.not_to raise_error | ||
end | ||
|
||
context 'when failing' do | ||
before do | ||
Providers.stub_solr_failure_with_auth | ||
end | ||
|
||
it 'fails check!' do | ||
expect { | ||
subject.check! | ||
}.to raise_error(HealthMonitor::Providers::SolrException) | ||
end | ||
|
||
it 'checks against the configured solr url' do | ||
expect { | ||
subject.check! | ||
}.to raise_error(HealthMonitor::Providers::SolrException) | ||
expect(Providers.stub_solr_failure_with_auth).to have_been_requested | ||
end | ||
end | ||
end | ||
end | ||
|
||
describe '#configure' do | ||
before do | ||
subject.configure | ||
end | ||
|
||
let(:url) { 'solr://user:[email protected]:8983/' } | ||
|
||
it 'url can be configured' do | ||
expect { | ||
subject.configure do |config| | ||
config.url = url | ||
end | ||
}.to change { subject.configuration.url }.to(url) | ||
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you update the example to
https
? 😅There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!