Class: Perfgate::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/perfgate/config.rb,
lib/perfgate/config/schema.rb,
lib/perfgate/config/defaults.rb,
lib/perfgate/config/validator.rb,
lib/perfgate/config/env_overrides.rb

Overview

Loads, validates, and provides typed access to baseline.yml (spec section 11). Configuration is a plain merged Hash under the hood; this class only adds convenience readers for the values Milestone 1 actually acts on (execution sample/warmup counts, enabled metrics, storage path). Later milestones will add readers for comparison, policy, and fingerprint sections as those are implemented.

Defined Under Namespace

Modules: Defaults, EnvOverrides, Schema, Validator

Constant Summary collapse

DEFAULT_DATASET_FINGERPRINT =

The default dataset fingerprint hook (spec section 12.3): apps that care about dataset drift affecting comparability can override this with a callable of their own via Perfgate.configure.

-> { ENV.fetch("PERFGATE_DATASET_VERSION", "unspecified") }

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Config

Returns a new instance of Config.



77
78
79
80
# File 'lib/perfgate/config.rb', line 77

def initialize(hash)
  @to_h = hash
  @dataset_fingerprint = DEFAULT_DATASET_FINGERPRINT
end

Instance Attribute Details

#dataset_fingerprintObject

Returns the value of attribute dataset_fingerprint.



75
76
77
# File 'lib/perfgate/config.rb', line 75

def dataset_fingerprint
  @dataset_fingerprint
end

#to_hObject (readonly)

Returns the value of attribute to_h.



74
75
76
# File 'lib/perfgate/config.rb', line 74

def to_h
  @to_h
end

Class Method Details

.defaultObject

A Config built entirely from defaults, with no file on disk.



19
20
21
# File 'lib/perfgate/config.rb', line 19

def default
  new(deep_dup(Defaults::HASH))
end

.load(path = "perfgate.yml") ⇒ Object

Loads baseline.yml (or the given path). A missing file is treated as an empty configuration, i.e. pure defaults.



25
26
27
28
29
30
31
# File 'lib/perfgate/config.rb', line 25

def load(path = "perfgate.yml")
  raw = read_yaml(path)
  merged = deep_merge(deep_dup(Defaults::HASH), raw)
  EnvOverrides.apply(merged)
  Validator.call(merged)
  new(merged)
end

Instance Method Details

#comparison_confidence_levelObject



108
109
110
# File 'lib/perfgate/config.rb', line 108

def comparison_confidence_level
  to_h.dig(:comparison, :confidence_level)
end

#comparison_minimum_samplesObject



104
105
106
# File 'lib/perfgate/config.rb', line 104

def comparison_minimum_samples
  to_h.dig(:comparison, :minimum_samples)
end

#comparison_noise_ratio_thresholdObject



112
113
114
# File 'lib/perfgate/config.rb', line 112

def comparison_noise_ratio_threshold
  to_h.dig(:comparison, :noise_ratio_threshold)
end

#dig(*keys) ⇒ Object



132
133
134
# File 'lib/perfgate/config.rb', line 132

def dig(*keys)
  to_h.dig(*keys)
end

#enabled_metricsObject



90
91
92
# File 'lib/perfgate/config.rb', line 90

def enabled_metrics
  to_h.fetch(:metrics).select { |_name, opts| opts[:enabled] }.keys
end

#execution_defaultsObject

Defaults handed to newly-discovered workloads that don't override samples/warmup/metrics themselves (spec section 9.3).



96
97
98
# File 'lib/perfgate/config.rb', line 96

def execution_defaults
  { samples: execution_samples, warmup: execution_warmup, metrics: enabled_metrics }
end

#execution_samplesObject



82
83
84
# File 'lib/perfgate/config.rb', line 82

def execution_samples
  to_h.dig(:execution, :samples)
end

#execution_warmupObject



86
87
88
# File 'lib/perfgate/config.rb', line 86

def execution_warmup
  to_h.dig(:execution, :warmup)
end

#fingerprint_informational_fieldsObject



124
125
126
# File 'lib/perfgate/config.rb', line 124

def fingerprint_informational_fields
  to_h.dig(:fingerprint, :informational)
end

#fingerprint_strict_fieldsObject



120
121
122
# File 'lib/perfgate/config.rb', line 120

def fingerprint_strict_fields
  to_h.dig(:fingerprint, :strict)
end

#policyObject



128
129
130
# File 'lib/perfgate/config.rb', line 128

def policy
  to_h.fetch(:policy)
end

#practical_thresholdsObject



116
117
118
# File 'lib/perfgate/config.rb', line 116

def practical_thresholds
  to_h.dig(:comparison, :practical_thresholds)
end

#storage_pathObject



100
101
102
# File 'lib/perfgate/config.rb', line 100

def storage_path
  to_h.dig(:storage, :path)
end