Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/services/metrics/dashboard/panel_preview_service.rb')
-rw-r--r--app/services/metrics/dashboard/panel_preview_service.rb54
1 files changed, 54 insertions, 0 deletions
diff --git a/app/services/metrics/dashboard/panel_preview_service.rb b/app/services/metrics/dashboard/panel_preview_service.rb
new file mode 100644
index 00000000000..5b24d817fb6
--- /dev/null
+++ b/app/services/metrics/dashboard/panel_preview_service.rb
@@ -0,0 +1,54 @@
+# frozen_string_literal: true
+
+# Ingest YAML fragment with metrics dashboard panel definition
+# https://docs.gitlab.com/ee/operations/metrics/dashboards/yaml.html#panel-panels-properties
+# process it and returns renderable json version
+module Metrics
+ module Dashboard
+ class PanelPreviewService
+ SEQUENCE = [
+ ::Gitlab::Metrics::Dashboard::Stages::CommonMetricsInserter,
+ ::Gitlab::Metrics::Dashboard::Stages::MetricEndpointInserter,
+ ::Gitlab::Metrics::Dashboard::Stages::PanelIdsInserter,
+ ::Gitlab::Metrics::Dashboard::Stages::AlertsInserter,
+ ::Gitlab::Metrics::Dashboard::Stages::UrlValidator
+ ].freeze
+
+ HANDLED_PROCESSING_ERRORS = [
+ Gitlab::Metrics::Dashboard::Errors::DashboardProcessingError,
+ Gitlab::Config::Loader::Yaml::NotHashError,
+ Gitlab::Config::Loader::Yaml::DataTooLargeError,
+ Gitlab::Config::Loader::FormatError
+ ].freeze
+
+ def initialize(project, panel_yaml, environment)
+ @project, @panel_yaml, @environment = project, panel_yaml, environment
+ end
+
+ def execute
+ dashboard = ::Gitlab::Metrics::Dashboard::Processor.new(project, dashboard_structure, SEQUENCE, environment: environment).process
+ ServiceResponse.success(payload: dashboard[:panel_groups][0][:panels][0])
+ rescue *HANDLED_PROCESSING_ERRORS => error
+ ServiceResponse.error(message: error.message)
+ end
+
+ private
+
+ attr_accessor :project, :panel_yaml, :environment
+
+ def dashboard_structure
+ {
+ panel_groups: [
+ {
+ panels: [panel_hash]
+ }
+ ]
+ }
+ end
+
+ def panel_hash
+ ::Gitlab::Config::Loader::Yaml.new(panel_yaml).load_raw!
+ end
+ end
+ end
+end