From 6379a849c0a9ab004f68307dac5375443f3e49fa Mon Sep 17 00:00:00 2001 From: Andreas Brandl Date: Mon, 12 Mar 2018 18:24:36 +0100 Subject: Fix timestamp to include %M instead of %I for post-deploy migrations. Closes #44121. --- .../post_deployment_migration/post_deployment_migration_generator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/generators/rails/post_deployment_migration/post_deployment_migration_generator.rb b/lib/generators/rails/post_deployment_migration/post_deployment_migration_generator.rb index 7cb4bccb23c..91175b49c79 100644 --- a/lib/generators/rails/post_deployment_migration/post_deployment_migration_generator.rb +++ b/lib/generators/rails/post_deployment_migration/post_deployment_migration_generator.rb @@ -3,7 +3,7 @@ require 'rails/generators' module Rails class PostDeploymentMigrationGenerator < Rails::Generators::NamedBase def create_migration_file - timestamp = Time.now.strftime('%Y%m%d%H%I%S') + timestamp = Time.now.strftime('%Y%m%d%H%M%S') template "migration.rb", "db/post_migrate/#{timestamp}_#{file_name}.rb" end -- cgit v1.2.1 From afe2c15e6bf1005e5bd1d213d3548a1a17a11137 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20D=C3=A1vila?= Date: Mon, 12 Mar 2018 16:01:43 -0500 Subject: Fix provider server URL used when listing repos to import Also use Gitlab::Auth::OAuth::Provider.config_for to access OmniAuth config --- lib/gitlab/auth/saml/config.rb | 2 +- lib/gitlab/github_import/client.rb | 5 +---- lib/gitlab/gitlab_import/client.rb | 2 +- lib/gitlab/legacy_github_import/client.rb | 2 +- lib/google_api/auth.rb | 2 +- 5 files changed, 5 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/gitlab/auth/saml/config.rb b/lib/gitlab/auth/saml/config.rb index e654e7fe438..2760b1a3247 100644 --- a/lib/gitlab/auth/saml/config.rb +++ b/lib/gitlab/auth/saml/config.rb @@ -4,7 +4,7 @@ module Gitlab class Config class << self def options - Gitlab.config.omniauth.providers.find { |provider| provider.name == 'saml' } + Gitlab::Auth::OAuth::Provider.config_for('saml') end def groups diff --git a/lib/gitlab/github_import/client.rb b/lib/gitlab/github_import/client.rb index 4f160e4a447..a61beafae0d 100644 --- a/lib/gitlab/github_import/client.rb +++ b/lib/gitlab/github_import/client.rb @@ -197,10 +197,7 @@ module Gitlab end def github_omniauth_provider - @github_omniauth_provider ||= - Gitlab.config.omniauth.providers - .find { |provider| provider.name == 'github' } - .to_h + @github_omniauth_provider ||= Gitlab::Auth::OAuth::Provider.config_for('github').to_h end def rate_limit_counter diff --git a/lib/gitlab/gitlab_import/client.rb b/lib/gitlab/gitlab_import/client.rb index 075b3982608..5482504e72e 100644 --- a/lib/gitlab/gitlab_import/client.rb +++ b/lib/gitlab/gitlab_import/client.rb @@ -72,7 +72,7 @@ module Gitlab end def config - Gitlab.config.omniauth.providers.find {|provider| provider.name == "gitlab"} + Gitlab::Auth::OAuth::Provider.config_for('gitlab') end def gitlab_options diff --git a/lib/gitlab/legacy_github_import/client.rb b/lib/gitlab/legacy_github_import/client.rb index 53c910d44bd..d8ed0ebca9d 100644 --- a/lib/gitlab/legacy_github_import/client.rb +++ b/lib/gitlab/legacy_github_import/client.rb @@ -83,7 +83,7 @@ module Gitlab end def config - Gitlab.config.omniauth.providers.find { |provider| provider.name == "github" } + Gitlab::Auth::OAuth::Provider.config_for('github') end def github_options diff --git a/lib/google_api/auth.rb b/lib/google_api/auth.rb index 99a82c849e0..1aeaa387a49 100644 --- a/lib/google_api/auth.rb +++ b/lib/google_api/auth.rb @@ -32,7 +32,7 @@ module GoogleApi private def config - Gitlab.config.omniauth.providers.find { |provider| provider.name == "google_oauth2" } + Gitlab::Auth::OAuth::Provider.config_for('google_oauth2') end def client -- cgit v1.2.1 From d30576c5a7197b167d1f2c472361dd4ce77b8262 Mon Sep 17 00:00:00 2001 From: Sean McGivern Date: Tue, 6 Mar 2018 14:02:18 +0000 Subject: Add Gitaly call details to the performance bar The same as the SQL queries, show the details of Gitaly calls in the performance bar, as a modal that can be opened in the same way. --- lib/gitlab/gitaly_client.rb | 18 ++++++++++++++++++ lib/peek/views/gitaly.rb | 19 ++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/gitlab/gitaly_client.rb b/lib/gitlab/gitaly_client.rb index 9cd76630484..c3aa3ccd7b1 100644 --- a/lib/gitlab/gitaly_client.rb +++ b/lib/gitlab/gitaly_client.rb @@ -119,6 +119,8 @@ module Gitlab # def self.call(storage, service, rpc, request, remote_storage: nil, timeout: nil) start = Gitlab::Metrics::System.monotonic_time + @last_request = request.is_a?(Google::Protobuf::MessageExts) ? request.to_h : nil + enforce_gitaly_request_limits(:call) kwargs = request_kwargs(storage, timeout, remote_storage: remote_storage) @@ -258,6 +260,9 @@ module Gitlab gitaly_migrate_call_duration_seconds.observe({ gitaly_enabled: is_enabled, feature: feature }, total_time) feature_stack.shift Thread.current[:gitaly_feature_stack] = nil if feature_stack.empty? + add_call_details(feature: feature, + duration: total_time, + request: is_enabled ? @last_request : {}) end end end @@ -344,6 +349,19 @@ module Gitlab end end + def self.add_call_details(details) + return unless RequestStore.active? && RequestStore.store[:peek_enabled] + + RequestStore.store['gitaly_call_details'] ||= [] + RequestStore.store['gitaly_call_details'] << details + end + + def self.call_details + return [] unless RequestStore.active? && RequestStore.store[:peek_enabled] + + RequestStore.store['gitaly_call_details'] || [] + end + def self.expected_server_version path = Rails.root.join(SERVER_VERSION_FILE) path.read.chomp diff --git a/lib/peek/views/gitaly.rb b/lib/peek/views/gitaly.rb index d519d8e86fa..79851640318 100644 --- a/lib/peek/views/gitaly.rb +++ b/lib/peek/views/gitaly.rb @@ -10,11 +10,28 @@ module Peek end def results - { duration: formatted_duration, calls: calls } + { + duration: formatted_duration, + calls: calls, + details: details + } end private + def details + ::Gitlab::GitalyClient.call_details + .sort { |a, b| b[:duration] <=> a[:duration] } + .map(&method(:format_call_details)) + end + + def format_call_details(call) + pretty_request = call[:request].reject { |k, v| v.blank? }.to_h.pretty_inspect + + call.merge(duration: (call[:duration] * 1000).round(3), + request: pretty_request) + end + def formatted_duration ms = duration * 1000 if ms >= 1000 -- cgit v1.2.1 From 582447d9ae0074e0843c60df92d7c2ab09b23c80 Mon Sep 17 00:00:00 2001 From: Sean McGivern Date: Thu, 8 Mar 2018 12:10:59 +0000 Subject: Capture Gitaly calls that don't go through `migrate` --- lib/gitlab/gitaly_client.rb | 29 +++++++++++++++++++---------- lib/peek/views/gitaly.rb | 7 ++++--- 2 files changed, 23 insertions(+), 13 deletions(-) (limited to 'lib') diff --git a/lib/gitlab/gitaly_client.rb b/lib/gitlab/gitaly_client.rb index c3aa3ccd7b1..8ca30ffc232 100644 --- a/lib/gitlab/gitaly_client.rb +++ b/lib/gitlab/gitaly_client.rb @@ -119,7 +119,8 @@ module Gitlab # def self.call(storage, service, rpc, request, remote_storage: nil, timeout: nil) start = Gitlab::Metrics::System.monotonic_time - @last_request = request.is_a?(Google::Protobuf::MessageExts) ? request.to_h : nil + request_hash = request.is_a?(Google::Protobuf::MessageExts) ? request.to_h : {} + @current_call_id ||= SecureRandom.uuid enforce_gitaly_request_limits(:call) @@ -137,6 +138,10 @@ module Gitlab gitaly_controller_action_duration_seconds.observe( current_transaction_labels.merge(gitaly_service: service.to_s, rpc: rpc.to_s), duration) + + add_call_details(id: @current_call_id, feature: service, duration: duration, request: request_hash) + + @current_call_id = nil end def self.handle_grpc_unavailable!(ex) @@ -254,15 +259,16 @@ module Gitlab feature_stack.unshift(feature) begin start = Gitlab::Metrics::System.monotonic_time + @current_call_id = SecureRandom.uuid + call_details = { id: @current_call_id } yield is_enabled ensure total_time = Gitlab::Metrics::System.monotonic_time - start gitaly_migrate_call_duration_seconds.observe({ gitaly_enabled: is_enabled, feature: feature }, total_time) feature_stack.shift Thread.current[:gitaly_feature_stack] = nil if feature_stack.empty? - add_call_details(feature: feature, - duration: total_time, - request: is_enabled ? @last_request : {}) + + add_call_details(call_details.merge(feature: feature, duration: total_time)) end end end @@ -350,16 +356,19 @@ module Gitlab end def self.add_call_details(details) - return unless RequestStore.active? && RequestStore.store[:peek_enabled] + id = details.delete(:id) + + return unless id && RequestStore.active? && RequestStore.store[:peek_enabled] - RequestStore.store['gitaly_call_details'] ||= [] - RequestStore.store['gitaly_call_details'] << details + RequestStore.store['gitaly_call_details'] ||= {} + RequestStore.store['gitaly_call_details'][id] ||= {} + RequestStore.store['gitaly_call_details'][id].merge!(details) end - def self.call_details - return [] unless RequestStore.active? && RequestStore.store[:peek_enabled] + def self.list_call_details + return {} unless RequestStore.active? && RequestStore.store[:peek_enabled] - RequestStore.store['gitaly_call_details'] || [] + RequestStore.store['gitaly_call_details'] || {} end def self.expected_server_version diff --git a/lib/peek/views/gitaly.rb b/lib/peek/views/gitaly.rb index 79851640318..ab35f7a2258 100644 --- a/lib/peek/views/gitaly.rb +++ b/lib/peek/views/gitaly.rb @@ -20,16 +20,17 @@ module Peek private def details - ::Gitlab::GitalyClient.call_details + ::Gitlab::GitalyClient.list_call_details + .values .sort { |a, b| b[:duration] <=> a[:duration] } .map(&method(:format_call_details)) end def format_call_details(call) - pretty_request = call[:request].reject { |k, v| v.blank? }.to_h.pretty_inspect + pretty_request = call[:request]&.reject { |k, v| v.blank? }.to_h.pretty_inspect call.merge(duration: (call[:duration] * 1000).round(3), - request: pretty_request) + request: pretty_request || {}) end def formatted_duration -- cgit v1.2.1