diff options
author | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-06-16 14:23:33 +0200 |
---|---|---|
committer | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-06-16 14:34:23 +0200 |
commit | b97d5b65dd40fb5d8753c0677534e82cb5636f2d (patch) | |
tree | 4e6fbc43e10ddbb2d1be735df5ea2224aa12d42e /lib/gitlab/prometheus/additional_metrics_parser.rb | |
parent | 0e7e7c2f2bd0e9c913cda438826a60e761130271 (diff) | |
download | gitlab-ce-b97d5b65dd40fb5d8753c0677534e82cb5636f2d.tar.gz |
Use include ActiveModel::Model to hold metrics data parsed from yaml.
Diffstat (limited to 'lib/gitlab/prometheus/additional_metrics_parser.rb')
-rw-r--r-- | lib/gitlab/prometheus/additional_metrics_parser.rb | 23 |
1 files changed, 7 insertions, 16 deletions
diff --git a/lib/gitlab/prometheus/additional_metrics_parser.rb b/lib/gitlab/prometheus/additional_metrics_parser.rb index 9bd41b99d81..70151e8c6ad 100644 --- a/lib/gitlab/prometheus/additional_metrics_parser.rb +++ b/lib/gitlab/prometheus/additional_metrics_parser.rb @@ -9,26 +9,17 @@ module Gitlab private - def metrics_from_list(list) - list.map { |entry| metric_from_entry(entry) } - end - - def metric_from_entry(entry) - required_fields = [:title, :required_metrics, :weight, :queries] - missing_fields = required_fields.select { |key| entry[key].nil? } - raise ParsingError.new("entry missing required fields #{missing_fields}") unless missing_fields.empty? - - Metric.new(entry[:title], entry[:required_metrics], entry[:weight], entry[:y_label], entry[:queries]) + def validate!(obj) + raise ParsingError.new(obj.errors.full_messages.join('\n')) unless obj.valid? end def group_from_entry(entry) - required_fields = [:group, :priority, :metrics] - missing_fields = required_fields.select { |key| entry[key].nil? } - - raise ParsingError.new("entry missing required fields #{missing_fields.map(&:to_s)}") unless missing_fields.empty? + entry[:name] = entry.delete(:group) + entry[:metrics]&.map! do |entry| + Metric.new(entry).tap(&method(:validate!)) + end - group = MetricGroup.new(entry[:group], entry[:priority]) - group.tap { |g| g.metrics = metrics_from_list(entry[:metrics]) } + MetricGroup.new(entry).tap(&method(:validate!)) end def additional_metrics_raw |