Closed Rucknar closed 10 years ago
This is a very interesting idea, although I'm not sure there is a better way than parsing the ci_reports output. I would imagine this cookbook would want to avoid a dependency on any graphite cookbooks or handlers, so the cleanest approach to me would be a new handler that would parse the data and push it into graphite (or any other metrics endpoint that might make sense)
I'll see if i can rustle something up using the ci_reports and upload.
Okay, we have this working now, i won't submit a pull request as our cookbook is specific to our environment. What we added is below if you wish to incorporate it, it will silently fail if the ci_reports don't exist.
def minitest testdirpath = "#{node['minitest']['ci_reports']}" testresults = Hash.new testresults[:minitest_tests] = 0 testresults[:minitest_assertions] = 0 testresults[:minitest_failures] = 0 testresults[:minitest_errors] = 0 testresults[:minitest_skipped] = 0
return if !(File.directory? testdirpath)
Dir.glob("#{testdirpath}/TEST*[^0-9].xml") do |xmlfile|
file = File.new xmlfile
doc = REXML::Document.new file
root = doc.root
testresults[:minitest_tests] += root.attributes["tests"].to_i
testresults[:minitest_assertions] += root.attributes["assertions"].to_i
testresults[:minitest_failures] += root.attributes["failures"].to_i
testresults[:minitest_errors] += root.attributes["errors"].to_i
testresults[:minitest_skipped] += root.attributes["skipped"].to_i
end
testresults
end
def report testresults = minitest g = Graphite.new g.host = @graphite_host g.port = @graphite_port
metrics = Hash.new
metrics[:updated_resources] = run_status.respond_to?(:updated_resources) ? run_status.updated_resources.length : 0
metrics[:all_resources] = run_status.respond_to?(:all_resources) ? run_status.all_resources.length : 0
metrics[:elapsed_time] = run_status.elapsed_time
# Graph metrics from the Ohai system-packages plugin (https://github.com/finnlabs/ohai-system_packages/)
if node.has_key? 'system_packages'
node['system_packages'].each do |k, v|
metrics["#{k}_packages"] = v.size if v and v.respond_to? :size
end
end
if run_status.success?
metrics[:success] = 1
metrics[:fail] = 0
else
metrics[:success] = 0
metrics[:fail] = 1
end
metrics.merge! minitest
This is great info, however I believe this functionality belongs in its own cookbook as opposed to this one.
I wish to graph the output of minitest handler in graphite (also using a handler). I've scanned the code but can't seem to get my head around how i would obtain the test summary data from within another handler?
One option i'm looking at is using the ci_reports to output to the files and then have them parsed by my graphite plugin but it feels convoluted...