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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-10 15:08:16 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-10 15:08:16 +0300
commit1fa79760ad2d4bd67f5c5a27f372a7533b9b7c69 (patch)
treeffdfbd9113743831ff4f1290959a62cf6567fde5 /lib
parent82fa8a3d1e8466ef36b58604d20fcc145ea12118 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/ci/config/entry/inherit.rb4
-rw-r--r--lib/gitlab/ci/config/entry/inherit/default.rb51
-rw-r--r--lib/gitlab/ci/config/entry/inherit/variables.rb48
-rw-r--r--lib/gitlab/ci/config/entry/processable.rb11
-rw-r--r--lib/gitlab/metrics/dashboard/finder.rb6
-rw-r--r--lib/gitlab/metrics/dashboard/service_selector.rb3
-rw-r--r--lib/gitlab/middleware/go.rb3
-rw-r--r--lib/gitlab/sidekiq_middleware/server_metrics.rb4
-rw-r--r--lib/sentry/client/issue.rb18
9 files changed, 135 insertions, 13 deletions
diff --git a/lib/gitlab/ci/config/entry/inherit.rb b/lib/gitlab/ci/config/entry/inherit.rb
index 540f1e62c6c..b806d77b155 100644
--- a/lib/gitlab/ci/config/entry/inherit.rb
+++ b/lib/gitlab/ci/config/entry/inherit.rb
@@ -16,11 +16,11 @@ module Gitlab
validates :config, allowed_keys: ALLOWED_KEYS
end
- entry :default, ::Gitlab::Config::Entry::Boolean,
+ entry :default, ::Gitlab::Ci::Config::Entry::Inherit::Default,
description: 'Indicates whether to inherit `default:`.',
default: true
- entry :variables, ::Gitlab::Config::Entry::Boolean,
+ entry :variables, ::Gitlab::Ci::Config::Entry::Inherit::Variables,
description: 'Indicates whether to inherit `variables:`.',
default: true
end
diff --git a/lib/gitlab/ci/config/entry/inherit/default.rb b/lib/gitlab/ci/config/entry/inherit/default.rb
new file mode 100644
index 00000000000..74386baf62f
--- /dev/null
+++ b/lib/gitlab/ci/config/entry/inherit/default.rb
@@ -0,0 +1,51 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Ci
+ class Config
+ module Entry
+ ##
+ # This class represents a default inherit entry
+ #
+ class Inherit
+ class Default < ::Gitlab::Config::Entry::Simplifiable
+ strategy :BooleanStrategy, if: -> (config) { [true, false].include?(config) }
+ strategy :ArrayStrategy, if: -> (config) { config.is_a?(Array) }
+
+ class BooleanStrategy < ::Gitlab::Config::Entry::Boolean
+ def inherit?(_key)
+ value
+ end
+ end
+
+ class ArrayStrategy < ::Gitlab::Config::Entry::Node
+ include ::Gitlab::Config::Entry::Validatable
+
+ ALLOWED_VALUES = ::Gitlab::Ci::Config::Entry::Default::ALLOWED_KEYS.map(&:to_s).freeze
+
+ validations do
+ validates :config, type: Array
+ validates :config, array_of_strings: true
+ validates :config, allowed_array_values: { in: ALLOWED_VALUES }
+ end
+
+ def inherit?(key)
+ value.include?(key.to_s)
+ end
+ end
+
+ class UnknownStrategy < ::Gitlab::Config::Entry::Node
+ def errors
+ ["#{location} should be a bool or array of strings"]
+ end
+
+ def inherit?(key)
+ false
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/ci/config/entry/inherit/variables.rb b/lib/gitlab/ci/config/entry/inherit/variables.rb
new file mode 100644
index 00000000000..aa68833bdb8
--- /dev/null
+++ b/lib/gitlab/ci/config/entry/inherit/variables.rb
@@ -0,0 +1,48 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Ci
+ class Config
+ module Entry
+ ##
+ # This class represents a variables inherit entry
+ #
+ class Inherit
+ class Variables < ::Gitlab::Config::Entry::Simplifiable
+ strategy :BooleanStrategy, if: -> (config) { [true, false].include?(config) }
+ strategy :ArrayStrategy, if: -> (config) { config.is_a?(Array) }
+
+ class BooleanStrategy < ::Gitlab::Config::Entry::Boolean
+ def inherit?(_key)
+ value
+ end
+ end
+
+ class ArrayStrategy < ::Gitlab::Config::Entry::Node
+ include ::Gitlab::Config::Entry::Validatable
+
+ validations do
+ validates :config, type: Array
+ validates :config, array_of_strings: true
+ end
+
+ def inherit?(key)
+ value.include?(key.to_s)
+ end
+ end
+
+ class UnknownStrategy < ::Gitlab::Config::Entry::Node
+ def errors
+ ["#{location} should be a bool or array of strings"]
+ end
+
+ def inherit?(key)
+ false
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/ci/config/entry/processable.rb b/lib/gitlab/ci/config/entry/processable.rb
index b4da48957b0..81211acbec7 100644
--- a/lib/gitlab/ci/config/entry/processable.rb
+++ b/lib/gitlab/ci/config/entry/processable.rb
@@ -94,7 +94,7 @@ module Gitlab
end
def overwrite_entry(deps, key, current_entry)
- return unless inherit_entry&.default_value
+ return unless inherit_entry&.default_entry&.inherit?(key)
return unless deps.default_entry
deps.default_entry[key] unless current_entry.specified?
@@ -111,11 +111,12 @@ module Gitlab
end
def root_and_job_variables_value
- if inherit_entry&.variables_value
- @root_variables_value.to_h.merge(variables_value.to_h) # rubocop:disable Gitlab/ModuleWithInstanceVariables
- else
- variables_value.to_h
+ root_variables = @root_variables_value.to_h # rubocop:disable Gitlab/ModuleWithInstanceVariables
+ root_variables = root_variables.select do |key, _|
+ inherit_entry&.variables_entry&.inherit?(key)
end
+
+ root_variables.merge(variables_value.to_h)
end
end
end
diff --git a/lib/gitlab/metrics/dashboard/finder.rb b/lib/gitlab/metrics/dashboard/finder.rb
index 3dd86c8685d..990fd57bf41 100644
--- a/lib/gitlab/metrics/dashboard/finder.rb
+++ b/lib/gitlab/metrics/dashboard/finder.rb
@@ -29,9 +29,11 @@ module Gitlab
# Used by embedded dashboards.
# @param options - y_label [String] Y-Axis label of
# a panel. Used by embedded dashboards.
- # @param options - cluster [Cluster]
+ # @param options - cluster [Cluster]. Used by
+ # embedded and un-embedded dashboards.
# @param options - cluster_type [Symbol] The level of
- # cluster, one of [:admin, :project, :group]
+ # cluster, one of [:admin, :project, :group]. Used by
+ # embedded and un-embedded dashboards.
# @param options - grafana_url [String] URL pointing
# to a grafana dashboard panel
# @param options - prometheus_alert_id [Integer] ID of
diff --git a/lib/gitlab/metrics/dashboard/service_selector.rb b/lib/gitlab/metrics/dashboard/service_selector.rb
index 24ea85a5a95..993e508cbc6 100644
--- a/lib/gitlab/metrics/dashboard/service_selector.rb
+++ b/lib/gitlab/metrics/dashboard/service_selector.rb
@@ -3,7 +3,8 @@
# Responsible for determining which dashboard service should
# be used to fetch or generate a dashboard hash.
# The services can be considered in two categories - embeds
-# and dashboards. Embeds are all portions of dashboards.
+# and dashboards. Embed hashes are identical to dashboard hashes except
+# that they contain a subset of panels.
module Gitlab
module Metrics
module Dashboard
diff --git a/lib/gitlab/middleware/go.rb b/lib/gitlab/middleware/go.rb
index 53508938c49..abdbccd3aa8 100644
--- a/lib/gitlab/middleware/go.rb
+++ b/lib/gitlab/middleware/go.rb
@@ -53,8 +53,9 @@ module Gitlab
repository_url = if Gitlab::CurrentSettings.enabled_git_access_protocol == 'ssh'
shell = config.gitlab_shell
+ user = "#{shell.ssh_user}@" unless shell.ssh_user.empty?
port = ":#{shell.ssh_port}" unless shell.ssh_port == 22
- "ssh://#{shell.ssh_user}@#{shell.ssh_host}#{port}/#{path}.git"
+ "ssh://#{user}#{shell.ssh_host}#{port}/#{path}.git"
else
"#{project_url}.git"
end
diff --git a/lib/gitlab/sidekiq_middleware/server_metrics.rb b/lib/gitlab/sidekiq_middleware/server_metrics.rb
index fa7f56b8d9c..9615febc5d8 100644
--- a/lib/gitlab/sidekiq_middleware/server_metrics.rb
+++ b/lib/gitlab/sidekiq_middleware/server_metrics.rb
@@ -45,6 +45,8 @@ module Gitlab
labels[:job_status] = job_succeeded ? "done" : "fail"
@metrics[:sidekiq_jobs_cpu_seconds].observe(labels, job_thread_cputime)
@metrics[:sidekiq_jobs_completion_seconds].observe(labels, monotonic_time)
+ @metrics[:sidekiq_jobs_db_seconds].observe(labels, ActiveRecord::LogSubscriber.runtime / 1000)
+ @metrics[:sidekiq_jobs_gitaly_seconds].observe(labels, Gitlab::GitalyClient.query_time)
end
end
@@ -54,6 +56,8 @@ module Gitlab
{
sidekiq_jobs_cpu_seconds: ::Gitlab::Metrics.histogram(:sidekiq_jobs_cpu_seconds, 'Seconds of cpu time to run Sidekiq job', {}, SIDEKIQ_LATENCY_BUCKETS),
sidekiq_jobs_completion_seconds: ::Gitlab::Metrics.histogram(:sidekiq_jobs_completion_seconds, 'Seconds to complete Sidekiq job', {}, SIDEKIQ_LATENCY_BUCKETS),
+ sidekiq_jobs_db_seconds: ::Gitlab::Metrics.histogram(:sidekiq_jobs_db_seconds, 'Seconds of database time to run Sidekiq job', {}, SIDEKIQ_LATENCY_BUCKETS),
+ sidekiq_jobs_gitaly_seconds: ::Gitlab::Metrics.histogram(:sidekiq_jobs_gitaly_seconds, 'Seconds of Gitaly time to run Sidekiq job', {}, SIDEKIQ_LATENCY_BUCKETS),
sidekiq_jobs_queue_duration_seconds: ::Gitlab::Metrics.histogram(:sidekiq_jobs_queue_duration_seconds, 'Duration in seconds that a Sidekiq job was queued before being executed', {}, SIDEKIQ_LATENCY_BUCKETS),
sidekiq_jobs_failed_total: ::Gitlab::Metrics.counter(:sidekiq_jobs_failed_total, 'Sidekiq jobs failed'),
sidekiq_jobs_retried_total: ::Gitlab::Metrics.counter(:sidekiq_jobs_retried_total, 'Sidekiq jobs retried'),
diff --git a/lib/sentry/client/issue.rb b/lib/sentry/client/issue.rb
index 1c5d88e8862..986311ab62a 100644
--- a/lib/sentry/client/issue.rb
+++ b/lib/sentry/client/issue.rb
@@ -75,7 +75,21 @@ module Sentry
http_get(api_urls.issue_url(issue_id))[:body]
end
- def parse_gitlab_issue(plugin_issues)
+ def parse_gitlab_issue(issue)
+ parse_issue_annotations(issue) || parse_plugin_issue(issue)
+ end
+
+ def parse_issue_annotations(issue)
+ issue
+ .fetch('annotations', [])
+ .reject(&:blank?)
+ .map { |annotation| Nokogiri.make(annotation) }
+ .find { |html| html['href']&.starts_with?(Gitlab.config.gitlab.url) }
+ .try(:[], 'href')
+ end
+
+ def parse_plugin_issue(issue)
+ plugin_issues = issue.fetch('pluginIssues', nil)
return unless plugin_issues
gitlab_plugin = plugin_issues.detect { |item| item['id'] == 'gitlab' }
@@ -145,7 +159,7 @@ module Sentry
short_id: issue.fetch('shortId', nil),
status: issue.fetch('status', nil),
frequency: issue.dig('stats', '24h'),
- gitlab_issue: parse_gitlab_issue(issue.fetch('pluginIssues', nil)),
+ gitlab_issue: parse_gitlab_issue(issue),
project_id: issue.dig('project', 'id'),
project_name: issue.dig('project', 'name'),
project_slug: issue.dig('project', 'slug'),