class Proxy::Reports::Processor
Attributes
errors[R]
telemetry[R]
TODO support multiple metrics and adding total time
Public Class Methods
new(*, json_body: true)
click to toggle source
# File lib/smart_proxy_reports/processor.rb, line 20 def initialize(*, json_body: true) @keywords_set = {} @errors = [] @json_body = json_body end
new_processor(format, data, json_body: true)
click to toggle source
# File lib/smart_proxy_reports/processor.rb, line 9 def self.new_processor(format, data, json_body: true) case format when "puppet" PuppetProcessor.new(data, json_body: json_body) when "ansible" AnsibleProcessor.new(data, json_body: json_body) else NotImplementedError.new end end
Public Instance Methods
add_keywords(*keywords)
click to toggle source
# File lib/smart_proxy_reports/processor.rb, line 65 def add_keywords(*keywords) keywords.each do |keyword| @keywords_set[keyword] = true end end
build_report_root(format:, version:, host:, proxy:, change:, nochange:, failure:, body:, keywords:)
click to toggle source
# File lib/smart_proxy_reports/processor.rb, line 39 def build_report_root(format:, version:, host:, proxy:, change:, nochange:, failure:, body:, keywords:) { "host_report" => { "format" => format, "version" => version, "host" => host, "reported_at" => now_utc, "proxy" => proxy, "body" => @json_body ? body.to_json : body, "keywords" => keywords, "change" => change, "nochange" => nochange, "failure" => failure, }, } end
debug_payload(prefix, data)
click to toggle source
# File lib/smart_proxy_reports/processor.rb, line 60 def debug_payload(prefix, data) return unless debug_payload? logger.debug { "#{prefix}: #{data.pretty_inspect}" } end
debug_payload?()
click to toggle source
# File lib/smart_proxy_reports/processor.rb, line 56 def debug_payload? Proxy::Reports::Plugin.settings.debug_payload end
errors?()
click to toggle source
# File lib/smart_proxy_reports/processor.rb, line 87 def errors? @errors&.any? end
generated_report_id()
click to toggle source
# File lib/smart_proxy_reports/processor.rb, line 26 def generated_report_id @generated_report_id ||= SecureRandom.uuid end
hostname_from_config()
click to toggle source
# File lib/smart_proxy_reports/processor.rb, line 30 def hostname_from_config @hostname_from_config ||= Proxy::Reports::Plugin.settings.override_hostname end
keywords()
click to toggle source
# File lib/smart_proxy_reports/processor.rb, line 71 def keywords @keywords_set.keys.to_a rescue [] end
log_error(message, exception = nil)
click to toggle source
# File lib/smart_proxy_reports/processor.rb, line 77 def log_error(message, exception = nil) msg = if exception "#{message}: #{exception}" else message end logger.error msg, exception @errors << msg.to_s end
measure(metric) { || ... }
click to toggle source
# File lib/smart_proxy_reports/processor.rb, line 94 def measure(metric) t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC) yield ensure t2 = Process.clock_gettime(Process::CLOCK_MONOTONIC) @telemetry ||= {} @telemetry[metric.to_s] = (t2 - t1) * 1000 end
now_utc()
click to toggle source
# File lib/smart_proxy_reports/processor.rb, line 34 def now_utc # make sure it contains TZ info: "2022-01-20 14:16:26 UTC" Time.now.utc.to_s end
spool_report()
click to toggle source
Calls superclass method
# File lib/smart_proxy_reports/processor.rb, line 111 def spool_report super logger.debug "Spooled #{report_id}: #{telemetry_as_string}" end
telemetry_as_string()
click to toggle source
# File lib/smart_proxy_reports/processor.rb, line 103 def telemetry_as_string result = [] telemetry.each do |key, value| result << "#{key}=#{value.round(1)}ms" end result.join(", ") end