2020-01-28 18:08:35 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module PerformanceMonitoring
|
|
|
|
class PrometheusPanelGroup
|
|
|
|
include ActiveModel::Model
|
|
|
|
|
|
|
|
attr_accessor :group, :priority, :panels
|
|
|
|
|
|
|
|
validates :group, presence: true
|
2020-06-19 00:09:12 +00:00
|
|
|
validates :panels, array_members: { member_class: PerformanceMonitoring::PrometheusPanel }
|
|
|
|
|
2020-06-05 18:08:19 +00:00
|
|
|
class << self
|
|
|
|
def from_json(json_content)
|
|
|
|
build_from_hash(json_content).tap(&:validate!)
|
|
|
|
end
|
2020-01-28 18:08:35 +00:00
|
|
|
|
2020-06-05 18:08:19 +00:00
|
|
|
private
|
2020-01-28 18:08:35 +00:00
|
|
|
|
2020-06-05 18:08:19 +00:00
|
|
|
def build_from_hash(attributes)
|
|
|
|
return new unless attributes.is_a?(Hash)
|
|
|
|
|
|
|
|
new(
|
|
|
|
group: attributes['group'],
|
|
|
|
priority: attributes['priority'],
|
2020-06-19 00:09:12 +00:00
|
|
|
panels: initialize_children_collection(attributes['panels'])
|
2020-06-05 18:08:19 +00:00
|
|
|
)
|
|
|
|
end
|
2020-06-19 00:09:12 +00:00
|
|
|
|
|
|
|
def initialize_children_collection(children)
|
|
|
|
return unless children.is_a?(Array)
|
|
|
|
|
|
|
|
children.map { |panels| PerformanceMonitoring::PrometheusPanel.from_json(panels) }
|
|
|
|
end
|
2020-01-28 18:08:35 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|