Class: PhobosPrometheus::HistogramsValidator
- Inherits:
-
Object
- Object
- PhobosPrometheus::HistogramsValidator
- Includes:
- Logger
- Defined in:
- lib/phobos_prometheus/config_parser.rb
Overview
Validate Histograms
Constant Summary collapse
- HISTOGRAM_INSTRUMENTATION_MISSING =
'Missing required key :instrumentation for histogram'- HISTOGRAM_BUCKET_NAME_MISSING =
'Missing required key :bucket_name for histogram'- HISTOGRAM_INVALID_BUCKET =
'Invalid bucket reference specified for histogram'- HISTOGRAM_INVALID_KEY =
'Invalid configuration option detected at histogram level, ignoring'- HISTOGRAM_KEYS =
[:instrumentation, :bucket_name].freeze
Instance Method Summary collapse
- #assert_bucket_exists(name) ⇒ Object
-
#initialize(histograms, buckets) ⇒ HistogramsValidator
constructor
A new instance of HistogramsValidator.
- #validate ⇒ Object
- #validate_histogram(histogram) ⇒ Object
Methods included from Logger
#log_error, #log_info, #log_warn
Constructor Details
#initialize(histograms, buckets) ⇒ HistogramsValidator
Returns a new instance of HistogramsValidator.
38 39 40 41 |
# File 'lib/phobos_prometheus/config_parser.rb', line 38 def initialize(histograms, buckets) @histograms = histograms @buckets = buckets end |
Instance Method Details
#assert_bucket_exists(name) ⇒ Object
59 60 61 |
# File 'lib/phobos_prometheus/config_parser.rb', line 59 def assert_bucket_exists(name) @buckets.any? { |key| key.name == name } end |
#validate ⇒ Object
43 44 45 46 47 |
# File 'lib/phobos_prometheus/config_parser.rb', line 43 def validate @histograms.map do |histogram| validate_histogram(histogram) end end |
#validate_histogram(histogram) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/phobos_prometheus/config_parser.rb', line 49 def validate_histogram(histogram) Helper.assert_required_key(histogram, :instrumentation) || \ Helper.fail_config(HISTOGRAM_INSTRUMENTATION_MISSING) Helper.assert_required_key(histogram, :bucket_name) || \ Helper.fail_config(HISTOGRAM_BUCKET_NAME_MISSING) assert_bucket_exists(histogram['bucket_name']) || Helper.fail_config(HISTOGRAM_INVALID_BUCKET) Helper.check_invalid_keys(HISTOGRAM_KEYS, histogram) || \ log_warn(HISTOGRAM_INVALID_KEY) end |