diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 14:18:50 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 14:18:50 +0300 |
commit | 8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch) | |
tree | a77e7fe7a93de11213032ed4ab1f33a3db51b738 /app/models/performance_monitoring/prometheus_panel.rb | |
parent | 00b35af3db1abfe813a778f643dad221aad51fca (diff) |
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'app/models/performance_monitoring/prometheus_panel.rb')
-rw-r--r-- | app/models/performance_monitoring/prometheus_panel.rb | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/app/models/performance_monitoring/prometheus_panel.rb b/app/models/performance_monitoring/prometheus_panel.rb index 3fe029abda0..a16a68ba832 100644 --- a/app/models/performance_monitoring/prometheus_panel.rb +++ b/app/models/performance_monitoring/prometheus_panel.rb @@ -8,17 +8,24 @@ module PerformanceMonitoring validates :title, presence: true validates :metrics, presence: true + class << self + def from_json(json_content) + build_from_hash(json_content).tap(&:validate!) + end - def self.from_json(json_content) - panel = new( - type: json_content['type'], - title: json_content['title'], - y_label: json_content['y_label'], - weight: json_content['weight'], - metrics: json_content['metrics'].map { |metric| PrometheusMetric.from_json(metric) } - ) + private - panel.tap(&:validate!) + def build_from_hash(attributes) + return new unless attributes.is_a?(Hash) + + new( + type: attributes['type'], + title: attributes['title'], + y_label: attributes['y_label'], + weight: attributes['weight'], + metrics: attributes['metrics']&.map { |metric| PrometheusMetric.from_json(metric) } + ) + end end def id(group_title) |