2017-06-06 10:07:33 -04:00
|
|
|
module Gitlab
|
|
|
|
module Prometheus
|
|
|
|
module AdditionalMetricsParser
|
|
|
|
extend self
|
|
|
|
|
|
|
|
def load_groups_from_yaml
|
2017-06-08 06:29:53 -04:00
|
|
|
additional_metrics_raw.map(&method(:group_from_entry))
|
2017-06-06 10:07:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2017-06-16 08:23:33 -04:00
|
|
|
def validate!(obj)
|
|
|
|
raise ParsingError.new(obj.errors.full_messages.join('\n')) unless obj.valid?
|
2017-06-06 10:07:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def group_from_entry(entry)
|
2017-06-16 08:23:33 -04:00
|
|
|
entry[:name] = entry.delete(:group)
|
|
|
|
entry[:metrics]&.map! do |entry|
|
|
|
|
Metric.new(entry).tap(&method(:validate!))
|
|
|
|
end
|
2017-06-06 10:07:33 -04:00
|
|
|
|
2017-06-16 08:23:33 -04:00
|
|
|
MetricGroup.new(entry).tap(&method(:validate!))
|
2017-06-06 10:07:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def additional_metrics_raw
|
2017-06-16 14:58:18 -04:00
|
|
|
load_yaml_file&.map(&:deep_symbolize_keys).freeze
|
2017-06-09 06:43:12 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def load_yaml_file
|
2017-06-16 14:58:18 -04:00
|
|
|
@loaded_yaml_file ||= YAML.load_file(Rails.root.join('config/prometheus/additional_metrics.yml'))
|
2017-06-06 10:07:33 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|