summaryrefslogtreecommitdiff
path: root/app/models/performance_monitoring/prometheus_panel.rb
blob: 3fe029abda059c872d23836817eea1d28f0456d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# frozen_string_literal: true

module PerformanceMonitoring
  class PrometheusPanel
    include ActiveModel::Model

    attr_accessor :type, :title, :y_label, :weight, :metrics, :y_axis, :max_value

    validates :title, presence: true
    validates :metrics, presence: true

    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) }
      )

      panel.tap(&:validate!)
    end

    def id(group_title)
      Digest::SHA2.hexdigest([group_title, type, title].join)
    end
  end
end