From f131757fc81e6f04f5adfcf09f37e13b008bf4b8 Mon Sep 17 00:00:00 2001 From: Zeger-Jan van de Weg Date: Wed, 16 May 2018 10:20:14 +0200 Subject: Set Gitaly Server feature flags from Rails Gitaly itself hold very little state, other than the data on disk. This limits the interfaces to set feature flags. Gitaly now has the ability to interpret the request metadata to check for feature flags. https://gitlab.com/gitlab-org/gitaly/merge_requests/704 This allows clients control on the Gitaly server, and given that Rails has an internal chatops interface to set these values this was chosen as solution. Known limitation right now, is that this package doesn't support the opt out that other Gitaly features do. --- lib/gitlab/git/commit.rb | 5 +++++ lib/gitlab/gitaly_client.rb | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/lib/gitlab/git/commit.rb b/lib/gitlab/git/commit.rb index 89f761dd515..f24ebe8a7d2 100644 --- a/lib/gitlab/git/commit.rb +++ b/lib/gitlab/git/commit.rb @@ -60,6 +60,11 @@ module Gitlab # Some weird thing? return nil unless commit_id.is_a?(String) + # The Go-Git backend Gitaly might use, tries to be nice when resolving + # to the commit, and `master:ref` will resolve to the commit that master + # resolves to. To keep behaviour the same, we return nil + return nil if commit_id.include?(':') + commit = repo.gitaly_migrate(:find_commit) do |is_enabled| if is_enabled repo.gitaly_commit_client.find_commit(commit_id) diff --git a/lib/gitlab/gitaly_client.rb b/lib/gitlab/gitaly_client.rb index 550294916a4..52e940ee407 100644 --- a/lib/gitlab/gitaly_client.rb +++ b/lib/gitlab/gitaly_client.rb @@ -191,6 +191,8 @@ module Gitlab metadata['call_site'] = feature.to_s if feature metadata['gitaly-servers'] = address_metadata(remote_storage) if remote_storage + metadata.merge!(server_feature_flags(feature)) + result = { metadata: metadata } # nil timeout indicates that we should use the default @@ -209,6 +211,20 @@ module Gitlab result end + SERVER_FEATURE_FLAGS = { + find_commit: ["gogit-findcommit"] + }.freeze + + # Other than data on the disk, Gitaly is stateless. Rails will thus set + # feature flags in the request metadata. + def self.server_feature_flags(feature) + return {} unless SERVER_FEATURE_FLAGS.key?(feature) + + SERVER_FEATURE_FLAGS[feature] + .map { |f| ["gitaly-feature-#{f}", feature_enabled?(f).to_s] } + .to_h + end + def self.token(storage) params = Gitlab.config.repositories.storages[storage] raise "storage not found: #{storage.inspect}" if params.nil? -- cgit v1.2.3 From e7ef91339e5ca005ba3726a5e15927d618435222 Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Fri, 1 Jun 2018 11:37:03 +0200 Subject: Simplify server feature flags --- lib/gitlab/git/commit.rb | 4 +--- lib/gitlab/gitaly_client.rb | 18 ++++++------------ 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/lib/gitlab/git/commit.rb b/lib/gitlab/git/commit.rb index f24ebe8a7d2..c9806cdb85f 100644 --- a/lib/gitlab/git/commit.rb +++ b/lib/gitlab/git/commit.rb @@ -60,9 +60,7 @@ module Gitlab # Some weird thing? return nil unless commit_id.is_a?(String) - # The Go-Git backend Gitaly might use, tries to be nice when resolving - # to the commit, and `master:ref` will resolve to the commit that master - # resolves to. To keep behaviour the same, we return nil + # This saves us an RPC round trip. return nil if commit_id.include?(':') commit = repo.gitaly_migrate(:find_commit) do |is_enabled| diff --git a/lib/gitlab/gitaly_client.rb b/lib/gitlab/gitaly_client.rb index 52e940ee407..5756b9ef0d5 100644 --- a/lib/gitlab/gitaly_client.rb +++ b/lib/gitlab/gitaly_client.rb @@ -191,7 +191,7 @@ module Gitlab metadata['call_site'] = feature.to_s if feature metadata['gitaly-servers'] = address_metadata(remote_storage) if remote_storage - metadata.merge!(server_feature_flags(feature)) + metadata.merge!(server_feature_flags) result = { metadata: metadata } @@ -211,18 +211,12 @@ module Gitlab result end - SERVER_FEATURE_FLAGS = { - find_commit: ["gogit-findcommit"] - }.freeze + SERVER_FEATURE_FLAGS = %w[gogit_findcommit].freeze - # Other than data on the disk, Gitaly is stateless. Rails will thus set - # feature flags in the request metadata. - def self.server_feature_flags(feature) - return {} unless SERVER_FEATURE_FLAGS.key?(feature) - - SERVER_FEATURE_FLAGS[feature] - .map { |f| ["gitaly-feature-#{f}", feature_enabled?(f).to_s] } - .to_h + def self.server_feature_flags + SERVER_FEATURE_FLAGS.map do |f| + ["gitaly-feature-#{f.tr('_', '-')}", feature_enabled?(f).to_s] + end.to_h end def self.token(storage) -- cgit v1.2.3 From 9f71d02e46668a0344123749bb6a0a7764e69b68 Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Tue, 5 Jun 2018 11:49:13 +0200 Subject: Use gitaly 0.105.0 --- GITALY_SERVER_VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GITALY_SERVER_VERSION b/GITALY_SERVER_VERSION index e49057b3302..f1b9cc4cd95 100644 --- a/GITALY_SERVER_VERSION +++ b/GITALY_SERVER_VERSION @@ -1 +1 @@ -0.104.0 +0.105.0 -- cgit v1.2.3 From 536d180f80839ad8350e26e435a181e3cbf2253b Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Wed, 6 Jun 2018 11:39:38 +0200 Subject: Rescue from failed feature lookups --- lib/gitlab/gitaly_client.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/gitlab/gitaly_client.rb b/lib/gitlab/gitaly_client.rb index 5756b9ef0d5..36e9adf27da 100644 --- a/lib/gitlab/gitaly_client.rb +++ b/lib/gitlab/gitaly_client.rb @@ -253,6 +253,10 @@ module Gitlab else false end + rescue => ex + # During application startup feature lookups in SQL can fail + Rails.logger.warn "exception while checking Gitaly feature status for #{feature_name}: #{ex}" + false end # opt_into_all_features? returns true when the current environment -- cgit v1.2.3