Class: PhobosPrometheus::ConfigParser
- Inherits:
-
Object
- Object
- PhobosPrometheus::ConfigParser
show all
- Includes:
- Logger
- Defined in:
- lib/phobos_prometheus/config_parser.rb
Overview
Config validates and parses configuration yml
Constant Summary
collapse
- ROOT_MISSING_COLLECTORS =
'No histograms, gauges nor counters are configured. ' \
'Metrics will not be recorded'
- ROOT_INVALID_KEY =
'Invalid configuration option detected at root level, ignoring'
- ROOT_KEYS =
[:metrics_prefix, :counters, :histograms, :buckets, :gauges].freeze
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Logger
#log_error, #log_info, #log_warn
Constructor Details
Returns a new instance of ConfigParser.
161
162
163
164
165
166
167
168
|
# File 'lib/phobos_prometheus/config_parser.rb', line 161
def initialize(path)
@config = Helper.read_config(path)
validate_config
@config.counters = [] unless @config.counters
@config.histograms = [] unless @config.histograms
@config.gauges = [] unless @config.gauges
@config.freeze
end
|
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
154
155
156
|
# File 'lib/phobos_prometheus/config_parser.rb', line 154
def config
@config
end
|
Instance Method Details
#assert_required_root_keys ⇒ Object
200
201
202
203
|
# File 'lib/phobos_prometheus/config_parser.rb', line 200
def assert_required_root_keys
@config.counters || @config.histograms || @config.gauges || \
log_warn(ROOT_MISSING_COLLECTORS)
end
|
#validate_buckets ⇒ Object
192
193
194
|
# File 'lib/phobos_prometheus/config_parser.rb', line 192
def validate_buckets
BucketsValidator.new(@config.to_h[:buckets] || []).validate
end
|
#validate_config ⇒ Object
170
171
172
173
174
175
176
|
# File 'lib/phobos_prometheus/config_parser.rb', line 170
def validate_config
validate_root
validate_counters
validate_histograms
validate_buckets
validate_gauges
end
|
#validate_counters ⇒ Object
184
185
186
|
# File 'lib/phobos_prometheus/config_parser.rb', line 184
def validate_counters
CountersValidator.new(@config.to_h[:counters] || []).validate
end
|
#validate_gauges ⇒ Object
196
197
198
|
# File 'lib/phobos_prometheus/config_parser.rb', line 196
def validate_gauges
GaugesValidator.new(@config.to_h[:gauges] || []).validate
end
|
#validate_histograms ⇒ Object
188
189
190
|
# File 'lib/phobos_prometheus/config_parser.rb', line 188
def validate_histograms
HistogramsValidator.new(@config.to_h[:histograms] || [], @config.buckets).validate
end
|