From 83eacc9a9e263fc85f68040ecd34215be6b59a55 Mon Sep 17 00:00:00 2001 From: Andreas Zuber Date: Thu, 14 Jun 2018 23:07:28 +0200 Subject: [PATCH] Add support for report format 9 This adds provider_used to the resource_status model --- .../20180614210435_add_report_format9.rb | 5 + db/schema.rb | 3 +- lib/puppet/report_sanitizer.rb | 34 +- spec/fixtures/reports/formats/09_failing.yaml | 366 ++++++++++++++++++ spec/lib/puppet/report_sanitizer_spec.rb | 14 + 5 files changed, 416 insertions(+), 6 deletions(-) create mode 100644 db/migrate/20180614210435_add_report_format9.rb create mode 100644 spec/fixtures/reports/formats/09_failing.yaml diff --git a/db/migrate/20180614210435_add_report_format9.rb b/db/migrate/20180614210435_add_report_format9.rb new file mode 100644 index 000000000..95f8e0524 --- /dev/null +++ b/db/migrate/20180614210435_add_report_format9.rb @@ -0,0 +1,5 @@ +class AddReportFormat9 < ActiveRecord::Migration[5.2] + def change + add_column :resource_statuses, :provider_used, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index ea2281ad5..4d71079db 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_06_14_161626) do +ActiveRecord::Schema.define(version: 2018_06_14_210435) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -200,6 +200,7 @@ t.string "status" t.text "containment_path" t.boolean "corrective_change" + t.string "provider_used" t.index ["report_id"], name: "index_resource_statuses_on_report_id" end diff --git a/lib/puppet/report_sanitizer.rb b/lib/puppet/report_sanitizer.rb index debca6efa..6854b194b 100644 --- a/lib/puppet/report_sanitizer.rb +++ b/lib/puppet/report_sanitizer.rb @@ -23,8 +23,10 @@ def sanitize(raw) format6sanitizer.sanitize(raw) when 7 format7sanitizer.sanitize(raw) - else + when 8 format8sanitizer.sanitize(raw) + else + format9sanitizer.sanitize(raw) end when raw.include?('resource_statuses') format1sanitizer.sanitize(raw) @@ -70,6 +72,10 @@ def format7sanitizer() def format8sanitizer() @format8sanitizer ||= ReportSanitizer::FormatVersion8.new end + + def format9sanitizer() + @format9sanitizer ||= ReportSanitizer::FormatVersion9.new + end end module Util @@ -331,7 +337,7 @@ class FormatVersion6 < FormatVersion5 def initialize( log_sanitizer = FormatVersion4LogSanitizer.new, metric_sanitizer = MetricSanitizer.new, - status_sanitizer = FormatVersion5StatusSanitizer.new + status_sanitizer = FormatVersion6StatusSanitizer.new ) super(log_sanitizer, metric_sanitizer, status_sanitizer) end @@ -342,8 +348,8 @@ def sanitize(raw) Util.copy_attributes(sanitized, raw, %w[noop noop_pending corrective_change master_used]) end - class FormatVersion5StatusSanitizer < FormatVersion4StatusSanitizer - def initialize(event_sanitizer = FormatVersion5EventSanitizer.new) + class FormatVersion6StatusSanitizer < FormatVersion4StatusSanitizer + def initialize(event_sanitizer = FormatVersion6EventSanitizer.new) super(event_sanitizer) end @@ -353,7 +359,7 @@ def sanitize(raw) Util.copy_attributes(sanitized, raw, %w[corrective_change]) end - class FormatVersion5EventSanitizer < FormatVersion4EventSanitizer + class FormatVersion6EventSanitizer < FormatVersion4EventSanitizer def sanitize(raw) sanitized = super Util.verify_attributes(raw, %w[corrective_change redacted]) @@ -379,4 +385,22 @@ def sanitize(raw) end end + class FormatVersion9 < FormatVersion8 + def initialize( + log_sanitizer = FormatVersion4LogSanitizer.new, + metric_sanitizer = MetricSanitizer.new, + status_sanitizer = FormatVersion9StatusSanitizer.new + ) + super(log_sanitizer, metric_sanitizer, status_sanitizer) + end + + class FormatVersion9StatusSanitizer < FormatVersion6StatusSanitizer + def sanitize(raw) + sanitized = super + Util.verify_attributes(raw, %w[provider_used]) + Util.copy_attributes(sanitized, raw, %w[provider_used]) + end + end + end + end diff --git a/spec/fixtures/reports/formats/09_failing.yaml b/spec/fixtures/reports/formats/09_failing.yaml new file mode 100644 index 000000000..98149913a --- /dev/null +++ b/spec/fixtures/reports/formats/09_failing.yaml @@ -0,0 +1,366 @@ +--- !ruby/object:Puppet::Transaction::Report +host: report-test.example.com +time: '2018-06-12T23:31:23.617459229+02:00' +configuration_version: 1528839083 +transaction_uuid: 7f1aae13-2e4b-40a8-8946-8dfa138efccf +report_format: 9 +puppet_version: 5.5.0 +status: failed +transaction_completed: true +noop: false +noop_pending: false +environment: production +logs: +- level: err + message: Could not find command '/usr/bin/thisdoesnotexist' + source: Puppet + tags: + - err + time: '2018-06-12T23:31:23.624318609+02:00' + file: + line: +- level: err + message: 'change from ''notrun'' to [''0''] failed: Could not find command ''/usr/bin/thisdoesnotexist''' + source: "/Stage[main]/Main/Exec[/usr/bin/thisdoesnotexist]/returns" + tags: + - err + - exec + - class + time: '2018-06-12T23:31:23.625230131+02:00' + file: "/home/azuber/tmp/puppet-report-generator/test.pp" + line: 2 +- level: notice + message: hello world + source: Puppet + tags: + - notice + time: '2018-06-12T23:31:23.625552739+02:00' + file: + line: +- level: notice + message: defined 'message' as 'hello world' + source: "/Stage[main]/Main/Notify[hello world]/message" + tags: + - notice + - notify + - class + time: '2018-06-12T23:31:23.625881970+02:00' + file: "/home/azuber/tmp/puppet-report-generator/test.pp" + line: 4 +- level: notice + message: Applied catalog in 0.02 seconds + source: Puppet + tags: + - notice + time: '2018-06-12T23:31:23.636582286+02:00' + file: + line: +metrics: + resources: + name: resources + label: Resources + values: + - - total + - Total + - 9 + - - skipped + - Skipped + - 0 + - - failed + - Failed + - 1 + - - failed_to_restart + - Failed to restart + - 0 + - - restarted + - Restarted + - 0 + - - changed + - Changed + - 1 + - - out_of_sync + - Out of sync + - 2 + - - scheduled + - Scheduled + - 0 + - - corrective_change + - Corrective change + - 0 + time: + name: time + label: Time + values: + - - exec + - Exec + - 0.001325921 + - - notify + - Notify + - 0.000548334 + - - schedule + - Schedule + - 0.000248223 + - - filebucket + - Filebucket + - 5.3079e-05 + - - config_retrieval + - Config retrieval + - 0.088663979 + - - transaction_evaluation + - Transaction evaluation + - 0.005367110000406683 + - - catalog_application + - Catalog application + - 0.01686296299976675 + - - total + - Total + - 0.11306960900017343 + changes: + name: changes + label: Changes + values: + - - total + - Total + - 1 + events: + name: events + label: Events + values: + - - total + - Total + - 2 + - - failure + - Failure + - 1 + - - success + - Success + - 1 +resource_statuses: + Exec[/usr/bin/thisdoesnotexist]: + title: "/usr/bin/thisdoesnotexist" + file: "/home/azuber/tmp/puppet-report-generator/test.pp" + line: 2 + resource: Exec[/usr/bin/thisdoesnotexist] + resource_type: Exec + provider_used: posix + containment_path: + - Stage[main] + - Main + - Exec[/usr/bin/thisdoesnotexist] + evaluation_time: 0.001325921 + tags: + - exec + - class + time: '2018-06-12T23:31:23.623974516+02:00' + failed: true + changed: false + out_of_sync: true + skipped: false + change_count: 0 + out_of_sync_count: 1 + events: + - audited: false + property: returns + previous_value: notrun + desired_value: + - '0' + historical_value: + message: 'change from ''notrun'' to [''0''] failed: Could not find command ''/usr/bin/thisdoesnotexist''' + name: executed_command + status: failure + time: '2018-06-12T23:31:23.624410261+02:00' + redacted: + corrective_change: false + corrective_change: false + Notify[hello world]: + title: hello world + file: "/home/azuber/tmp/puppet-report-generator/test.pp" + line: 4 + resource: Notify[hello world] + resource_type: Notify + provider_used: + containment_path: + - Stage[main] + - Main + - Notify[hello world] + evaluation_time: 0.000548334 + tags: + - notify + - class + time: '2018-06-12T23:31:23.625402508+02:00' + failed: false + changed: true + out_of_sync: true + skipped: false + change_count: 1 + out_of_sync_count: 1 + events: + - audited: false + property: message + previous_value: absent + desired_value: hello world + historical_value: + message: defined 'message' as 'hello world' + name: message_changed + status: success + time: '2018-06-12T23:31:23.625524733+02:00' + redacted: + corrective_change: false + corrective_change: false + Schedule[puppet]: + title: puppet + file: + line: + resource: Schedule[puppet] + resource_type: Schedule + provider_used: + containment_path: + - Schedule[puppet] + evaluation_time: 5.964e-05 + tags: + - schedule + - puppet + time: '2018-06-12T23:31:23.626201047+02:00' + failed: false + changed: false + out_of_sync: false + skipped: false + change_count: 0 + out_of_sync_count: 0 + events: [] + corrective_change: false + Schedule[hourly]: + title: hourly + file: + line: + resource: Schedule[hourly] + resource_type: Schedule + provider_used: + containment_path: + - Schedule[hourly] + evaluation_time: 3.846e-05 + tags: + - schedule + - hourly + time: '2018-06-12T23:31:23.626310018+02:00' + failed: false + changed: false + out_of_sync: false + skipped: false + change_count: 0 + out_of_sync_count: 0 + events: [] + corrective_change: false + Schedule[daily]: + title: daily + file: + line: + resource: Schedule[daily] + resource_type: Schedule + provider_used: + containment_path: + - Schedule[daily] + evaluation_time: 3.9011e-05 + tags: + - schedule + - daily + time: '2018-06-12T23:31:23.626403824+02:00' + failed: false + changed: false + out_of_sync: false + skipped: false + change_count: 0 + out_of_sync_count: 0 + events: [] + corrective_change: false + Schedule[weekly]: + title: weekly + file: + line: + resource: Schedule[weekly] + resource_type: Schedule + provider_used: + containment_path: + - Schedule[weekly] + evaluation_time: 3.774e-05 + tags: + - schedule + - weekly + time: '2018-06-12T23:31:23.626502575+02:00' + failed: false + changed: false + out_of_sync: false + skipped: false + change_count: 0 + out_of_sync_count: 0 + events: [] + corrective_change: false + Schedule[monthly]: + title: monthly + file: + line: + resource: Schedule[monthly] + resource_type: Schedule + provider_used: + containment_path: + - Schedule[monthly] + evaluation_time: 3.1703e-05 + tags: + - schedule + - monthly + time: '2018-06-12T23:31:23.626592123+02:00' + failed: false + changed: false + out_of_sync: false + skipped: false + change_count: 0 + out_of_sync_count: 0 + events: [] + corrective_change: false + Schedule[never]: + title: never + file: + line: + resource: Schedule[never] + resource_type: Schedule + provider_used: + containment_path: + - Schedule[never] + evaluation_time: 4.1669e-05 + tags: + - schedule + - never + time: '2018-06-12T23:31:23.626677117+02:00' + failed: false + changed: false + out_of_sync: false + skipped: false + change_count: 0 + out_of_sync_count: 0 + events: [] + corrective_change: false + Filebucket[puppet]: + title: puppet + file: + line: + resource: Filebucket[puppet] + resource_type: Filebucket + provider_used: + containment_path: + - Filebucket[puppet] + evaluation_time: 5.3079e-05 + tags: + - filebucket + - puppet + time: '2018-06-12T23:31:23.626774252+02:00' + failed: false + changed: false + out_of_sync: false + skipped: false + change_count: 0 + out_of_sync_count: 0 + events: [] + corrective_change: false +corrective_change: false +catalog_uuid: 7a50702d-3c15-443a-82c0-e5466812c940 +cached_catalog_status: not_used diff --git a/spec/lib/puppet/report_sanitizer_spec.rb b/spec/lib/puppet/report_sanitizer_spec.rb index f0e06d5bd..823b1ffb0 100644 --- a/spec/lib/puppet/report_sanitizer_spec.rb +++ b/spec/lib/puppet/report_sanitizer_spec.rb @@ -480,6 +480,20 @@ end end + describe 'a format version 9 (puppet 5.5.0-latest) report' do + let(:report_file) { '09_failing.yaml' } + + it 'should produce a hash of the report' do + hash = ReportSanitizer.sanitize(raw_report) + hash.should be_a(Hash) + hash.keys.should =~ %w{host time logs metrics resource_statuses kind configuration_version puppet_version report_format status environment transaction_uuid catalog_uuid cached_catalog_status noop noop_pending corrective_change master_used transaction_completed} + hash['report_format'].should == 9 + hash['host'].should == 'report-test.example.com' + resource_status = hash['resource_statuses']['Exec[/usr/bin/thisdoesnotexist]'] + resource_status['provider_used'].should == 'posix' + end + end + end end