summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Vosmaer <jacob@gitlab.com>2017-03-24 18:22:42 +0100
committerJacob Vosmaer <jacob@gitlab.com>2017-03-29 14:48:05 +0200
commit1904c80f3dd5437cb39aa90de933279bf9635678 (patch)
tree6de907068aadafc992ada78ffb0b484b1ad74faa
parenteee07f1c7cacdd24cbd66917ba66e703128f65c6 (diff)
downloadgitlab-ce-1904c80f3dd5437cb39aa90de933279bf9635678.tar.gz
Change socket_path to gitaly_address
-rw-r--r--config/gitlab.yml.example16
-rw-r--r--config/initializers/8_gitaly.rb20
-rw-r--r--doc/install/installation.md4
-rw-r--r--lib/gitlab/gitaly_client.rb16
-rw-r--r--lib/gitlab/workhorse.rb9
-rw-r--r--spec/lib/gitlab/workhorse_spec.rb12
-rw-r--r--spec/requests/api/internal_spec.rb2
7 files changed, 48 insertions, 31 deletions
diff --git a/config/gitlab.yml.example b/config/gitlab.yml.example
index 3747baf4c3b..d89e25c0959 100644
--- a/config/gitlab.yml.example
+++ b/config/gitlab.yml.example
@@ -443,14 +443,10 @@ production: &base
# Gitaly settings
gitaly:
- # The socket_path setting is optional and obsolete. When this is set
- # GitLab assumes it can reach a Gitaly services via a Unix socket at
- # this path. When this is commented out GitLab will not use Gitaly.
- #
- # This setting is obsolete because we expect it to be moved under
- # repositories/storages in GitLab 9.1.
- #
- # socket_path: tmp/sockets/private/gitaly.socket
+ # This setting controls whether GitLab uses Gitaly (new component
+ # introduced in 9.0). Eventually Gitaly use will become mandatory and
+ # this option will disappear.
+ enabled: false
#
# 4. Advanced settings
@@ -465,6 +461,7 @@ production: &base
storages: # You must have at least a `default` storage path.
default:
path: /home/git/repositories/
+ gitaly_address: unix:/home/git/gitlab/tmp/sockets/private/gitaly.socket
## Backup settings
backup:
@@ -577,6 +574,9 @@ test:
storages:
default:
path: tmp/tests/repositories/
+ gitaly_address: unix:<%= Rails.root.join('tmp/sockets/private/gitaly.socket') %>
+ gitaly:
+ enabled: false
backup:
path: tmp/tests/backups
gitlab_shell:
diff --git a/config/initializers/8_gitaly.rb b/config/initializers/8_gitaly.rb
index e4a505a8ba4..69c0a91d6f0 100644
--- a/config/initializers/8_gitaly.rb
+++ b/config/initializers/8_gitaly.rb
@@ -1,4 +1,18 @@
-# Make sure we initialize a Gitaly channel before Sidekiq starts multi-threaded execution.
-Gitlab.config.repositories.storages.each do |name, params|
- Gitlab::GitalyClient.configure_channel(name, params['socket_path'])
+require 'uri'
+
+# Make sure we initialize our Gitaly channels before Sidekiq starts multi-threaded execution.
+if Gitlab.config.gitaly.enabled || Rails.env.test?
+ Gitlab.config.repositories.storages.each do |name, params|
+ address = params['gitaly_address']
+
+ unless address.present?
+ raise "storage #{name.inspect} is missing a gitaly_address"
+ end
+
+ unless URI(address).scheme == 'unix'
+ raise "Unsupported Gitaly address: #{address.inspect}"
+ end
+
+ Gitlab::GitalyClient.configure_channel(name, address)
+ end
end
diff --git a/doc/install/installation.md b/doc/install/installation.md
index a6b10176450..a2248a38435 100644
--- a/doc/install/installation.md
+++ b/doc/install/installation.md
@@ -477,12 +477,12 @@ with setting up Gitaly until you upgrade to GitLab 9.1 or later.
# Enable Gitaly in the init script
echo 'gitaly_enabled=true' | sudo tee -a /etc/default/gitlab
-Next, edit `/home/git/gitlab/config/gitlab.yml` and make sure `socket_path` in
+Next, edit `/home/git/gitlab/config/gitlab.yml` and make sure `enabled: true` in
the `gitaly:` section is uncommented.
# <- gitlab.yml indentation starts here
gitaly:
- socket_path: tmp/sockets/private/gitaly.socket
+ enabled: true
For more information about configuring Gitaly see
[doc/administration/gitaly](../administration/gitaly).
diff --git a/lib/gitlab/gitaly_client.rb b/lib/gitlab/gitaly_client.rb
index c947075bf62..a0dbe0a8c11 100644
--- a/lib/gitlab/gitaly_client.rb
+++ b/lib/gitlab/gitaly_client.rb
@@ -4,9 +4,11 @@ module Gitlab
module GitalyClient
SERVER_VERSION_FILE = 'GITALY_SERVER_VERSION'.freeze
- def self.configure_channel(shard, socket_path)
- @channel ||= {}
- @channel[shard] = new_channel("unix://#{socket_path}")
+ def self.configure_channel(storage, address)
+ @addresses ||= {}
+ @addresses[storage] = address
+ @channels ||= {}
+ @channels[storage] = new_channel(address)
end
def self.new_channel(address)
@@ -16,8 +18,12 @@ module Gitlab
GRPC::Core::Channel.new(address, {}, :this_channel_is_insecure)
end
- def self.get_channel(shard)
- @channel.fetch(shard)
+ def self.get_channel(storage)
+ @channels[storage]
+ end
+
+ def self.get_address(storage)
+ @addresses[storage]
end
def self.enabled?
diff --git a/lib/gitlab/workhorse.rb b/lib/gitlab/workhorse.rb
index eae1a0abf06..6fe85af3c30 100644
--- a/lib/gitlab/workhorse.rb
+++ b/lib/gitlab/workhorse.rb
@@ -1,6 +1,7 @@
require 'base64'
require 'json'
require 'securerandom'
+require 'uri'
module Gitlab
class Workhorse
@@ -21,10 +22,10 @@ module Gitlab
RepoPath: repository.path_to_repo,
}
- params.merge!(
- GitalySocketPath: Gitlab.config.gitaly.socket_path,
- GitalyResourcePath: "/projects/#{repository.project.id}/git-http/info-refs",
- ) if Gitlab.config.gitaly.socket_path.present?
+ if Gitlab.config.gitaly.enabled
+ address = Gitlab::GitalyClient.get_address(repository.project.repository_storage)
+ params[:GitalySocketPath] = URI(address).path
+ end
params
end
diff --git a/spec/lib/gitlab/workhorse_spec.rb b/spec/lib/gitlab/workhorse_spec.rb
index 8e5e8288c49..535c96eeee9 100644
--- a/spec/lib/gitlab/workhorse_spec.rb
+++ b/spec/lib/gitlab/workhorse_spec.rb
@@ -184,18 +184,14 @@ describe Gitlab::Workhorse, lib: true do
it { expect(subject).to eq({ GL_ID: "user-#{user.id}", RepoPath: repository.path_to_repo }) }
- context 'when Gitaly socket path is present' do
- let(:gitaly_socket_path) { '/tmp/gitaly.sock' }
-
+ context 'when Gitaly is enabled' do
before do
- allow(Gitlab.config.gitaly).to receive(:socket_path).and_return(gitaly_socket_path)
+ allow(Gitlab.config.gitaly).to receive(:enabled).and_return(true)
end
it 'includes Gitaly params in the returned value' do
- expect(subject).to include({
- GitalyResourcePath: "/projects/#{repository.project.id}/git-http/info-refs",
- GitalySocketPath: gitaly_socket_path,
- })
+ gitaly_socket_path = URI(Gitlab::GitalyClient.get_address('default')).path
+ expect(subject).to include({ GitalySocketPath: gitaly_socket_path })
end
end
end
diff --git a/spec/requests/api/internal_spec.rb b/spec/requests/api/internal_spec.rb
index e25157a8abc..eed45d37444 100644
--- a/spec/requests/api/internal_spec.rb
+++ b/spec/requests/api/internal_spec.rb
@@ -424,7 +424,7 @@ describe API::Internal, api: true do
end
before do
- allow(Gitlab.config.gitaly).to receive(:socket_path).and_return('path/to/gitaly.socket')
+ allow(Gitlab.config.gitaly).to receive(:enabled).and_return(true)
end
it "calls the Gitaly client if it's enabled" do