diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 04:45:44 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 04:45:44 +0300 |
commit | 85dc423f7090da0a52c73eb66faf22ddb20efff9 (patch) | |
tree | 9160f299afd8c80c038f08e1545be119f5e3f1e1 /app/models/blob_viewer | |
parent | 15c2c8c66dbe422588e5411eee7e68f1fa440bb8 (diff) |
Add latest changes from gitlab-org/gitlab@13-4-stable-ee
Diffstat (limited to 'app/models/blob_viewer')
-rw-r--r-- | app/models/blob_viewer/dependency_manager.rb | 4 | ||||
-rw-r--r-- | app/models/blob_viewer/metrics_dashboard_yml.rb | 26 |
2 files changed, 20 insertions, 10 deletions
diff --git a/app/models/blob_viewer/dependency_manager.rb b/app/models/blob_viewer/dependency_manager.rb index a851f22bfcd..1be7120a955 100644 --- a/app/models/blob_viewer/dependency_manager.rb +++ b/app/models/blob_viewer/dependency_manager.rb @@ -33,8 +33,8 @@ module BlobViewer @json_data ||= begin prepare! Gitlab::Json.parse(blob.data) - rescue - {} + rescue + {} end end diff --git a/app/models/blob_viewer/metrics_dashboard_yml.rb b/app/models/blob_viewer/metrics_dashboard_yml.rb index c05fb5d88d6..88643253d3d 100644 --- a/app/models/blob_viewer/metrics_dashboard_yml.rb +++ b/app/models/blob_viewer/metrics_dashboard_yml.rb @@ -25,20 +25,30 @@ module BlobViewer private def parse_blob_data - yaml = ::Gitlab::Config::Loader::Yaml.new(blob.data).load_raw! + if Feature.enabled?(:metrics_dashboard_exhaustive_validations, project) + exhaustive_metrics_dashboard_validation + else + old_metrics_dashboard_validation + end + end + def old_metrics_dashboard_validation + 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) + ["YAML syntax: #{error.message}"] rescue ActiveModel::ValidationError => invalid - invalid.model.errors + invalid.model.errors.messages.map { |messages| messages.join(': ') } end - def wrap_yml_syntax_error(error) - ::PerformanceMonitoring::PrometheusDashboard.new.errors.tap do |errors| - errors.add(:'YAML syntax', error.message) - end + 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] end end end |