debian-mirror-gitlab/app/models/performance_monitoring/prometheus_panel.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

43 lines
1.1 KiB
Ruby
Raw Permalink Normal View History

2020-03-13 15:44:24 +05:30
# frozen_string_literal: true
module PerformanceMonitoring
class PrometheusPanel
include ActiveModel::Model
2020-04-22 19:07:51 +05:30
attr_accessor :type, :title, :y_label, :weight, :metrics, :y_axis, :max_value
2020-03-13 15:44:24 +05:30
validates :title, presence: true
2020-07-28 23:09:34 +05:30
validates :metrics, array_members: { member_class: PerformanceMonitoring::PrometheusMetric }
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(
type: attributes['type'],
title: attributes['title'],
y_label: attributes['y_label'],
weight: attributes['weight'],
2020-07-28 23:09:34 +05:30
metrics: initialize_children_collection(attributes['metrics'])
2020-06-23 00:09:42 +05:30
)
end
2020-07-28 23:09:34 +05:30
def initialize_children_collection(children)
return unless children.is_a?(Array)
children.map { |metrics| PerformanceMonitoring::PrometheusMetric.from_json(metrics) }
end
2020-03-13 15:44:24 +05:30
end
2020-04-22 19:07:51 +05:30
def id(group_title)
Digest::SHA2.hexdigest([group_title, type, title].join)
end
2020-03-13 15:44:24 +05:30
end
end