From 8323e55b6c0d59627c584b49e70d4f6ccfd3c8f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Rodr=C3=ADguez?= Date: Thu, 31 Aug 2017 18:00:40 -0300 Subject: Return a value to check if redis is available on /internal/check --- lib/api/helpers/internal_helpers.rb | 9 +++++++++ lib/api/internal.rb | 3 ++- spec/requests/api/internal_spec.rb | 11 +++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/api/helpers/internal_helpers.rb b/lib/api/helpers/internal_helpers.rb index f57ff0f2632..4c0db4d42b1 100644 --- a/lib/api/helpers/internal_helpers.rb +++ b/lib/api/helpers/internal_helpers.rb @@ -46,6 +46,15 @@ module API ::MergeRequests::GetUrlsService.new(project).execute(params[:changes]) end + def redis_ping + result = Gitlab::Redis::SharedState.with { |redis| redis.ping } + + result == 'PONG' + rescue => e + Rails.logger.warn("GitLab: An unexpected error occurred in pinging to Redis: #{e}") + false + end + private def set_project diff --git a/lib/api/internal.rb b/lib/api/internal.rb index 622bd9650e4..85b66593175 100644 --- a/lib/api/internal.rb +++ b/lib/api/internal.rb @@ -88,7 +88,8 @@ module API { api_version: API.version, gitlab_version: Gitlab::VERSION, - gitlab_rev: Gitlab::REVISION + gitlab_rev: Gitlab::REVISION, + redis: redis_ping } end diff --git a/spec/requests/api/internal_spec.rb b/spec/requests/api/internal_spec.rb index a6c804fb2b3..1494c451543 100644 --- a/spec/requests/api/internal_spec.rb +++ b/spec/requests/api/internal_spec.rb @@ -8,10 +8,21 @@ describe API::Internal do describe "GET /internal/check" do it do + expect_any_instance_of(Redis).to receive(:ping).and_return('PONG') + get api("/internal/check"), secret_token: secret_token expect(response).to have_http_status(200) expect(json_response['api_version']).to eq(API::API.version) + expect(json_response['redis']).to be(true) + end + + it 'returns false for field `redis` when redis is unavailable' do + expect_any_instance_of(Redis).to receive(:ping).and_raise(Errno::ENOENT) + + get api("/internal/check"), secret_token: secret_token + + expect(json_response['redis']).to be(false) end end -- cgit v1.2.1 From ff3eeffa083e6f2299db9c622611762028578bfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Rodr=C3=ADguez?= Date: Thu, 31 Aug 2017 18:01:07 -0300 Subject: Implement /internal/pre-receive for shell operations --- lib/api/internal.rb | 8 ++++++++ spec/requests/api/internal_spec.rb | 20 ++++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/api/internal.rb b/lib/api/internal.rb index 85b66593175..c0fef56378f 100644 --- a/lib/api/internal.rb +++ b/lib/api/internal.rb @@ -143,6 +143,14 @@ module API { success: true, recovery_codes: codes } end + post '/pre_receive' do + status 200 + + reference_counter_increased = Gitlab::ReferenceCounter.new(params[:gl_repository]).increase + + { reference_counter_increased: reference_counter_increased } + end + post "/notify_post_receive" do status 200 diff --git a/spec/requests/api/internal_spec.rb b/spec/requests/api/internal_spec.rb index 1494c451543..1274e66bb4c 100644 --- a/spec/requests/api/internal_spec.rb +++ b/spec/requests/api/internal_spec.rb @@ -5,6 +5,8 @@ describe API::Internal do let(:key) { create(:key, user: user) } let(:project) { create(:project, :repository) } let(:secret_token) { Gitlab::Shell.secret_token } + let(:gl_repository) { "project-#{project.id}" } + let(:reference_counter) { double('ReferenceCounter') } describe "GET /internal/check" do it do @@ -672,9 +674,7 @@ describe API::Internal do # end describe 'POST /internal/post_receive' do - let(:gl_repository) { "project-#{project.id}" } let(:identifier) { 'key-123' } - let(:reference_counter) { double('ReferenceCounter') } let(:valid_params) do { @@ -760,6 +760,22 @@ describe API::Internal do end end + describe 'POST /internal/pre_receive' do + let(:valid_params) do + { gl_repository: gl_repository, secret_token: secret_token } + end + + it 'decreases the reference counter and returns the result' do + expect(Gitlab::ReferenceCounter).to receive(:new).with(gl_repository) + .and_return(reference_counter) + expect(reference_counter).to receive(:increase).and_return(true) + + post api("/internal/pre_receive"), valid_params + + expect(json_response['reference_counter_increased']).to be(true) + end + end + def project_with_repo_path(path) double().tap do |fake_project| allow(fake_project).to receive_message_chain('repository.path_to_repo' => path) -- cgit v1.2.1 From 758f18b213791bd8f19125c8da76961cffee0e18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Rodr=C3=ADguez?= Date: Wed, 6 Sep 2017 07:53:09 -0300 Subject: Update GitLab Shell to v5.9.0 --- GITLAB_SHELL_VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GITLAB_SHELL_VERSION b/GITLAB_SHELL_VERSION index 11d9efa3d5a..b3d91f9cfc0 100644 --- a/GITLAB_SHELL_VERSION +++ b/GITLAB_SHELL_VERSION @@ -1 +1 @@ -5.8.0 +5.9.0 -- cgit v1.2.1