diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 11:18:50 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 11:18:50 +0000 |
commit | 8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch) | |
tree | a77e7fe7a93de11213032ed4ab1f33a3db51b738 /app/models/performance_monitoring/prometheus_metric.rb | |
parent | 00b35af3db1abfe813a778f643dad221aad51fca (diff) | |
download | gitlab-ce-8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781.tar.gz |
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'app/models/performance_monitoring/prometheus_metric.rb')
-rw-r--r-- | app/models/performance_monitoring/prometheus_metric.rb | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/app/models/performance_monitoring/prometheus_metric.rb b/app/models/performance_monitoring/prometheus_metric.rb index 7b8bef906fa..d67b1809d93 100644 --- a/app/models/performance_monitoring/prometheus_metric.rb +++ b/app/models/performance_monitoring/prometheus_metric.rb @@ -10,16 +10,24 @@ module PerformanceMonitoring validates :query, presence: true, unless: :query_range validates :query_range, presence: true, unless: :query - def self.from_json(json_content) - metric = PrometheusMetric.new( - id: json_content['id'], - unit: json_content['unit'], - label: json_content['label'], - query: json_content['query'], - query_range: json_content['query_range'] - ) + class << self + def from_json(json_content) + build_from_hash(json_content).tap(&:validate!) + end - metric.tap(&:validate!) + private + + def build_from_hash(attributes) + return new unless attributes.is_a?(Hash) + + new( + id: attributes['id'], + unit: attributes['unit'], + label: attributes['label'], + query: attributes['query'], + query_range: attributes['query_range'] + ) + end end end end |