summaryrefslogtreecommitdiff
path: root/app/models/performance_monitoring/prometheus_panel.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-07-20 12:26:25 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-07-20 12:26:25 +0000
commita09983ae35713f5a2bbb100981116d31ce99826e (patch)
tree2ee2af7bd104d57086db360a7e6d8c9d5d43667a /app/models/performance_monitoring/prometheus_panel.rb
parent18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff)
downloadgitlab-ce-a09983ae35713f5a2bbb100981116d31ce99826e.tar.gz
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'app/models/performance_monitoring/prometheus_panel.rb')
-rw-r--r--app/models/performance_monitoring/prometheus_panel.rb11
1 files changed, 9 insertions, 2 deletions
diff --git a/app/models/performance_monitoring/prometheus_panel.rb b/app/models/performance_monitoring/prometheus_panel.rb
index a16a68ba832..b33c09001ae 100644
--- a/app/models/performance_monitoring/prometheus_panel.rb
+++ b/app/models/performance_monitoring/prometheus_panel.rb
@@ -7,7 +7,8 @@ module PerformanceMonitoring
attr_accessor :type, :title, :y_label, :weight, :metrics, :y_axis, :max_value
validates :title, presence: true
- validates :metrics, presence: true
+ validates :metrics, array_members: { member_class: PerformanceMonitoring::PrometheusMetric }
+
class << self
def from_json(json_content)
build_from_hash(json_content).tap(&:validate!)
@@ -23,9 +24,15 @@ module PerformanceMonitoring
title: attributes['title'],
y_label: attributes['y_label'],
weight: attributes['weight'],
- metrics: attributes['metrics']&.map { |metric| PrometheusMetric.from_json(metric) }
+ metrics: initialize_children_collection(attributes['metrics'])
)
end
+
+ def initialize_children_collection(children)
+ return unless children.is_a?(Array)
+
+ children.map { |metrics| PerformanceMonitoring::PrometheusMetric.from_json(metrics) }
+ end
end
def id(group_title)