Commit 1904c80f authored by Jacob Vosmaer's avatar Jacob Vosmaer

Change socket_path to gitaly_address

parent eee07f1c
...@@ -443,14 +443,10 @@ production: &base ...@@ -443,14 +443,10 @@ production: &base
# Gitaly settings # Gitaly settings
gitaly: gitaly:
# The socket_path setting is optional and obsolete. When this is set # This setting controls whether GitLab uses Gitaly (new component
# GitLab assumes it can reach a Gitaly services via a Unix socket at # introduced in 9.0). Eventually Gitaly use will become mandatory and
# this path. When this is commented out GitLab will not use Gitaly. # this option will disappear.
# enabled: false
# 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
# #
# 4. Advanced settings # 4. Advanced settings
...@@ -465,6 +461,7 @@ production: &base ...@@ -465,6 +461,7 @@ production: &base
storages: # You must have at least a `default` storage path. storages: # You must have at least a `default` storage path.
default: default:
path: /home/git/repositories/ path: /home/git/repositories/
gitaly_address: unix:/home/git/gitlab/tmp/sockets/private/gitaly.socket
## Backup settings ## Backup settings
backup: backup:
...@@ -577,6 +574,9 @@ test: ...@@ -577,6 +574,9 @@ test:
storages: storages:
default: default:
path: tmp/tests/repositories/ path: tmp/tests/repositories/
gitaly_address: unix:<%= Rails.root.join('tmp/sockets/private/gitaly.socket') %>
gitaly:
enabled: false
backup: backup:
path: tmp/tests/backups path: tmp/tests/backups
gitlab_shell: gitlab_shell:
......
# Make sure we initialize a Gitaly channel before Sidekiq starts multi-threaded execution. require 'uri'
Gitlab.config.repositories.storages.each do |name, params|
Gitlab::GitalyClient.configure_channel(name, params['socket_path']) # 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 end
...@@ -477,12 +477,12 @@ with setting up Gitaly until you upgrade to GitLab 9.1 or later. ...@@ -477,12 +477,12 @@ with setting up Gitaly until you upgrade to GitLab 9.1 or later.
# Enable Gitaly in the init script # Enable Gitaly in the init script
echo 'gitaly_enabled=true' | sudo tee -a /etc/default/gitlab 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. the `gitaly:` section is uncommented.
# <- gitlab.yml indentation starts here # <- gitlab.yml indentation starts here
gitaly: gitaly:
socket_path: tmp/sockets/private/gitaly.socket enabled: true
For more information about configuring Gitaly see For more information about configuring Gitaly see
[doc/administration/gitaly](../administration/gitaly). [doc/administration/gitaly](../administration/gitaly).
......
...@@ -4,9 +4,11 @@ module Gitlab ...@@ -4,9 +4,11 @@ module Gitlab
module GitalyClient module GitalyClient
SERVER_VERSION_FILE = 'GITALY_SERVER_VERSION'.freeze SERVER_VERSION_FILE = 'GITALY_SERVER_VERSION'.freeze
def self.configure_channel(shard, socket_path) def self.configure_channel(storage, address)
@channel ||= {} @addresses ||= {}
@channel[shard] = new_channel("unix://#{socket_path}") @addresses[storage] = address
@channels ||= {}
@channels[storage] = new_channel(address)
end end
def self.new_channel(address) def self.new_channel(address)
...@@ -16,8 +18,12 @@ module Gitlab ...@@ -16,8 +18,12 @@ module Gitlab
GRPC::Core::Channel.new(address, {}, :this_channel_is_insecure) GRPC::Core::Channel.new(address, {}, :this_channel_is_insecure)
end end
def self.get_channel(shard) def self.get_channel(storage)
@channel.fetch(shard) @channels[storage]
end
def self.get_address(storage)
@addresses[storage]
end end
def self.enabled? def self.enabled?
......
require 'base64' require 'base64'
require 'json' require 'json'
require 'securerandom' require 'securerandom'
require 'uri'
module Gitlab module Gitlab
class Workhorse class Workhorse
...@@ -21,10 +22,10 @@ module Gitlab ...@@ -21,10 +22,10 @@ module Gitlab
RepoPath: repository.path_to_repo, RepoPath: repository.path_to_repo,
} }
params.merge!( if Gitlab.config.gitaly.enabled
GitalySocketPath: Gitlab.config.gitaly.socket_path, address = Gitlab::GitalyClient.get_address(repository.project.repository_storage)
GitalyResourcePath: "/projects/#{repository.project.id}/git-http/info-refs", params[:GitalySocketPath] = URI(address).path
) if Gitlab.config.gitaly.socket_path.present? end
params params
end end
......
...@@ -184,18 +184,14 @@ describe Gitlab::Workhorse, lib: true do ...@@ -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 }) } it { expect(subject).to eq({ GL_ID: "user-#{user.id}", RepoPath: repository.path_to_repo }) }
context 'when Gitaly socket path is present' do context 'when Gitaly is enabled' do
let(:gitaly_socket_path) { '/tmp/gitaly.sock' }
before 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 end
it 'includes Gitaly params in the returned value' do it 'includes Gitaly params in the returned value' do
expect(subject).to include({ gitaly_socket_path = URI(Gitlab::GitalyClient.get_address('default')).path
GitalyResourcePath: "/projects/#{repository.project.id}/git-http/info-refs", expect(subject).to include({ GitalySocketPath: gitaly_socket_path })
GitalySocketPath: gitaly_socket_path,
})
end end
end end
end end
......
...@@ -424,7 +424,7 @@ describe API::Internal, api: true do ...@@ -424,7 +424,7 @@ describe API::Internal, api: true do
end end
before do 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 end
it "calls the Gitaly client if it's enabled" do it "calls the Gitaly client if it's enabled" do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment