Class: PhobosPrometheus::BucketsValidator

Inherits:
Object
  • Object
show all
Includes:
Logger
Defined in:
lib/phobos_prometheus/config_parser.rb

Overview

Validate buckets

Constant Summary collapse

BUCKET_NAME_MISSING =
'Missing required key :name for bucket'
BUCKET_BINS_MISSING =
'Missing required key :bins for bucket'
BUCKET_BINS_EMPTY =
'Bucket config bad, bins are empty'
BUCKET_INVALID_KEY =
'Invalid configuration option detected at bucket level, ignoring'
BUCKET_KEYS =
[:name, :bins].freeze

Instance Method Summary collapse

Methods included from Logger

#log_error, #log_info, #log_warn

Constructor Details

#initialize(buckets) ⇒ BucketsValidator

Returns a new instance of BucketsValidator.



73
74
75
# File 'lib/phobos_prometheus/config_parser.rb', line 73

def initialize(buckets)
  @buckets = buckets
end

Instance Method Details

#validateObject



77
78
79
80
81
# File 'lib/phobos_prometheus/config_parser.rb', line 77

def validate
  @buckets.map do |bucket|
    validate_bucket(bucket)
  end
end

#validate_bucket(bucket) ⇒ Object



83
84
85
86
87
88
89
# File 'lib/phobos_prometheus/config_parser.rb', line 83

def validate_bucket(bucket)
  Helper.assert_required_key(bucket, :name) || Helper.fail_config(BUCKET_NAME_MISSING)
  Helper.assert_required_key(bucket, :bins) || Helper.fail_config(BUCKET_BINS_MISSING)
  Helper.assert_array_of_type(bucket, :bins, Integer) || Helper.fail_config(BUCKET_BINS_EMPTY)
  Helper.check_invalid_keys(BUCKET_KEYS, bucket) || \
    log_warn(BUCKET_INVALID_KEY)
end