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

46 lines
1.2 KiB
Ruby
Raw Normal View History

2020-03-13 15:44:24 +05:30
# frozen_string_literal: true
module PerformanceMonitoring
class PrometheusDashboard
include ActiveModel::Model
2020-05-24 23:13:21 +05:30
attr_accessor :dashboard, :panel_groups, :path, :environment, :priority, :templating
2020-03-13 15:44:24 +05:30
validates :dashboard, presence: true
validates :panel_groups, presence: true
2020-04-22 19:07:51 +05:30
class << self
def from_json(json_content)
dashboard = new(
dashboard: json_content['dashboard'],
panel_groups: json_content['panel_groups'].map { |group| PrometheusPanelGroup.from_json(group) }
)
dashboard.tap(&:validate!)
end
def find_for(project:, user:, path:, options: {})
dashboard_response = Gitlab::Metrics::Dashboard::Finder.find(project, user, options.merge(dashboard_path: path))
return unless dashboard_response[:status] == :success
new(
{
path: path,
environment: options[:environment]
}.merge(dashboard_response[:dashboard])
)
end
2020-03-13 15:44:24 +05:30
end
def to_yaml
2020-04-22 19:07:51 +05:30
self.as_json(only: yaml_valid_attributes).to_yaml
2020-03-13 15:44:24 +05:30
end
private
2020-04-22 19:07:51 +05:30
def yaml_valid_attributes
2020-03-13 15:44:24 +05:30
%w(panel_groups panels metrics group priority type title y_label weight id unit label query query_range dashboard)
end
end
end