Skip to content

Commit

Permalink
Reports are now indexed by its name and return data
Browse files Browse the repository at this point in the history
  • Loading branch information
vinibaggio committed Jun 27, 2011
1 parent f3d24ec commit 926ecd3
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 14 deletions.
20 changes: 8 additions & 12 deletions lib/outpost/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def name(val=nil)
# Returns the status of the last service check or nil if it didn't happen.
attr_reader :last_status

# Returns a list of {Report} containing the last r])ults of the last check.
# Returns a list of {Report} containing the last results of the last check.
attr_reader :reports

# Returns all the registered scouts.
Expand All @@ -93,7 +93,7 @@ def name(val=nil)

# New instance of a Outpost-based class.
def initialize
@reports = []
@reports = {}
@last_status = nil
@scouts = Hash.new { |h, k| h[k] = {} }
@notifiers = {}
Expand Down Expand Up @@ -128,11 +128,11 @@ def add_notifier(notifier_name, options)
# Execute all the scouts associated with an Outpost-based class and returns
# either :up or :down, depending on the results.
def run
@reports = scouts.map do |scout, options|
run_scout(scout, options)
scouts.map do |scout, options|
@reports[options[:description]] = run_scout(scout, options)
end

statuses = @reports.map { |r| r.status }
statuses = @reports.map { |_, r| r.status }

@last_status = Report.summarize(statuses)
end
Expand Down Expand Up @@ -163,16 +163,11 @@ def down?
@last_status == :down
end

# Returns the name of an Outpost-based class or the class name itself if
# not set.
#
# @return [String] The name of the Outpost

# Returns the messages of the latest service check.
#
# @return [Array<String>] An array containing all report messages.
def messages
reports.map { |r| r.to_s }
reports.map { |_, r| r.to_s }
end

private
Expand All @@ -184,7 +179,8 @@ def run_scout(scout, options)
params = {
:name => scout.name,
:description => options[:description],
:status => scout_instance.run
:status => scout_instance.run,
:data => scout_instance.report_data
}
Report.new(params)
end
Expand Down
3 changes: 2 additions & 1 deletion lib/outpost/report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ def self.summarize(status_list)
return :up
end

attr_reader :name, :description, :status
attr_reader :name, :description, :status, :data

def initialize(params)
@name = params[:name]
@description = params[:description]
@status = params[:status]
@data = params[:data]
end

def to_s
Expand Down
39 changes: 39 additions & 0 deletions test/integration/reporting_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
require 'test_helper'

require 'outpost/scouts'

describe "using only report data integration test" do
class RetrieveServerData < Outpost::Application
using Outpost::Scouts::Http => 'master http server' do
options :host => 'localhost', :port => 9595, :path => '/'
end

using Outpost::Scouts::Ping => :load_balancer do
options :host => 'localhost'
report :up, :response_time => {:less_than => 500}
end
end

before(:each) do
@server = Server.new
@server.boot(TestApp)
@server.wait_until_booted

@outpost = RetrieveServerData.new
@outpost.run
end

it "should build report for each scout" do
assert_equal 2, @outpost.reports.size
end

it "should build reports with data" do
http_report = @outpost.reports['master http server']
ping_report = @outpost.reports[:load_balancer]

assert_equal({:response_code => 200,
:response_body => 'Up and running!'}, http_report.data)

assert ping_report.data[:response_time] < 500
end
end
7 changes: 6 additions & 1 deletion test/outpost/application_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ class ScoutMock
class << self
attr_accessor :status
end

def initialize(*args); end
def run ; self.class.status ; end
def report_data; ; {} ; end
end

class NotifierMock
Expand Down Expand Up @@ -78,7 +80,6 @@ class ExampleOne < Outpost::Application
end
end


describe "#run" do
it "should return up when scouts return up" do
ScoutMock.status = :up
Expand Down Expand Up @@ -204,6 +205,10 @@ class ExampleOne < Outpost::Application
end
end

describe "#reports" do

end

private

def create_outpost
Expand Down

0 comments on commit 926ecd3

Please sign in to comment.