2020-03-13 15:44:24 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module PerformanceMonitoring
|
|
|
|
class PrometheusPanelGroup
|
|
|
|
include ActiveModel::Model
|
|
|
|
|
|
|
|
attr_accessor :group, :priority, :panels
|
|
|
|
|
|
|
|
validates :group, presence: true
|
|
|
|
validates :panels, presence: true
|
2020-06-23 00:09:42 +05:30
|
|
|
class << self
|
|
|
|
def from_json(json_content)
|
|
|
|
build_from_hash(json_content).tap(&:validate!)
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
private
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
def build_from_hash(attributes)
|
|
|
|
return new unless attributes.is_a?(Hash)
|
|
|
|
|
|
|
|
new(
|
|
|
|
group: attributes['group'],
|
|
|
|
priority: attributes['priority'],
|
|
|
|
panels: attributes['panels']&.map { |panel| PrometheusPanel.from_json(panel) }
|
|
|
|
)
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|