Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Commit

Permalink
Merge "Add mongodb service healthz" into devel
Browse files Browse the repository at this point in the history
  • Loading branch information
rtang authored and Gerrit Code Review committed Jul 5, 2011
2 parents 6d2a38f + 616ca02 commit 559aec7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
20 changes: 20 additions & 0 deletions mongodb/lib/mongodb_service/mongodb_node.rb
Expand Up @@ -423,6 +423,26 @@ def varz_details
}
end

def healthz_details
healthz = {}
healthz[:self] = "ok"
ProvisionedService.all.each do |instance|
healthz[instance.name.to_sym] = get_healthz(instance)
end
healthz
rescue => e
@logger.warn("Error get healthz details: #{e}")
{:self => "fail"}
end

def get_healthz(instance)
conn = Mongo::Connection.new(@local_ip, instance.port).db(instance.db)
auth = conn.authenticate(instance.admin, instance.adminpass)
auth ? "ok" : "fail"
rescue => e
"fail"
end

def start_instance(provisioned_service)
@logger.debug("Starting: #{provisioned_service.pretty_inspect}")

Expand Down
10 changes: 10 additions & 0 deletions mongodb/spec/mongodb_provision_spec.rb
Expand Up @@ -64,6 +64,16 @@
end
end

it "should return healthz" do
EM.run do
stats = @node.healthz_details
stats.should_not be_nil
stats[:self].should == "ok"
stats[@resp['name'].to_sym].should == "ok"
EM.stop
end
end

it "should allow authorized user to access the instance" do
EM.run do
conn = Mongo::Connection.new('localhost', @resp['port']).db(@resp['db'])
Expand Down

0 comments on commit 559aec7

Please sign in to comment.