Skip to content

Commit 8fe2701

Browse files
(PUP-11654) Omit unchanged resources from reports
Before this change, the report contained detailed information for each resource, regardless if there was a change or not during catalog application. With this change, the report can omit unchanged resources from the report by setting `exclude_unchanged_resources` to true.
1 parent 95291a9 commit 8fe2701

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

lib/puppet/defaults.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,6 +1450,12 @@ def self.initialize_default_settings!(settings)
14501450
14511451
To turn off reports entirely, set this to `none`",
14521452
},
1453+
:exclude_unchanged_resources => {
1454+
:default => false,
1455+
:type => :boolean,
1456+
:desc => 'When set to true, resources that have had no changes after catalog application
1457+
will not have corresponding unchanged resource status updates listed in the report.'
1458+
},
14531459
:reportdir => {
14541460
:default => "$vardir/reports",
14551461
:type => :directory,

lib/puppet/transaction/report.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,16 @@ def initialize_from_hash(data)
308308
end
309309
end
310310

311+
def skip_or_to_data_hash(rs)
312+
if rs.nil?
313+
nil
314+
elsif !rs.out_of_sync? && Puppet[:exclude_unchanged_resources]
315+
{}
316+
else
317+
rs.to_data_hash
318+
end
319+
end
320+
311321
def to_data_hash
312322
hash = {
313323
'host' => @host,
@@ -323,7 +333,7 @@ def to_data_hash
323333
'environment' => @environment,
324334
'logs' => @logs.map { |log| log.to_data_hash },
325335
'metrics' => Hash[@metrics.map { |key, metric| [key, metric.to_data_hash] }],
326-
'resource_statuses' => Hash[@resource_statuses.map { |key, rs| [key, rs.nil? ? nil : rs.to_data_hash] }],
336+
'resource_statuses' => Hash[@resource_statuses.map { |key, rs| [key, skip_or_to_data_hash(rs)] }],
327337
'corrective_change' => @corrective_change,
328338
}
329339

spec/unit/transaction/report_spec.rb

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
require 'spec_helper'
2-
2+
require 'puppet_spec/compiler'
33
require 'puppet'
44
require 'puppet/transaction/report'
55
require 'matchers/json'
66

77
describe Puppet::Transaction::Report do
88
include JSONMatchers
99
include PuppetSpec::Files
10+
include PuppetSpec::Compiler
1011

1112
before do
1213
allow(Puppet::Util::Storage).to receive(:store)
@@ -136,6 +137,33 @@
136137
expect(report.metrics['time'].values.any? {|metric| metric.first =~ /whit/i}).to be_falsey
137138
end
138139

140+
describe "when exclude_unchanged_resources is true" do
141+
before do
142+
Puppet[:exclude_unchanged_resources] = true
143+
end
144+
145+
let(:test_dir) { tmpdir('unchanged_resources') }
146+
def generate_report_and_get_resource_statuses(test_dir)
147+
transaction = apply_compiled_manifest(<<-END)
148+
file { '#{test_dir}':
149+
ensure => directory
150+
}
151+
END
152+
return transaction.report.to_data_hash['resource_statuses']
153+
end
154+
155+
it 'a changed resource is still reported correctly' do
156+
FileUtils.rm_rf(test_dir)
157+
resource_statuses = generate_report_and_get_resource_statuses(test_dir)
158+
expect(resource_statuses["File[#{test_dir}]"]['out_of_sync']).to be_truthy
159+
end
160+
161+
it 'the status for the unchanged resource should be empty' do
162+
resource_statuses = generate_report_and_get_resource_statuses(test_dir)
163+
expect(resource_statuses["File[#{test_dir}]"]).to eq({})
164+
end
165+
end
166+
139167
describe "when accepting logs" do
140168
before do
141169
@report = Puppet::Transaction::Report.new

0 commit comments

Comments
 (0)