summaryrefslogtreecommitdiff
path: root/app/models/performance_monitoring/prometheus_panel.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/performance_monitoring/prometheus_panel.rb')
-rw-r--r--app/models/performance_monitoring/prometheus_panel.rb25
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)