Module: Perfgate::Serialization::RunResult
- Defined in:
- lib/perfgate/serialization/run_result.rb
Overview
Builds the schema_version 1 run-result document described in spec section 14.1. Milestone 5 will add source metadata; fingerprinting (spec section 15) is populated here so the comparison engine can decide compatibility without re-deriving it from scratch.
Constant Summary collapse
- SCHEMA_VERSION =
1
Class Method Summary collapse
- .build(workload_results, config: Perfgate.configuration) ⇒ Object
- .build_workload(result) ⇒ Object
- .metric_keys(samples) ⇒ Object
-
.summarize(samples) ⇒ Object
Every metric key present in at least one sample gets its own summary block (spec section 14.1 shows this for duration_ns, but the same shape applies to sql_count, sql_duration_ns, etc. once those metrics are enabled).
Class Method Details
.build(workload_results, config: Perfgate.configuration) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/perfgate/serialization/run_result.rb', line 19 def build(workload_results, config: Perfgate.configuration) { "schema_version" => SCHEMA_VERSION, "run_id" => SecureRandom.uuid, "created_at" => Time.now.utc.iso8601, "fingerprint" => Fingerprints::Components.collect(config: config), "workloads" => workload_results.map { |result| build_workload(result) } } end |
.build_workload(result) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/perfgate/serialization/run_result.rb', line 29 def build_workload(result) samples = result.fetch("samples") { "id" => result.fetch("id"), "status" => result.fetch("status"), "error" => result["error"], "definition_hash" => result["definition_hash"], "samples" => samples, "summary" => summarize(samples) } end |
.metric_keys(samples) ⇒ Object
53 54 55 |
# File 'lib/perfgate/serialization/run_result.rb', line 53 def metric_keys(samples) samples.each_with_object([]) { |sample, keys| keys.concat(sample.keys) }.uniq end |
.summarize(samples) ⇒ Object
Every metric key present in at least one sample gets its own summary block (spec section 14.1 shows this for duration_ns, but the same shape applies to sql_count, sql_duration_ns, etc. once those metrics are enabled).
46 47 48 49 50 51 |
# File 'lib/perfgate/serialization/run_result.rb', line 46 def summarize(samples) metric_keys(samples).each_with_object({}) do |key, summary| values = samples.map { |sample| sample[key] }.compact summary[key] = Statistics::Summary.call(values) end end |