Change socket_path to gitaly_address

This commit is contained in:
Jacob Vosmaer 2017-03-24 18:22:42 +01:00
parent eee07f1c7c
commit 1904c80f3d
7 changed files with 48 additions and 31 deletions

View File

@ -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:

View File

@ -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

View File

@ -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).

View File

@ -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?

View File

@ -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

View File

@ -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

View File

@ -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