summaryrefslogtreecommitdiff
path: root/lib/api
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-14 18:09:54 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-14 18:09:54 +0000
commitf697dc5e76dfc5894df006d53b2b7e751653cf05 (patch)
tree1387cd225039e611f3683f96b318bb17d4c422cb /lib/api
parent874ead9c3a50de4c4ca4551eaf5b7eb976d26b50 (diff)
downloadgitlab-ce-f697dc5e76dfc5894df006d53b2b7e751653cf05.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/api')
-rw-r--r--lib/api/api.rb1
-rw-r--r--lib/api/entities/metrics/dashboard/annotation.rb19
-rw-r--r--lib/api/metrics/dashboard/annotations.rb41
3 files changed, 61 insertions, 0 deletions
diff --git a/lib/api/api.rb b/lib/api/api.rb
index eb7f47de9e2..de9a3120d90 100644
--- a/lib/api/api.rb
+++ b/lib/api/api.rb
@@ -152,6 +152,7 @@ module API
mount ::API::Members
mount ::API::MergeRequestDiffs
mount ::API::MergeRequests
+ mount ::API::Metrics::Dashboard::Annotations
mount ::API::Namespaces
mount ::API::Notes
mount ::API::Discussions
diff --git a/lib/api/entities/metrics/dashboard/annotation.rb b/lib/api/entities/metrics/dashboard/annotation.rb
new file mode 100644
index 00000000000..66bd09d84f9
--- /dev/null
+++ b/lib/api/entities/metrics/dashboard/annotation.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+module API
+ module Entities
+ module Metrics
+ module Dashboard
+ class Annotation < Grape::Entity
+ expose :id
+ expose :starting_at
+ expose :ending_at
+ expose :dashboard_path
+ expose :description
+ expose :environment_id
+ expose :cluster_id
+ end
+ end
+ end
+ end
+end
diff --git a/lib/api/metrics/dashboard/annotations.rb b/lib/api/metrics/dashboard/annotations.rb
new file mode 100644
index 00000000000..691abac863a
--- /dev/null
+++ b/lib/api/metrics/dashboard/annotations.rb
@@ -0,0 +1,41 @@
+# frozen_string_literal: true
+
+module API
+ module Metrics
+ module Dashboard
+ class Annotations < Grape::API
+ desc 'Create a new monitoring dashboard annotation' do
+ success Entities::Metrics::Dashboard::Annotation
+ end
+
+ params do
+ requires :starting_at, type: DateTime,
+ desc: 'Date time indicating starting moment to which the annotation relates.'
+ optional :ending_at, type: DateTime,
+ desc: 'Date time indicating ending moment to which the annotation relates.'
+ requires :dashboard_path, type: String,
+ desc: 'The path to a file defining the dashboard on which the annotation should be added'
+ requires :description, type: String, desc: 'The description of the annotation'
+ end
+
+ resource :environments do
+ post ':id/metrics_dashboard/annotations' do
+ environment = ::Environment.find(params[:id])
+
+ not_found! unless Feature.enabled?(:metrics_dashboard_annotations, environment.project)
+
+ forbidden! unless can?(current_user, :create_metrics_dashboard_annotation, environment)
+
+ result = ::Metrics::Dashboard::Annotations::CreateService.new(current_user, declared(params).merge(environment: environment)).execute
+
+ if result[:status] == :success
+ present result[:annotation], with: Entities::Metrics::Dashboard::Annotation
+ else
+ error!(result, 400)
+ end
+ end
+ end
+ end
+ end
+ end
+end