summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-01-15 18:08:34 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-01-15 18:08:34 +0000
commit571d993b49313dd806bd3f6af16d36c26d9d28ca (patch)
tree06bd12c4b56b97881aef8a00d4d46698de1eb63f /lib
parent9044365a91112d426fbbfba07eca595652bbe2df (diff)
downloadgitlab-ce-571d993b49313dd806bd3f6af16d36c26d9d28ca.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r--lib/api/entities.rb7
-rw-r--r--lib/gitlab/background_migration/activate_prometheus_services_for_shared_cluster_applications.rb52
-rw-r--r--lib/gitlab/git/gitmodules_parser.rb2
-rw-r--r--lib/gitlab/group_search_results.rb2
-rw-r--r--lib/gitlab/metrics/dashboard/stages/endpoint_inserter.rb2
-rw-r--r--lib/gitlab/sidekiq_config.rb85
-rw-r--r--lib/gitlab/sidekiq_config/cli_methods.rb43
-rw-r--r--lib/tasks/sidekiq.rake25
8 files changed, 155 insertions, 63 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index 74f8edb0784..a2813d0e063 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -613,6 +613,7 @@ module API
end
class ProtectedBranch < Grape::Entity
+ expose :id
expose :name
expose :push_access_levels, using: Entities::ProtectedRefAccess
expose :merge_access_levels, using: Entities::ProtectedRefAccess
@@ -1128,7 +1129,11 @@ module API
end
class ProjectServiceBasic < Grape::Entity
- expose :id, :title, :created_at, :updated_at, :active
+ expose :id, :title
+ expose :slug do |service|
+ service.to_param.dasherize
+ end
+ expose :created_at, :updated_at, :active
expose :commit_events, :push_events, :issues_events, :confidential_issues_events
expose :merge_requests_events, :tag_push_events, :note_events
expose :confidential_note_events, :pipeline_events, :wiki_page_events
diff --git a/lib/gitlab/background_migration/activate_prometheus_services_for_shared_cluster_applications.rb b/lib/gitlab/background_migration/activate_prometheus_services_for_shared_cluster_applications.rb
new file mode 100644
index 00000000000..19f5821d449
--- /dev/null
+++ b/lib/gitlab/background_migration/activate_prometheus_services_for_shared_cluster_applications.rb
@@ -0,0 +1,52 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module BackgroundMigration
+ # Create missing PrometheusServices records or sets active attribute to true
+ # for all projects which belongs to cluster with Prometheus Application installed.
+ class ActivatePrometheusServicesForSharedClusterApplications
+ module Migratable
+ # Migration model namespace isolated from application code.
+ class PrometheusService < ActiveRecord::Base
+ self.inheritance_column = :_type_disabled
+ self.table_name = 'services'
+
+ default_scope { where("services.type = 'PrometheusService'") }
+
+ def self.for_project(project_id)
+ new(
+ project_id: project_id,
+ active: true,
+ properties: '{}',
+ type: 'PrometheusService',
+ template: false,
+ push_events: true,
+ issues_events: true,
+ merge_requests_events: true,
+ tag_push_events: true,
+ note_events: true,
+ category: 'monitoring',
+ default: false,
+ wiki_page_events: true,
+ pipeline_events: true,
+ confidential_issues_events: true,
+ commit_events: true,
+ job_events: true,
+ confidential_note_events: true,
+ deployment_events: false
+ )
+ end
+
+ def managed?
+ properties == '{}'
+ end
+ end
+ end
+
+ def perform(project_id)
+ service = Migratable::PrometheusService.find_by(project_id: project_id) || Migratable::PrometheusService.for_project(project_id)
+ service.update!(active: true) if service.managed?
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/git/gitmodules_parser.rb b/lib/gitlab/git/gitmodules_parser.rb
index 575e12390cd..92940c352d3 100644
--- a/lib/gitlab/git/gitmodules_parser.rb
+++ b/lib/gitlab/git/gitmodules_parser.rb
@@ -71,7 +71,7 @@ module Gitlab
# Convert from an indexed by name to an array indexed by path
# If a submodule doesn't have a path, it is considered bogus
# and is ignored
- submodules_by_name.each_with_object({}) do |(name, data), results|
+ submodules_by_name.each_with_object({}) do |(_name, data), results|
path = data.delete 'path'
next unless path
diff --git a/lib/gitlab/group_search_results.rb b/lib/gitlab/group_search_results.rb
index 334642f252e..8597903ad00 100644
--- a/lib/gitlab/group_search_results.rb
+++ b/lib/gitlab/group_search_results.rb
@@ -30,7 +30,7 @@ module Gitlab
# rubocop:enable CodeReuse/ActiveRecord
def issuable_params
- super.merge(group_id: group.id)
+ super.merge(group_id: group.id, include_subgroups: true)
end
end
end
diff --git a/lib/gitlab/metrics/dashboard/stages/endpoint_inserter.rb b/lib/gitlab/metrics/dashboard/stages/endpoint_inserter.rb
index 4f5e9a98799..e085f551952 100644
--- a/lib/gitlab/metrics/dashboard/stages/endpoint_inserter.rb
+++ b/lib/gitlab/metrics/dashboard/stages/endpoint_inserter.rb
@@ -16,7 +16,7 @@ module Gitlab
private
def endpoint_for_metric(metric)
- if ENV['USE_SAMPLE_METRICS']
+ if params[:sample_metrics]
Gitlab::Routing.url_helpers.sample_metrics_project_environment_path(
project,
params[:environment],
diff --git a/lib/gitlab/sidekiq_config.rb b/lib/gitlab/sidekiq_config.rb
index ffceeb68f20..b246c507e9e 100644
--- a/lib/gitlab/sidekiq_config.rb
+++ b/lib/gitlab/sidekiq_config.rb
@@ -1,78 +1,53 @@
# frozen_string_literal: true
require 'yaml'
-require 'set'
module Gitlab
module SidekiqConfig
- QUEUE_CONFIG_PATHS = begin
- result = %w[app/workers/all_queues.yml]
- result << 'ee/app/workers/all_queues.yml' if Gitlab.ee?
- result
- end.freeze
+ class << self
+ include Gitlab::SidekiqConfig::CliMethods
- # This method is called by `ee/bin/sidekiq-cluster` in EE, which runs outside
- # of bundler/Rails context, so we cannot use any gem or Rails methods.
- def self.worker_queues(rails_path = Rails.root.to_s)
- @worker_queues ||= {}
-
- @worker_queues[rails_path] ||= QUEUE_CONFIG_PATHS.flat_map do |path|
- full_path = File.join(rails_path, path)
-
- File.exist?(full_path) ? YAML.load_file(full_path) : []
+ def redis_queues
+ # Not memoized, because this can change during the life of the application
+ Sidekiq::Queue.all.map(&:name)
end
- end
-
- # This method is called by `ee/bin/sidekiq-cluster` in EE, which runs outside
- # of bundler/Rails context, so we cannot use any gem or Rails methods.
- def self.expand_queues(queues, all_queues = self.worker_queues)
- return [] if queues.empty?
- queues_set = all_queues.to_set
-
- queues.flat_map do |queue|
- [queue, *queues_set.grep(/\A#{queue}:/)]
+ def config_queues
+ @config_queues ||= begin
+ config = YAML.load_file(Rails.root.join('config/sidekiq_queues.yml'))
+ config[:queues].map(&:first)
+ end
end
- end
- def self.redis_queues
- # Not memoized, because this can change during the life of the application
- Sidekiq::Queue.all.map(&:name)
- end
+ def cron_workers
+ @cron_workers ||= Settings.cron_jobs.map { |job_name, options| options['job_class'].constantize }
+ end
- def self.config_queues
- @config_queues ||= begin
- config = YAML.load_file(Rails.root.join('config/sidekiq_queues.yml'))
- config[:queues].map(&:first)
+ def workers
+ @workers ||= begin
+ result = find_workers(Rails.root.join('app', 'workers'))
+ result.concat(find_workers(Rails.root.join('ee', 'app', 'workers'))) if Gitlab.ee?
+ result
+ end
end
- end
- def self.cron_workers
- @cron_workers ||= Settings.cron_jobs.map { |job_name, options| options['job_class'].constantize }
- end
+ private
- def self.workers
- @workers ||= begin
- result = find_workers(Rails.root.join('app', 'workers'))
- result.concat(find_workers(Rails.root.join('ee', 'app', 'workers'))) if Gitlab.ee?
- result
- end
- end
+ def find_workers(root)
+ concerns = root.join('concerns').to_s
- def self.find_workers(root)
- concerns = root.join('concerns').to_s
+ workers = Dir[root.join('**', '*.rb')]
+ .reject { |path| path.start_with?(concerns) }
- workers = Dir[root.join('**', '*.rb')]
- .reject { |path| path.start_with?(concerns) }
+ workers.map! do |path|
+ ns = Pathname.new(path).relative_path_from(root).to_s.gsub('.rb', '')
- workers.map! do |path|
- ns = Pathname.new(path).relative_path_from(root).to_s.gsub('.rb', '')
+ ns.camelize.constantize
+ end
- ns.camelize.constantize
+ # Skip things that aren't workers
+ workers.select { |w| w < Sidekiq::Worker }
end
-
- # Skip things that aren't workers
- workers.select { |w| w < Sidekiq::Worker }
end
end
end
diff --git a/lib/gitlab/sidekiq_config/cli_methods.rb b/lib/gitlab/sidekiq_config/cli_methods.rb
new file mode 100644
index 00000000000..1ce46289e81
--- /dev/null
+++ b/lib/gitlab/sidekiq_config/cli_methods.rb
@@ -0,0 +1,43 @@
+# frozen_string_literal: true
+
+require 'yaml'
+require 'set'
+
+# These methods are called by `sidekiq-cluster`, which runs outside of
+# the bundler/Rails context, so we cannot use any gem or Rails methods.
+module Gitlab
+ module SidekiqConfig
+ module CliMethods
+ # The methods in this module are used as module methods
+ # rubocop:disable Gitlab/ModuleWithInstanceVariables
+ extend self
+
+ QUEUE_CONFIG_PATHS = begin
+ result = %w[app/workers/all_queues.yml]
+ result << 'ee/app/workers/all_queues.yml' if Gitlab.ee?
+ result
+ end.freeze
+
+ def worker_queues(rails_path = Rails.root.to_s)
+ @worker_queues ||= {}
+
+ @worker_queues[rails_path] ||= QUEUE_CONFIG_PATHS.flat_map do |path|
+ full_path = File.join(rails_path, path)
+
+ File.exist?(full_path) ? YAML.load_file(full_path) : []
+ end
+ end
+
+ def expand_queues(queues, all_queues = self.worker_queues)
+ return [] if queues.empty?
+
+ queues_set = all_queues.to_set
+
+ queues.flat_map do |queue|
+ [queue, *queues_set.grep(/\A#{queue}:/)]
+ end
+ end
+ # rubocop:enable Gitlab/ModuleWithInstanceVariables
+ end
+ end
+end
diff --git a/lib/tasks/sidekiq.rake b/lib/tasks/sidekiq.rake
index dd9ce86f7ca..cb9f4c751ed 100644
--- a/lib/tasks/sidekiq.rake
+++ b/lib/tasks/sidekiq.rake
@@ -1,21 +1,38 @@
namespace :sidekiq do
- desc "GitLab | Stop sidekiq"
+ def deprecation_warning!
+ warn <<~WARNING
+ This task is deprecated and will be removed in 13.0 as it is thought to be unused.
+
+ If you are using this task, please comment on the below issue:
+ https://gitlab.com/gitlab-org/gitlab/issues/196731
+ WARNING
+ end
+
+ desc "[DEPRECATED] GitLab | Stop sidekiq"
task :stop do
+ deprecation_warning!
+
system(*%w(bin/background_jobs stop))
end
- desc "GitLab | Start sidekiq"
+ desc "[DEPRECATED] GitLab | Start sidekiq"
task :start do
+ deprecation_warning!
+
system(*%w(bin/background_jobs start))
end
- desc 'GitLab | Restart sidekiq'
+ desc '[DEPRECATED] GitLab | Restart sidekiq'
task :restart do
+ deprecation_warning!
+
system(*%w(bin/background_jobs restart))
end
- desc "GitLab | Start sidekiq with launchd on Mac OS X"
+ desc "[DEPRECATED] GitLab | Start sidekiq with launchd on Mac OS X"
task :launchd do
+ deprecation_warning!
+
system(*%w(bin/background_jobs start_no_deamonize))
end
end