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

annotations.rb « dashboard « metrics « api « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ace772842c0e873670a96907a80ae08088783fc7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# frozen_string_literal: true

module API
  module Metrics
    module Dashboard
      class Annotations < ::API::Base
        feature_category :metrics
        urgency :low

        desc 'Create a new annotation' do
          detail 'Creates a new monitoring dashboard annotation'
          success Entities::Metrics::Dashboard::Annotation
          failure [
            { code: 400, message: 'Bad Request' },
            { code: 401, message: 'Unauthorized' },
            { code: 404, message: 'Not Found' }
          ]
          tags %w[dashboard_annotations]
        end

        ANNOTATIONS_SOURCES = [
          { class: ::Environment, resource: :environments, create_service_param_key: :environment },
          { class: ::Clusters::Cluster, resource: :clusters, create_service_param_key: :cluster }
        ].freeze

        ANNOTATIONS_SOURCES.each do |annotations_source|
          resource annotations_source[:resource] do
            params do
              requires :starting_at, type: DateTime,
                                     desc: 'Date time string, ISO 8601 formatted, such as 2016-03-11T03:45:40Z.'\
                                      'Timestamp marking start point of annotation.'
              optional :ending_at, type: DateTime,
                                   desc: 'Date time string, ISO 8601 formatted, such as 2016-03-11T03:45:40Z.'\
                                    'Timestamp marking end point of annotation.'\
                                    'When not supplied, an annotation displays as a single event at the start point.'
              requires :dashboard_path, type: String, coerce_with: -> (val) { CGI.unescape(val) },
                                        desc: 'ID of the dashboard which needs to be annotated.'\
                                          'Treated as a CGI-escaped path, and automatically un-escaped.'
              requires :description, type: String, desc: 'Description of the annotation.'
            end

            post ':id/metrics_dashboard/annotations' do
              not_found!
            end
          end
        end
      end
    end
  end
end