diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 14:18:50 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 14:18:50 +0300 |
commit | 8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch) | |
tree | a77e7fe7a93de11213032ed4ab1f33a3db51b738 /app/models/blob_viewer/metrics_dashboard_yml.rb | |
parent | 00b35af3db1abfe813a778f643dad221aad51fca (diff) |
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'app/models/blob_viewer/metrics_dashboard_yml.rb')
-rw-r--r-- | app/models/blob_viewer/metrics_dashboard_yml.rb | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/app/models/blob_viewer/metrics_dashboard_yml.rb b/app/models/blob_viewer/metrics_dashboard_yml.rb new file mode 100644 index 00000000000..c05fb5d88d6 --- /dev/null +++ b/app/models/blob_viewer/metrics_dashboard_yml.rb @@ -0,0 +1,44 @@ +# 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 + yaml = ::Gitlab::Config::Loader::Yaml.new(blob.data).load_raw! + + ::PerformanceMonitoring::PrometheusDashboard.from_json(yaml) + nil + rescue Gitlab::Config::Loader::FormatError => error + wrap_yml_syntax_error(error) + rescue ActiveModel::ValidationError => invalid + invalid.model.errors + end + + def wrap_yml_syntax_error(error) + ::PerformanceMonitoring::PrometheusDashboard.new.errors.tap do |errors| + errors.add(:'YAML syntax', error.message) + end + end + end +end |