Previously these metrics were omitted when their values were zero.
Signed-off-by: Paul Berry <[email protected]>
---
lib/puppet/transaction/report.rb | 13 +++++--------
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 6eac651..16b854a 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 98be287..5d270da 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|
--
1.7.2
--
You received this message because you are subscribed to the Google Groups
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/puppet-dev?hl=en.