Class: Puppet::Transaction::Report
- Extended by:
- Indirector
- Defined in:
- lib/puppet/transaction/report.rb
Overview
This class is used to report what happens on a client. There are two types of data in a report; Logs and Metrics.
-
Logs - are the output that each change produces.
-
Metrics - are all of the numerical data involved in the transaction.
Use Reports class to create a new custom report type. This class is indirectly used as a source of data to report in such a registered report.
##Metrics There are three types of metrics in each report, and each type of metric has one or more values.
-
Time: Keeps track of how long things took.
-
Total: Total time for the configuration run
-
File:
-
Exec:
-
User:
-
Group:
-
Config Retrieval: How long the configuration took to retrieve
-
Service:
-
Package:
-
-
Resources: Keeps track of the following stats:
-
Total: The total number of resources being managed
-
Skipped: How many resources were skipped, because of either tagging or scheduling restrictions
-
Scheduled: How many resources met any scheduling restrictions
-
Out of Sync: How many resources were out of sync
-
Applied: How many resources were attempted to be fixed
-
Failed: How many resources were not successfully fixed
-
Restarted: How many resources were restarted because their dependencies changed
-
Failed Restarts: How many resources could not be restarted
-
-
Changes: The total number of changes in the transaction.
Defined Under Namespace
Classes: Msgpack, Processor, Rest, Yaml
Constant Summary
Constants included from Indirector
Instance Attribute Summary collapse
-
#cached_catalog_status ⇒ String
Whether a cached catalog was used in the run, and if so, the reason that it was used.
-
#catalog_uuid ⇒ Object
A master generated catalog uuid, useful for connecting a single catalog to multiple reports.
-
#code_id ⇒ Object
The id of the code input to the compiler.
-
#configuration_version ⇒ ???
The version of the configuration.
- #corrective_change ⇒ Object readonly
-
#environment ⇒ String
The name of the environment the host is in.
-
#host ⇒ String
The host name for which the report is generated.
-
#kind ⇒ String
readonly
The ‘kind’ of report is the name of operation that triggered the report to be produced.
-
#logs ⇒ Array<Puppet::Util::Log>
readonly
A list of log messages.
-
#master_used ⇒ String
Contains the name and port of the master that was successfully contacted.
-
#metrics ⇒ Hash<{String => Object}>
readonly
A hash of metric name to metric value.
-
#noop ⇒ Boolean
readonly
Whether the puppet run was started in noop mode.
-
#noop_pending ⇒ Boolean
Whether there are changes that we decided not to apply because of noop.
-
#puppet_version ⇒ String
readonly
The Puppet version in String form.
-
#report_format ⇒ Integer
readonly
Report format version number.
-
#resource_statuses ⇒ Hash{String => Puppet::Resource::Status}
readonly
A hash with a map from resource to status.
-
#resources_failed_to_generate ⇒ Boolean
True if one or more resources attempted to generate resources and failed.
-
#status ⇒ String
readonly
The status of the client run is an enumeration: ‘failed’, ‘changed’ or ‘unchanged’.
-
#time ⇒ Time
readonly
The time when the report data was generated.
-
#transaction_uuid ⇒ String
An agent generated transaction uuid, useful for connecting catalog and report.
Class Method Summary collapse
Instance Method Summary collapse
- #<<(msg) ⇒ Object private
- #add_metric(name, hash) ⇒ Object private
- #add_resource_status(status) ⇒ Object private
- #add_times(name, value) ⇒ Object private
- #as_logging_destination(&block) ⇒ Object
- #compute_status(resource_metrics, change_metric) ⇒ Object private
-
#exit_status ⇒ Integer
Computes a single number that represents the report’s status.
- #finalize_report ⇒ Object private
- #has_noop_events?(resource) ⇒ Boolean private
-
#initialize(kind, configuration_version = nil, environment = nil, transaction_uuid = nil) ⇒ Report
constructor
private
A new instance of Report.
- #initialize_from_hash(data) ⇒ Object private
-
#name ⇒ String
The host name.
- #prune_internal_data ⇒ Object private
-
#raw_summary ⇒ Hash<{String => Object}>
Provides a raw hash summary of this report.
-
#summary ⇒ String
Provide a human readable textual summary of this report.
- #to_data_hash ⇒ Object
- #to_yaml_properties ⇒ Object private
Methods included from Indirector
Constructor Details
#initialize(kind, configuration_version = nil, environment = nil, transaction_uuid = nil) ⇒ Report
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Report.
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/puppet/transaction/report.rb', line 209 def initialize(kind, configuration_version=nil, environment=nil, transaction_uuid=nil) @metrics = {} @logs = [] @resource_statuses = {} @external_times ||= {} @host = Puppet[:node_name_value] @time = Time.now @kind = kind @report_format = 6 @puppet_version = Puppet.version @configuration_version = configuration_version @transaction_uuid = transaction_uuid @code_id = nil @catalog_uuid = nil @cached_catalog_status = nil @master_used = nil @environment = environment @status = 'failed' # assume failed until the report is finalized @noop = Puppet[:noop] @noop_pending = false @corrective_change = false end |
Instance Attribute Details
#cached_catalog_status ⇒ String
Whether a cached catalog was used in the run, and if so, the reason that it was used. or ‘on_failure’
60 61 62 |
# File 'lib/puppet/transaction/report.rb', line 60 def cached_catalog_status @cached_catalog_status end |
#catalog_uuid ⇒ Object
A master generated catalog uuid, useful for connecting a single catalog to multiple reports.
55 56 57 |
# File 'lib/puppet/transaction/report.rb', line 55 def catalog_uuid @catalog_uuid end |
#code_id ⇒ Object
The id of the code input to the compiler.
52 53 54 |
# File 'lib/puppet/transaction/report.rb', line 52 def code_id @code_id end |
#configuration_version ⇒ ???
Uncertain what this is?
The version of the configuration
45 46 47 |
# File 'lib/puppet/transaction/report.rb', line 45 def configuration_version @configuration_version end |
#corrective_change ⇒ Object (readonly)
128 129 130 |
# File 'lib/puppet/transaction/report.rb', line 128 def corrective_change @corrective_change end |
#environment ⇒ String
The name of the environment the host is in
72 73 74 |
# File 'lib/puppet/transaction/report.rb', line 72 def environment @environment end |
#host ⇒ String
The host name for which the report is generated
68 69 70 |
# File 'lib/puppet/transaction/report.rb', line 68 def host @host end |
#kind ⇒ String (readonly)
The ‘kind’ of report is the name of operation that triggered the report to be produced. Typically “apply”.
102 103 104 |
# File 'lib/puppet/transaction/report.rb', line 102 def kind @kind end |
#logs ⇒ Array<Puppet::Util::Log> (readonly)
A list of log messages.
85 86 87 |
# File 'lib/puppet/transaction/report.rb', line 85 def logs @logs end |
#master_used ⇒ String
Contains the name and port of the master that was successfully contacted
64 65 66 |
# File 'lib/puppet/transaction/report.rb', line 64 def master_used @master_used end |
#metrics ⇒ Hash<{String => Object}> (readonly)
Uncertain if all values are numbers - now marked as Object.
A hash of metric name to metric value.
91 92 93 |
# File 'lib/puppet/transaction/report.rb', line 91 def metrics @metrics end |
#noop ⇒ Boolean (readonly)
Whether the puppet run was started in noop mode
123 124 125 |
# File 'lib/puppet/transaction/report.rb', line 123 def noop @noop end |
#noop_pending ⇒ Boolean
Whether there are changes that we decided not to apply because of noop
77 78 79 |
# File 'lib/puppet/transaction/report.rb', line 77 def noop_pending @noop_pending end |
#puppet_version ⇒ String (readonly)
Returns The Puppet version in String form.
112 113 114 |
# File 'lib/puppet/transaction/report.rb', line 112 def puppet_version @puppet_version end |
#report_format ⇒ Integer (readonly)
Returns report format version number. This value is constant for a given version of Puppet; it is incremented when a new release of Puppet changes the API for the various objects that make up a report.
118 119 120 |
# File 'lib/puppet/transaction/report.rb', line 118 def report_format @report_format end |
#resource_statuses ⇒ Hash{String => Puppet::Resource::Status} (readonly)
A hash with a map from resource to status
81 82 83 |
# File 'lib/puppet/transaction/report.rb', line 81 def resource_statuses @resource_statuses end |
#resources_failed_to_generate ⇒ Boolean
Returns true if one or more resources attempted to generate resources and failed.
133 134 135 |
# File 'lib/puppet/transaction/report.rb', line 133 def resources_failed_to_generate @resources_failed_to_generate end |
#status ⇒ String (readonly)
The status of the client run is an enumeration: ‘failed’, ‘changed’ or ‘unchanged’
107 108 109 |
# File 'lib/puppet/transaction/report.rb', line 107 def status @status end |
#time ⇒ Time (readonly)
The time when the report data was generated.
96 97 98 |
# File 'lib/puppet/transaction/report.rb', line 96 def time @time end |
#transaction_uuid ⇒ String
An agent generated transaction uuid, useful for connecting catalog and report
49 50 51 |
# File 'lib/puppet/transaction/report.rb', line 49 def transaction_uuid @transaction_uuid end |
Class Method Details
.default_format ⇒ Object
396 397 398 |
# File 'lib/puppet/transaction/report.rb', line 396 def self.default_format :pson end |
.from_data_hash(data) ⇒ Object
135 136 137 138 139 |
# File 'lib/puppet/transaction/report.rb', line 135 def self.from_data_hash(data) obj = self.allocate obj.initialize_from_hash(data) obj end |
.supported_formats ⇒ Object
392 393 394 |
# File 'lib/puppet/transaction/report.rb', line 392 def self.supported_formats [:pson, :yaml] end |
Instance Method Details
#<<(msg) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
146 147 148 149 |
# File 'lib/puppet/transaction/report.rb', line 146 def <<(msg) @logs << msg self end |
#add_metric(name, hash) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
157 158 159 160 161 162 163 164 165 166 |
# File 'lib/puppet/transaction/report.rb', line 157 def add_metric(name, hash) metric = Puppet::Util::Metric.new(name) hash.each do |metric_name, value| metric.newvalue(metric_name, value) end @metrics[metric.name] = metric metric end |
#add_resource_status(status) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
169 170 171 |
# File 'lib/puppet/transaction/report.rb', line 169 def add_resource_status(status) @resource_statuses[status.resource] = status end |
#add_times(name, value) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
152 153 154 |
# File 'lib/puppet/transaction/report.rb', line 152 def add_times(name, value) @external_times[name] = value end |
#as_logging_destination(&block) ⇒ Object
141 142 143 |
# File 'lib/puppet/transaction/report.rb', line 141 def as_logging_destination(&block) Puppet::Util::Log.with_destination(self, &block) end |
#compute_status(resource_metrics, change_metric) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
174 175 176 177 178 179 180 181 182 |
# File 'lib/puppet/transaction/report.rb', line 174 def compute_status(resource_metrics, change_metric) if resources_failed_to_generate || (resource_metrics["failed"] || 0) > 0 'failed' elsif change_metric > 0 'changed' else 'unchanged' end end |
#exit_status ⇒ Integer
Computes a single number that represents the report’s status. The computation is based on the contents of this report’s metrics. The resulting number is a bitmask where individual bits represent the presence of different metrics.
-
0x2 set if there are changes
-
0x4 set if there are resource failures or resources that failed to restart
378 379 380 381 382 383 384 |
# File 'lib/puppet/transaction/report.rb', line 378 def exit_status status = 0 status |= 2 if @metrics["changes"]["total"] > 0 status |= 4 if @metrics["resources"]["failed"] > 0 status |= 4 if @metrics["resources"]["failed_to_restart"] > 0 status end |
#finalize_report ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/puppet/transaction/report.rb', line 195 def finalize_report prune_internal_data calculate_report_corrective_change resource_metrics = add_metric(:resources, calculate_resource_metrics) add_metric(:time, calculate_time_metrics) change_metric = calculate_change_metric add_metric(:changes, {"total" => change_metric}) add_metric(:events, calculate_event_metrics) @status = compute_status(resource_metrics, change_metric) @noop_pending = @resource_statuses.any? { |name,res| has_noop_events?(res) } end |
#has_noop_events?(resource) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
185 186 187 |
# File 'lib/puppet/transaction/report.rb', line 185 def has_noop_events?(resource) resource.events.any? { |event| event.status == 'noop' } end |
#initialize_from_hash(data) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
# File 'lib/puppet/transaction/report.rb', line 233 def initialize_from_hash(data) @puppet_version = data['puppet_version'] @report_format = data['report_format'] @configuration_version = data['configuration_version'] @transaction_uuid = data['transaction_uuid'] @environment = data['environment'] @status = data['status'] @noop = data['noop'] @noop_pending = data['noop_pending'] @host = data['host'] @time = data['time'] @corrective_change = data['corrective_change'] if master_used = data['master_used'] @master_used = master_used end if catalog_uuid = data['catalog_uuid'] @catalog_uuid = catalog_uuid end if code_id = data['code_id'] @code_id = code_id end if cached_catalog_status = data['cached_catalog_status'] @cached_catalog_status = cached_catalog_status end if @time.is_a? String @time = Time.parse(@time) end @kind = data['kind'] @metrics = {} data['metrics'].each do |name, hash| @metrics[name] = Puppet::Util::Metric.from_data_hash(hash) end @logs = data['logs'].map do |record| Puppet::Util::Log.from_data_hash(record) end @resource_statuses = {} data['resource_statuses'].map do |record| if record[1] == {} status = nil else status = Puppet::Resource::Status.from_data_hash(record[1]) end @resource_statuses[record[0]] = status end end |
#name ⇒ String
Returns the host name.
314 315 316 |
# File 'lib/puppet/transaction/report.rb', line 314 def name host end |
#prune_internal_data ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
190 191 192 |
# File 'lib/puppet/transaction/report.rb', line 190 def prune_internal_data resource_statuses.delete_if {|name,res| res.resource_type == 'Whit'} end |
#raw_summary ⇒ Hash<{String => Object}>
Provides a raw hash summary of this report.
353 354 355 356 357 358 359 360 361 362 363 364 365 366 |
# File 'lib/puppet/transaction/report.rb', line 353 def raw_summary report = { "version" => { "config" => configuration_version, "puppet" => Puppet.version } } @metrics.each do |name, metric| key = metric.name.to_s report[key] = {} metric.values.each do |metric_name, label, value| report[key][metric_name.to_s] = value end report[key]["total"] = 0 unless key == "time" or report[key].include?("total") end (report["time"] ||= {})["last_run"] = Time.now.tv_sec report end |
#summary ⇒ String
This is intended for debugging purposes
Provide a human readable textual summary of this report.
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 |
# File 'lib/puppet/transaction/report.rb', line 323 def summary report = raw_summary ret = "" report.keys.sort { |a,b| a.to_s <=> b.to_s }.each do |key| ret += "#{Puppet::Util::Metric.labelize(key)}:\n" report[key].keys.sort { |a,b| # sort by label if a == :total 1 elsif b == :total -1 else report[key][a].to_s <=> report[key][b].to_s end }.each do |label| value = report[key][label] next if value == 0 value = "%0.2f" % value if value.is_a?(Float) ret += " %15s %s\n" % [Puppet::Util::Metric.labelize(label) + ":", value] end end ret end |
#to_data_hash ⇒ Object
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
# File 'lib/puppet/transaction/report.rb', line 287 def to_data_hash { 'host' => @host, 'time' => @time.iso8601(9), 'configuration_version' => @configuration_version, 'transaction_uuid' => @transaction_uuid, 'catalog_uuid' => @catalog_uuid, 'code_id' => @code_id, 'cached_catalog_status' => @cached_catalog_status, 'report_format' => @report_format, 'puppet_version' => @puppet_version, 'kind' => @kind, 'status' => @status, 'noop' => @noop, 'noop_pending' => @noop_pending, 'environment' => @environment, 'master_used' => @master_used, 'logs' => @logs, 'metrics' => @metrics, 'resource_statuses' => @resource_statuses, 'corrective_change' => @corrective_change, } end |
#to_yaml_properties ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
388 389 390 |
# File 'lib/puppet/transaction/report.rb', line 388 def to_yaml_properties super - [:@external_times, :@resources_failed_to_generate] end |