summaryrefslogtreecommitdiff
path: root/app/models/performance_monitoring
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-01-28 18:08:35 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-01-28 18:08:35 +0000
commit6315ed9630fb1c6ade3114beb762cd1568d79219 (patch)
tree2a5d31936d09c14420c8f4c8bd752e268f0eb19f /app/models/performance_monitoring
parentfedf978f9aa1909ed7bb3fad767ad120a1c6bd7b (diff)
downloadgitlab-ce-6315ed9630fb1c6ade3114beb762cd1568d79219.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/performance_monitoring')
-rw-r--r--app/models/performance_monitoring/prometheus_dashboard.rb31
-rw-r--r--app/models/performance_monitoring/prometheus_metric.rb25
-rw-r--r--app/models/performance_monitoring/prometheus_panel.rb24
-rw-r--r--app/models/performance_monitoring/prometheus_panel_group.rb22
4 files changed, 102 insertions, 0 deletions
diff --git a/app/models/performance_monitoring/prometheus_dashboard.rb b/app/models/performance_monitoring/prometheus_dashboard.rb
new file mode 100644
index 00000000000..5f2df444fd0
--- /dev/null
+++ b/app/models/performance_monitoring/prometheus_dashboard.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+module PerformanceMonitoring
+ class PrometheusDashboard
+ include ActiveModel::Model
+
+ attr_accessor :dashboard, :panel_groups
+
+ validates :dashboard, presence: true
+ validates :panel_groups, presence: true
+
+ def self.from_json(json_content)
+ dashboard = new(
+ dashboard: json_content['dashboard'],
+ panel_groups: json_content['panel_groups'].map { |group| PrometheusPanelGroup.from_json(group) }
+ )
+
+ dashboard.tap(&:validate!)
+ end
+
+ def to_yaml
+ self.as_json(only: valid_attributes).to_yaml
+ end
+
+ private
+
+ def valid_attributes
+ %w(panel_groups panels metrics group priority type title y_label weight id unit label query query_range dashboard)
+ end
+ end
+end
diff --git a/app/models/performance_monitoring/prometheus_metric.rb b/app/models/performance_monitoring/prometheus_metric.rb
new file mode 100644
index 00000000000..7b8bef906fa
--- /dev/null
+++ b/app/models/performance_monitoring/prometheus_metric.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+module PerformanceMonitoring
+ class PrometheusMetric
+ include ActiveModel::Model
+
+ attr_accessor :id, :unit, :label, :query, :query_range
+
+ validates :unit, presence: true
+ validates :query, presence: true, unless: :query_range
+ validates :query_range, presence: true, unless: :query
+
+ def self.from_json(json_content)
+ metric = PrometheusMetric.new(
+ id: json_content['id'],
+ unit: json_content['unit'],
+ label: json_content['label'],
+ query: json_content['query'],
+ query_range: json_content['query_range']
+ )
+
+ metric.tap(&:validate!)
+ end
+ end
+end
diff --git a/app/models/performance_monitoring/prometheus_panel.rb b/app/models/performance_monitoring/prometheus_panel.rb
new file mode 100644
index 00000000000..c03218b4219
--- /dev/null
+++ b/app/models/performance_monitoring/prometheus_panel.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+module PerformanceMonitoring
+ class PrometheusPanel
+ include ActiveModel::Model
+
+ attr_accessor :type, :title, :y_label, :weight, :metrics
+
+ validates :title, presence: true
+ validates :metrics, presence: true
+
+ def self.from_json(json_content)
+ panel = new(
+ type: json_content['type'],
+ title: json_content['title'],
+ y_label: json_content['y_label'],
+ weight: json_content['weight'],
+ metrics: json_content['metrics'].map { |metric| PrometheusMetric.from_json(metric) }
+ )
+
+ panel.tap(&:validate!)
+ end
+ end
+end
diff --git a/app/models/performance_monitoring/prometheus_panel_group.rb b/app/models/performance_monitoring/prometheus_panel_group.rb
new file mode 100644
index 00000000000..e672545fce3
--- /dev/null
+++ b/app/models/performance_monitoring/prometheus_panel_group.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+module PerformanceMonitoring
+ class PrometheusPanelGroup
+ include ActiveModel::Model
+
+ attr_accessor :group, :priority, :panels
+
+ validates :group, presence: true
+ validates :panels, presence: true
+
+ def self.from_json(json_content)
+ panel_group = new(
+ group: json_content['group'],
+ priority: json_content['priority'],
+ panels: json_content['panels'].map { |panel| PrometheusPanel.from_json(panel) }
+ )
+
+ panel_group.tap(&:validate!)
+ end
+ end
+end