2020-06-03 05:08:47 -04:00
|
|
|
# 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
|
|
|
|
|
|
|
|
def valid?
|
|
|
|
errors.blank?
|
|
|
|
end
|
|
|
|
|
|
|
|
def errors
|
|
|
|
strong_memoize(:errors) do
|
|
|
|
prepare!
|
|
|
|
parse_blob_data
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def parse_blob_data
|
2020-08-27 11:10:21 -04:00
|
|
|
if Feature.enabled?(:metrics_dashboard_exhaustive_validations, project)
|
|
|
|
exhaustive_metrics_dashboard_validation
|
|
|
|
else
|
|
|
|
old_metrics_dashboard_validation
|
|
|
|
end
|
|
|
|
end
|
2020-08-19 14:10:34 -04:00
|
|
|
|
2020-08-27 11:10:21 -04:00
|
|
|
def old_metrics_dashboard_validation
|
|
|
|
yaml = ::Gitlab::Config::Loader::Yaml.new(blob.data).load_raw!
|
2020-08-19 14:10:34 -04:00
|
|
|
::PerformanceMonitoring::PrometheusDashboard.from_json(yaml)
|
2020-08-27 11:10:21 -04:00
|
|
|
[]
|
2020-06-16 14:09:01 -04:00
|
|
|
rescue Gitlab::Config::Loader::FormatError => error
|
2020-08-27 11:10:21 -04:00
|
|
|
["YAML syntax: #{error.message}"]
|
2020-08-19 14:10:34 -04:00
|
|
|
rescue ActiveModel::ValidationError => invalid
|
2020-08-27 11:10:21 -04:00
|
|
|
invalid.model.errors.messages.map { |messages| messages.join(': ') }
|
2020-08-19 14:10:34 -04:00
|
|
|
end
|
|
|
|
|
2020-08-27 11:10:21 -04:00
|
|
|
def exhaustive_metrics_dashboard_validation
|
|
|
|
yaml = ::Gitlab::Config::Loader::Yaml.new(blob.data).load_raw!
|
|
|
|
Gitlab::Metrics::Dashboard::Validator
|
|
|
|
.errors(yaml, dashboard_path: blob.path, project: project)
|
|
|
|
.map(&:message)
|
|
|
|
rescue Gitlab::Config::Loader::FormatError => error
|
|
|
|
[error.message]
|
2020-06-03 05:08:47 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|