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 58 def add_keywords(*keywords) keywords.each do |keyword| @keywords_set[keyword] = true end end
build_report_root(format:, version:, host:, reported_at:, statuses:, proxy:, body:, keywords:)
click to toggle source
# File lib/smart_proxy_reports/processor.rb, line 34 def build_report_root(format:, version:, host:, reported_at:, statuses:, proxy:, body:, keywords:) { "host_report" => { "format" => format, "version" => version, "host" => host, "reported_at" => reported_at, "proxy" => proxy, "body" => @json_body ? body.to_json : body, "keywords" => keywords, }.merge(statuses), } # TODO add metric with total time end
debug_payload(prefix, data)
click to toggle source
# File lib/smart_proxy_reports/processor.rb, line 53 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 49 def debug_payload? Proxy::Reports::Plugin.settings.debug_payload end
errors?()
click to toggle source
# File lib/smart_proxy_reports/processor.rb, line 74 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 64 def keywords @keywords_set.keys.to_a rescue [] end
log_error(message)
click to toggle source
# File lib/smart_proxy_reports/processor.rb, line 70 def log_error(message) @errors << message.to_s end
measure(metric) { || ... }
click to toggle source
# File lib/smart_proxy_reports/processor.rb, line 81 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
spool_report()
click to toggle source
Calls superclass method
# File lib/smart_proxy_reports/processor.rb, line 98 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 90 def telemetry_as_string result = [] telemetry.each do |key, value| result << "#{key}=#{value.round(1)}ms" end result.join(", ") end