debian-mirror-gitlab/app/models/blob_viewer/metrics_dashboard_yml.rb

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

46 lines
1.1 KiB
Ruby
Raw Normal View History

2020-06-23 00:09:42 +05:30
# frozen_string_literal: true
module BlobViewer
class MetricsDashboardYml < Base
include ServerSide
include Gitlab::Utils::StrongMemoize
include Auxiliary
self.partial_name = 'metrics_dashboard_yml'
self.loading_partial_name = 'metrics_dashboard_yml_loading'
self.file_types = %i(metrics_dashboard)
self.binary = false
2023-07-09 08:55:56 +05:30
def self.can_render?(blob, verify_binary: true)
super && !Feature.enabled?(:remove_monitor_metrics)
end
2020-06-23 00:09:42 +05:30
def valid?
errors.blank?
end
def errors
strong_memoize(:errors) do
prepare!
parse_blob_data
end
end
private
def parse_blob_data
2023-03-04 22:38:38 +05:30
old_metrics_dashboard_validation
2020-11-24 15:15:51 +05:30
end
2020-06-23 00:09:42 +05:30
2020-11-24 15:15:51 +05:30
def old_metrics_dashboard_validation
yaml = ::Gitlab::Config::Loader::Yaml.new(blob.data).load_raw!
2020-06-23 00:09:42 +05:30
::PerformanceMonitoring::PrometheusDashboard.from_json(yaml)
2020-11-24 15:15:51 +05:30
[]
2022-08-27 11:52:29 +05:30
rescue Gitlab::Config::Loader::FormatError => e
["YAML syntax: #{e.message}"]
rescue ActiveModel::ValidationError => e
e.model.errors.messages.map { |messages| messages.join(': ') }
2020-06-23 00:09:42 +05:30
end
end
end