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
path: root/app
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-10 21:09:32 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-10 21:09:32 +0300
commited5add1c2f001c9bd54e664b32f212de172eca6a (patch)
treef9449cbecde36706f25a62f426b5398566ae5cca /app
parentde2fb5b82c92c90f90ed67ced45143c04e934fb8 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
-rw-r--r--app/graphql/resolvers/metrics/dashboard_resolver.rb21
-rw-r--r--app/graphql/types/environment_type.rb4
-rw-r--r--app/graphql/types/metrics/dashboard_type.rb15
-rw-r--r--app/models/performance_monitoring/prometheus_dashboard.rb34
-rw-r--r--app/models/prometheus_alert.rb3
5 files changed, 66 insertions, 11 deletions
diff --git a/app/graphql/resolvers/metrics/dashboard_resolver.rb b/app/graphql/resolvers/metrics/dashboard_resolver.rb
new file mode 100644
index 00000000000..05d82ca0f46
--- /dev/null
+++ b/app/graphql/resolvers/metrics/dashboard_resolver.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+module Resolvers
+ module Metrics
+ class DashboardResolver < Resolvers::BaseResolver
+ argument :path, GraphQL::STRING_TYPE,
+ required: true,
+ description: "Path to a file which defines metrics dashboard eg: 'config/prometheus/common_metrics.yml'"
+
+ type Types::Metrics::DashboardType, null: true
+
+ alias_method :environment, :object
+
+ def resolve(**args)
+ return unless environment
+
+ ::PerformanceMonitoring::PrometheusDashboard.find_for(project: environment.project, user: context[:current_user], path: args[:path], options: { environment: environment })
+ end
+ end
+ end
+end
diff --git a/app/graphql/types/environment_type.rb b/app/graphql/types/environment_type.rb
index c165c0ddc61..34a90006d03 100644
--- a/app/graphql/types/environment_type.rb
+++ b/app/graphql/types/environment_type.rb
@@ -15,5 +15,9 @@ module Types
field :state, GraphQL::STRING_TYPE, null: false,
description: 'State of the environment, for example: available/stopped'
+
+ field :metrics_dashboard, Types::Metrics::DashboardType, null: true,
+ description: 'Metrics dashboard schema for the environment',
+ resolver: Resolvers::Metrics::DashboardResolver
end
end
diff --git a/app/graphql/types/metrics/dashboard_type.rb b/app/graphql/types/metrics/dashboard_type.rb
new file mode 100644
index 00000000000..11e834013ca
--- /dev/null
+++ b/app/graphql/types/metrics/dashboard_type.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+module Types
+ module Metrics
+ # rubocop: disable Graphql/AuthorizeTypes
+ # Authorization is performed at environment level
+ class DashboardType < ::Types::BaseObject
+ graphql_name 'MetricsDashboard'
+
+ field :path, GraphQL::STRING_TYPE, null: true,
+ description: 'Path to a file with the dashboard definition'
+ end
+ # rubocop: enable Graphql/AuthorizeTypes
+ end
+end
diff --git a/app/models/performance_monitoring/prometheus_dashboard.rb b/app/models/performance_monitoring/prometheus_dashboard.rb
index 5f2df444fd0..30fb1935a27 100644
--- a/app/models/performance_monitoring/prometheus_dashboard.rb
+++ b/app/models/performance_monitoring/prometheus_dashboard.rb
@@ -4,27 +4,41 @@ module PerformanceMonitoring
class PrometheusDashboard
include ActiveModel::Model
- attr_accessor :dashboard, :panel_groups
+ attr_accessor :dashboard, :panel_groups, :path, :environment, :priority
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!)
+ class << self
+ def 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 find_for(project:, user:, path:, options: {})
+ dashboard_response = Gitlab::Metrics::Dashboard::Finder.find(project, user, options.merge(dashboard_path: path))
+ return unless dashboard_response[:status] == :success
+
+ new(
+ {
+ path: path,
+ environment: options[:environment]
+ }.merge(dashboard_response[:dashboard])
+ )
+ end
end
def to_yaml
- self.as_json(only: valid_attributes).to_yaml
+ self.as_json(only: yaml_valid_attributes).to_yaml
end
private
- def valid_attributes
+ def yaml_valid_attributes
%w(panel_groups panels metrics group priority type title y_label weight id unit label query query_range dashboard)
end
end
diff --git a/app/models/prometheus_alert.rb b/app/models/prometheus_alert.rb
index a1303f59129..fbc0281296f 100644
--- a/app/models/prometheus_alert.rb
+++ b/app/models/prometheus_alert.rb
@@ -56,7 +56,8 @@ class PrometheusAlert < ApplicationRecord
"for" => "5m",
"labels" => {
"gitlab" => "hook",
- "gitlab_alert_id" => prometheus_metric_id
+ "gitlab_alert_id" => prometheus_metric_id,
+ "gitlab_prometheus_alert_id" => id
}
}
end