summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/api/group_labels.rb48
-rw-r--r--lib/api/helpers/label_helpers.rb42
-rw-r--r--lib/api/labels.rb66
-rw-r--r--lib/gitlab/cluster/puma_worker_killer_initializer.rb14
-rw-r--r--lib/quality/test_level.rb26
5 files changed, 161 insertions, 35 deletions
diff --git a/lib/api/group_labels.rb b/lib/api/group_labels.rb
index cb044d4095f..7585293031f 100644
--- a/lib/api/group_labels.rb
+++ b/lib/api/group_labels.rb
@@ -26,6 +26,18 @@ module API
get_labels(user_group, Entities::GroupLabel, include_ancestor_groups: params[:include_ancestor_groups])
end
+ desc 'Get a single label' do
+ detail 'This feature was added in GitLab 12.4.'
+ success Entities::GroupLabel
+ end
+ params do
+ optional :include_ancestor_groups, type: Boolean, default: true,
+ desc: 'Include ancestor groups'
+ end
+ get ':id/labels/:name' do
+ get_label(user_group, Entities::GroupLabel, include_ancestor_groups: params[:include_ancestor_groups])
+ end
+
desc 'Create a new label' do
detail 'This feature was added in GitLab 11.8'
success Entities::GroupLabel
@@ -38,22 +50,21 @@ module API
end
desc 'Update an existing label. At least one optional parameter is required.' do
- detail 'This feature was added in GitLab 11.8'
+ detail 'This feature was added in GitLab 11.8 and deprecated in GitLab 12.4.'
success Entities::GroupLabel
end
params do
- requires :name, type: String, desc: 'The name of the label to be updated'
- optional :new_name, type: String, desc: 'The new name of the label'
- optional :color, type: String, desc: "The new color of the label given in 6-digit hex notation with leading '#' sign (e.g. #FFAABB) or one of the allowed CSS color names"
- optional :description, type: String, desc: 'The new description of label'
- at_least_one_of :new_name, :color, :description
+ optional :label_id, type: Integer, desc: 'The id of the label to be updated'
+ optional :name, type: String, desc: 'The name of the label to be updated'
+ use :group_label_update_params
+ exactly_one_of :label_id, :name
end
put ':id/labels' do
update_label(user_group, Entities::GroupLabel)
end
desc 'Delete an existing label' do
- detail 'This feature was added in GitLab 11.8'
+ detail 'This feature was added in GitLab 11.8 and deprecated in GitLab 12.4.'
success Entities::GroupLabel
end
params do
@@ -62,6 +73,29 @@ module API
delete ':id/labels' do
delete_label(user_group)
end
+
+ desc 'Update an existing label. At least one optional parameter is required.' do
+ detail 'This feature was added in GitLab 12.4.'
+ success Entities::GroupLabel
+ end
+ params do
+ requires :name, type: String, desc: 'The name or id of the label to be updated'
+ use :group_label_update_params
+ end
+ put ':id/labels/:name' do
+ update_label(user_group, Entities::GroupLabel)
+ end
+
+ desc 'Delete an existing label' do
+ detail 'This feature was added in GitLab 12.4.'
+ success Entities::GroupLabel
+ end
+ params do
+ requires :name, type: String, desc: 'The name or id of the label to be deleted'
+ end
+ delete ':id/labels/:name' do
+ delete_label(user_group)
+ end
end
end
end
diff --git a/lib/api/helpers/label_helpers.rb b/lib/api/helpers/label_helpers.rb
index 126747e4f34..2fb2d9b79cf 100644
--- a/lib/api/helpers/label_helpers.rb
+++ b/lib/api/helpers/label_helpers.rb
@@ -11,6 +11,23 @@ module API
optional :description, type: String, desc: 'The description of label to be created'
end
+ params :label_update_params do
+ optional :new_name, type: String, desc: 'The new name of the label'
+ optional :color, type: String, desc: "The new color of the label given in 6-digit hex notation with leading '#' sign (e.g. #FFAABB) or one of the allowed CSS color names"
+ optional :description, type: String, desc: 'The new description of label'
+ end
+
+ params :project_label_update_params do
+ use :label_update_params
+ optional :priority, type: Integer, desc: 'The priority of the label', allow_blank: true
+ at_least_one_of :new_name, :color, :description, :priority
+ end
+
+ params :group_label_update_params do
+ use :label_update_params
+ at_least_one_of :new_name, :color, :description
+ end
+
def find_label(parent, id_or_title, include_ancestor_groups: true)
labels = available_labels_for(parent, include_ancestor_groups: include_ancestor_groups)
label = labels.find_by_id(id_or_title) || labels.find_by_title(id_or_title)
@@ -26,6 +43,12 @@ module API
with_counts: params[:with_counts]
end
+ def get_label(parent, entity, include_ancestor_groups: true)
+ label = find_label(parent, params_id_or_title, include_ancestor_groups: include_ancestor_groups)
+
+ present label, with: entity, current_user: current_user, parent: parent
+ end
+
def create_label(parent, entity)
authorize! :admin_label, parent
@@ -57,6 +80,7 @@ module API
# params is used to update the label so we need to remove this field here
params.delete(:label_id)
+ params.delete(:name)
label = ::Labels::UpdateService.new(declared_params(include_missing: false)).execute(label)
render_validation_error!(label) unless label.valid?
@@ -80,6 +104,24 @@ module API
destroy_conditionally!(label)
end
+ def promote_label(parent)
+ authorize! :admin_label, parent
+
+ label = find_label(parent, params[:name], include_ancestor_groups: false)
+
+ begin
+ group_label = ::Labels::PromoteService.new(parent, current_user).execute(label)
+
+ if group_label
+ present group_label, with: Entities::GroupLabel, current_user: current_user, parent: parent.group
+ else
+ render_api_error!('Failed to promote project label to group label', 400)
+ end
+ rescue => error
+ render_api_error!(error.to_s, 400)
+ end
+ end
+
def params_id_or_title
@params_id_or_title ||= params[:label_id] || params[:name]
end
diff --git a/lib/api/labels.rb b/lib/api/labels.rb
index 12553cbbbfa..2b283d82e4a 100644
--- a/lib/api/labels.rb
+++ b/lib/api/labels.rb
@@ -25,6 +25,18 @@ module API
get_labels(user_project, Entities::ProjectLabel, include_ancestor_groups: params[:include_ancestor_groups])
end
+ desc 'Get a single label' do
+ detail 'This feature was added in GitLab 12.4.'
+ success Entities::ProjectLabel
+ end
+ params do
+ optional :include_ancestor_groups, type: Boolean, default: true,
+ desc: 'Include ancestor groups'
+ end
+ get ':id/labels/:name' do
+ get_label(user_project, Entities::ProjectLabel, include_ancestor_groups: params[:include_ancestor_groups])
+ end
+
desc 'Create a new label' do
success Entities::ProjectLabel
end
@@ -37,23 +49,21 @@ module API
end
desc 'Update an existing label. At least one optional parameter is required.' do
+ detail 'This feature was deprecated in GitLab 12.4.'
success Entities::ProjectLabel
end
params do
optional :label_id, type: Integer, desc: 'The id of the label to be updated'
optional :name, type: String, desc: 'The name of the label to be updated'
- optional :new_name, type: String, desc: 'The new name of the label'
- optional :color, type: String, desc: "The new color of the label given in 6-digit hex notation with leading '#' sign (e.g. #FFAABB) or one of the allowed CSS color names"
- optional :description, type: String, desc: 'The new description of label'
- optional :priority, type: Integer, desc: 'The priority of the label', allow_blank: true
+ use :project_label_update_params
exactly_one_of :label_id, :name
- at_least_one_of :new_name, :color, :description, :priority
end
put ':id/labels' do
update_label(user_project, Entities::ProjectLabel)
end
desc 'Delete an existing label' do
+ detail 'This feature was deprecated in GitLab 12.4.'
success Entities::ProjectLabel
end
params do
@@ -66,28 +76,48 @@ module API
end
desc 'Promote a label to a group label' do
- detail 'This feature was added in GitLab 12.3'
+ detail 'This feature was added in GitLab 12.3 and deprecated in GitLab 12.4.'
success Entities::GroupLabel
end
params do
requires :name, type: String, desc: 'The name of the label to be promoted'
end
put ':id/labels/promote' do
- authorize! :admin_label, user_project
+ promote_label(user_project)
+ end
- label = find_label(user_project, params[:name], include_ancestor_groups: false)
+ desc 'Update an existing label. At least one optional parameter is required.' do
+ detail 'This feature was added in GitLab 12.4.'
+ success Entities::ProjectLabel
+ end
+ params do
+ requires :name, type: String, desc: 'The name or id of the label to be updated'
+ use :project_label_update_params
+ end
+ put ':id/labels/:name' do
+ update_label(user_project, Entities::ProjectLabel)
+ end
- begin
- group_label = ::Labels::PromoteService.new(user_project, current_user).execute(label)
+ desc 'Delete an existing label' do
+ detail 'This feature was added in GitLab 12.4.'
+ success Entities::ProjectLabel
+ end
+ params do
+ requires :name, type: String, desc: 'The name or id of the label to be deleted'
+ end
+ delete ':id/labels/:name' do
+ delete_label(user_project)
+ end
- if group_label
- present group_label, with: Entities::GroupLabel, current_user: current_user, parent: user_project.group
- else
- render_api_error!('Failed to promote project label to group label', 400)
- end
- rescue => error
- render_api_error!(error.to_s, 400)
- end
+ desc 'Promote a label to a group label' do
+ detail 'This feature was added in GitLab 12.4.'
+ success Entities::GroupLabel
+ end
+ params do
+ requires :name, type: String, desc: 'The name or id of the label to be promoted'
+ end
+ put ':id/labels/:name/promote' do
+ promote_label(user_project)
end
end
end
diff --git a/lib/gitlab/cluster/puma_worker_killer_initializer.rb b/lib/gitlab/cluster/puma_worker_killer_initializer.rb
index 4affc52b7b0..a8440b63baa 100644
--- a/lib/gitlab/cluster/puma_worker_killer_initializer.rb
+++ b/lib/gitlab/cluster/puma_worker_killer_initializer.rb
@@ -3,7 +3,7 @@
module Gitlab
module Cluster
class PumaWorkerKillerInitializer
- def self.start(puma_options, puma_per_worker_max_memory_mb: 650)
+ def self.start(puma_options, puma_per_worker_max_memory_mb: 850, puma_master_max_memory_mb: 550)
require 'puma_worker_killer'
PumaWorkerKiller.config do |config|
@@ -12,10 +12,9 @@ module Gitlab
# not each worker as is the case with GITLAB_UNICORN_MEMORY_MAX
worker_count = puma_options[:workers] || 1
# The Puma Worker Killer checks the total RAM used by both the master
- # and worker processes. Bump the limits to N+1 instead of N workers
- # to account for this:
+ # and worker processes.
# https://github.com/schneems/puma_worker_killer/blob/v0.1.0/lib/puma_worker_killer/puma_memory.rb#L57
- config.ram = (worker_count + 1) * puma_per_worker_max_memory_mb
+ config.ram = puma_master_max_memory_mb + (worker_count * puma_per_worker_max_memory_mb)
config.frequency = 20 # seconds
@@ -23,10 +22,9 @@ module Gitlab
# of available RAM.
config.percent_usage = 0.98
- # Ideally we'll never hit the maximum amount of memory. If so the worker
- # is restarted already, thus periodically restarting workers shouldn't be
- # needed.
- config.rolling_restart_frequency = false
+ # Ideally we'll never hit the maximum amount of memory. Restart the workers
+ # regularly rather than rely on OOM behavior for periodic restarting.
+ config.rolling_restart_frequency = 43200 # 12 hours in seconds.
observer = Gitlab::Cluster::PumaWorkerKillerObserver.new
config.pre_term = observer.callback
diff --git a/lib/quality/test_level.rb b/lib/quality/test_level.rb
index a65657dadd0..b7822adf6ed 100644
--- a/lib/quality/test_level.rb
+++ b/lib/quality/test_level.rb
@@ -53,11 +53,11 @@ module Quality
end
def pattern(level)
- @patterns[level] ||= "#{prefix}spec/{#{TEST_LEVEL_FOLDERS.fetch(level).join(',')}}{,/**/}*_spec.rb"
+ @patterns[level] ||= "#{prefix}spec/#{folders_pattern(level)}{,/**/}*_spec.rb"
end
def regexp(level)
- @regexps[level] ||= Regexp.new("#{prefix}spec/(#{TEST_LEVEL_FOLDERS.fetch(level).join('|')})").freeze
+ @regexps[level] ||= Regexp.new("#{prefix}spec/#{folders_regex(level)}").freeze
end
def level_for(file_path)
@@ -72,5 +72,27 @@ module Quality
raise UnknownTestLevelError, "Test level for #{file_path} couldn't be set. Please rename the file properly or change the test level detection regexes in #{__FILE__}."
end
end
+
+ private
+
+ def folders_pattern(level)
+ case level
+ # Geo specs aren't in a specific folder, but they all have the :geo tag, so we must search for them globally
+ when :all, :geo
+ '**'
+ else
+ "{#{TEST_LEVEL_FOLDERS.fetch(level).join(',')}}"
+ end
+ end
+
+ def folders_regex(level)
+ case level
+ # Geo specs aren't in a specific folder, but they all have the :geo tag, so we must search for them globally
+ when :all, :geo
+ ''
+ else
+ "(#{TEST_LEVEL_FOLDERS.fetch(level).join('|')})"
+ end
+ end
end
end