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

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

34 lines
797 B
Ruby
Raw Normal View History

2020-03-13 15:44:24 +05:30
# frozen_string_literal: true
module PerformanceMonitoring
class PrometheusMetric
include ActiveModel::Model
attr_accessor :id, :unit, :label, :query, :query_range
validates :unit, presence: true
validates :query, presence: true, unless: :query_range
validates :query_range, presence: true, unless: :query
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
def build_from_hash(attributes)
return new unless attributes.is_a?(Hash)
new(
id: attributes['id'],
unit: attributes['unit'],
label: attributes['label'],
query: attributes['query'],
query_range: attributes['query_range']
)
end
2020-03-13 15:44:24 +05:30
end
end
end