summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-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
-rw-r--r--lib/gitlab/background_migration/backfill_deployment_clusters_from_deployments.rb19
-rw-r--r--lib/gitlab/jira_import/labels_importer.rb17
-rw-r--r--lib/gitlab/legacy_github_import/client.rb7
6 files changed, 88 insertions, 16 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
diff --git a/lib/gitlab/background_migration/backfill_deployment_clusters_from_deployments.rb b/lib/gitlab/background_migration/backfill_deployment_clusters_from_deployments.rb
new file mode 100644
index 00000000000..9778f360e87
--- /dev/null
+++ b/lib/gitlab/background_migration/backfill_deployment_clusters_from_deployments.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module BackgroundMigration
+ # Backfill deployment_clusters for a range of deployments
+ class BackfillDeploymentClustersFromDeployments
+ def perform(start_id, end_id)
+ ActiveRecord::Base.connection.execute <<~SQL
+ INSERT INTO deployment_clusters (deployment_id, cluster_id)
+ SELECT deployments.id, deployments.cluster_id
+ FROM deployments
+ WHERE deployments.cluster_id IS NOT NULL
+ AND deployments.id BETWEEN #{start_id} AND #{end_id}
+ ON CONFLICT DO NOTHING
+ SQL
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/jira_import/labels_importer.rb b/lib/gitlab/jira_import/labels_importer.rb
index 142a2da5be9..35c434e48a4 100644
--- a/lib/gitlab/jira_import/labels_importer.rb
+++ b/lib/gitlab/jira_import/labels_importer.rb
@@ -11,28 +11,19 @@ module Gitlab
end
def execute
- create_import_label(project)
+ cache_import_label(project)
import_jira_labels
end
private
- def create_import_label(project)
- label = Labels::CreateService.new(build_label_attrs(project)).execute(project: project)
- raise Projects::ImportService::Error, _('Failed to create import label for jira import.') unless label
+ def cache_import_label(project)
+ label = project.jira_imports.by_jira_project_key(jira_project_key).last.label
+ raise Projects::ImportService::Error, _('Failed to find import label for jira import.') unless label
JiraImport.cache_import_label_id(project.id, label.id)
end
- def build_label_attrs(project)
- import_start_time = project&.import_state&.last_update_started_at || Time.now
- title = "jira-import-#{import_start_time.strftime('%Y-%m-%d-%H-%M-%S')}"
- description = "Label for issues that were imported from jira on #{import_start_time.strftime('%Y-%m-%d %H:%M:%S')}"
- color = "#{Label.color_for(title)}"
-
- { title: title, description: description, color: color }
- end
-
def import_jira_labels
# todo: import jira labels, see https://gitlab.com/gitlab-org/gitlab/-/issues/212651
job_waiter
diff --git a/lib/gitlab/legacy_github_import/client.rb b/lib/gitlab/legacy_github_import/client.rb
index 34634d20a16..f7eaafeb446 100644
--- a/lib/gitlab/legacy_github_import/client.rb
+++ b/lib/gitlab/legacy_github_import/client.rb
@@ -6,13 +6,14 @@ module Gitlab
GITHUB_SAFE_REMAINING_REQUESTS = 100
GITHUB_SAFE_SLEEP_TIME = 500
- attr_reader :access_token, :host, :api_version
+ attr_reader :access_token, :host, :api_version, :wait_for_rate_limit_reset
- def initialize(access_token, host: nil, api_version: 'v3')
+ def initialize(access_token, host: nil, api_version: 'v3', wait_for_rate_limit_reset: true)
@access_token = access_token
@host = host.to_s.sub(%r{/+\z}, '')
@api_version = api_version
@users = {}
+ @wait_for_rate_limit_reset = wait_for_rate_limit_reset
if access_token
::Octokit.auto_paginate = false
@@ -120,7 +121,7 @@ module Gitlab
end
def request(method, *args, &block)
- sleep rate_limit_sleep_time if rate_limit_exceed?
+ sleep rate_limit_sleep_time if wait_for_rate_limit_reset && rate_limit_exceed?
data = api.__send__(method, *args) # rubocop:disable GitlabSecurity/PublicSend
return data unless data.is_a?(Array)