diff options
| author | Paul Berry <paul@puppetlabs.com> | 2010-12-29 14:26:47 -0800 |
|---|---|---|
| committer | Paul Berry <paul@puppetlabs.com> | 2010-12-30 11:51:49 -0800 |
| commit | 71db5be0ecc5ab591e01974ba109f621348fdea0 (patch) | |
| tree | 0be294725a57b5f61d46ca1940817b94c50cf642 | |
| parent | a4e40f4dd5990df4dc6b2be065e82a142a31b6fc (diff) | |
(#5715) Made the changes/total and events/total metrics always present
Previously these metrics were omitted when their values were zero.
| -rw-r--r-- | lib/puppet/transaction/report.rb | 13 | ||||
| -rwxr-xr-x | spec/unit/transaction/report_spec.rb | 10 |
2 files changed, 15 insertions, 8 deletions
diff --git a/lib/puppet/transaction/report.rb b/lib/puppet/transaction/report.rb index 6eac6514b..16b854afc 100644 --- a/lib/puppet/transaction/report.rb +++ b/lib/puppet/transaction/report.rb @@ -46,7 +46,7 @@ class Puppet::Transaction::Report def finalize_report calculate_resource_metrics calculate_time_metrics - calculate_change_metrics + calculate_change_metric calculate_event_metrics end @@ -107,17 +107,14 @@ class Puppet::Transaction::Report private - def calculate_change_metrics - metrics = Hash.new(0) - resource_statuses.each do |name, status| - metrics[:total] += status.change_count if status.change_count - end - - add_metric(:changes, metrics) + def calculate_change_metric + total = resource_statuses.map { |name, status| status.change_count || 0 }.inject(0) { |a,b| a+b } + add_metric(:changes, {:total => total}) end def calculate_event_metrics metrics = Hash.new(0) + metrics[:total] = 0 resource_statuses.each do |name, status| metrics[:total] += status.events.length status.events.each do |event| diff --git a/spec/unit/transaction/report_spec.rb b/spec/unit/transaction/report_spec.rb index 98be28755..5d270dad3 100755 --- a/spec/unit/transaction/report_spec.rb +++ b/spec/unit/transaction/report_spec.rb @@ -174,6 +174,11 @@ describe Puppet::Transaction::Report do @report.finalize_report metric(:changes, :total).should == 9 end + + it "should provide a total even if there are no changes" do + @report.finalize_report + metric(:changes, :total).should == 0 + end end describe "for times" do @@ -220,6 +225,11 @@ describe Puppet::Transaction::Report do metric(:events, :total).should == 9 end + it "should provide the total even if there are no events" do + @report.finalize_report + metric(:events, :total).should == 0 + end + Puppet::Transaction::Event::EVENT_STATUSES.each do |status_name| it "should provide the number of #{status_name} events" do add_statuses(3) do |status| |
