Commit e79ab111 authored by Tomasz Maczukin's avatar Tomasz Maczukin Committed by Kamil Trzcinski

Remove legacy Runners support in /api/v4/jobs/request

In Runner v1.3.0 we've started to send User-Agent header with Runner's
version data. Since GitLab v8.12.0 we've started to use this header to check
if used Runner's version supports 204 status code instead of 404 as a
response when there is no jobs to execute by a Runner.

In APIv4 (introduced in GitLab 9.0.0) will require Runner v9.0.0. And
writing more accurately: GitLab Runner v9.0.0 will require GitLab at
least 9.0.0. Because of such breaking change we are able to switch
entirely to 204 response code and there is no need to do check of
User-Agent.

This commit removes useless code and complexity.
parent bbf4d27a
...@@ -41,14 +41,6 @@ module API ...@@ -41,14 +41,6 @@ module API
(Time.now - current_runner.contacted_at) >= contacted_at_max_age (Time.now - current_runner.contacted_at) >= contacted_at_max_age
end end
def job_not_found!
if headers['User-Agent'].to_s =~ /gitlab(-ci-multi)?-runner \d+\.\d+\.\d+(~beta\.\d+\.g[0-9a-f]+)? /
no_content!
else
not_found!
end
end
def validate_job!(job) def validate_job!(job)
not_found! unless job not_found! unless job
......
...@@ -63,6 +63,9 @@ module API ...@@ -63,6 +63,9 @@ module API
resource :jobs do resource :jobs do
desc 'Request a job' do desc 'Request a job' do
success Entities::JobRequest::Response success Entities::JobRequest::Response
http_codes [[201, 'Job was scheduled'],
[204, 'No job for Runner'],
[403, 'Forbidden']]
end end
params do params do
requires :token, type: String, desc: %q(Runner's authentication token) requires :token, type: String, desc: %q(Runner's authentication token)
...@@ -71,13 +74,13 @@ module API ...@@ -71,13 +74,13 @@ module API
end end
post '/request' do post '/request' do
authenticate_runner! authenticate_runner!
not_found! unless current_runner.active? no_content! unless current_runner.active?
update_runner_info update_runner_info
if current_runner.is_runner_queue_value_latest?(params[:last_update]) if current_runner.is_runner_queue_value_latest?(params[:last_update])
header 'X-GitLab-Last-Update', params[:last_update] header 'X-GitLab-Last-Update', params[:last_update]
Gitlab::Metrics.add_event(:build_not_found_cached) Gitlab::Metrics.add_event(:build_not_found_cached)
return job_not_found! return no_content!
end end
new_update = current_runner.ensure_runner_queue_value new_update = current_runner.ensure_runner_queue_value
...@@ -91,7 +94,7 @@ module API ...@@ -91,7 +94,7 @@ module API
else else
Gitlab::Metrics.add_event(:build_not_found) Gitlab::Metrics.add_event(:build_not_found)
header 'X-GitLab-Last-Update', new_update header 'X-GitLab-Last-Update', new_update
job_not_found! no_content!
end end
else else
# We received build that is invalid due to concurrency conflict # We received build that is invalid due to concurrency conflict
......
...@@ -248,18 +248,6 @@ describe API::Runner do ...@@ -248,18 +248,6 @@ describe API::Runner do
it { expect(response).to have_http_status(204) } it { expect(response).to have_http_status(204) }
end end
end end
context "when runner doesn't send version in User-Agent" do
let(:user_agent) { 'Go-http-client/1.1' }
it { expect(response).to have_http_status(404) }
end
context "when runner doesn't have a User-Agent" do
let(:user_agent) { nil }
it { expect(response).to have_http_status(404) }
end
end end
context 'when no token is provided' do context 'when no token is provided' do
...@@ -282,10 +270,10 @@ describe API::Runner do ...@@ -282,10 +270,10 @@ describe API::Runner do
context 'when Runner is not active' do context 'when Runner is not active' do
let(:runner) { create(:ci_runner, :inactive) } let(:runner) { create(:ci_runner, :inactive) }
it 'returns 404 error' do it 'returns 204 error' do
request_job request_job
expect(response).to have_http_status 404 expect(response).to have_http_status 204
end end
end end
......
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