Commit 43a476d9 authored by GitLab Bot's avatar GitLab Bot

Automatic merge of gitlab-org/gitlab-ce master

parents adcd4d42 a5fb32b5
......@@ -151,7 +151,7 @@ function deferredInitialisation() {
const canaryBadge = document.querySelector('.js-canary-badge');
const canaryLink = document.querySelector('.js-canary-link');
if (canaryBadge) {
canaryBadge.classList.add('hidden');
canaryBadge.classList.remove('hidden');
}
if (canaryLink) {
canaryLink.classList.add('hidden');
......
......@@ -221,7 +221,6 @@ class Projects::EnvironmentsController < Projects::ApplicationController
def metrics_params
return unless Feature.enabled?(:metrics_time_window, project)
return unless params[:start].present? || params[:end].present?
params.require([:start, :end])
end
......
......@@ -140,6 +140,8 @@ module Ci
where("EXISTS (?)", matcher)
end
scope :queued_before, ->(time) { where(arel_table[:queued_at].lt(time)) }
##
# TODO: Remove these mounters when we remove :ci_enable_legacy_artifacts feature flag
mount_uploader :legacy_artifacts_file, LegacyArtifactUploader, mount_on: :artifacts_file
......
......@@ -36,6 +36,11 @@ module Ci
builds = builds.with_any_tags
end
# pick builds that older than specified age
if params.key?(:job_age)
builds = builds.queued_before(params[:job_age].seconds.ago)
end
builds.each do |build|
next unless runner.can_pick?(build)
......
......@@ -18,7 +18,7 @@
%span.logo-text.d-none.d-lg-block.prepend-left-8
= logo_text
- if Gitlab.com?
= link_to 'https://next.gitlab.com', class: 'label-link js-canary-badge canary-badge bg-transparent', target: :_blank do
= link_to 'https://next.gitlab.com', class: 'label-link js-canary-badge canary-badge bg-transparent hidden', target: :_blank do
%span.color-label.has-tooltip.badge.badge-pill.green-badge
= _('Next')
......
---
title: "Added option to filter jobs by age in the /job/request API endpoint."
merge_request: 1340
author: Dmitry Chepurovskiy
type: added
---
title: Next badge must visible when canary flag is true
merge_request:
author:
type: fixed
# frozen_string_literal: true
# This migration make queued_at field indexed to speed up builds filtering by job_age
class AddBuildQueuedAtIndex < ActiveRecord::Migration[5.1]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
add_concurrent_index :ci_builds, :queued_at
end
def down
remove_concurrent_index :ci_builds, :queued_at
end
end
......@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20190515125613) do
ActiveRecord::Schema.define(version: 20190516011213) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......@@ -525,6 +525,7 @@ ActiveRecord::Schema.define(version: 20190515125613) do
t.index ["project_id", "id"], name: "index_ci_builds_on_project_id_and_id", using: :btree
t.index ["project_id", "status"], name: "index_ci_builds_project_id_and_status_for_live_jobs_partial2", where: "(((type)::text = 'Ci::Build'::text) AND ((status)::text = ANY (ARRAY[('running'::character varying)::text, ('pending'::character varying)::text, ('created'::character varying)::text])))", using: :btree
t.index ["protected"], name: "index_ci_builds_on_protected", using: :btree
t.index ["queued_at"], name: "index_ci_builds_on_queued_at", using: :btree
t.index ["runner_id"], name: "index_ci_builds_on_runner_id", using: :btree
t.index ["scheduled_at"], name: "partial_index_ci_builds_on_scheduled_at_with_scheduled_jobs", where: "((scheduled_at IS NOT NULL) AND ((type)::text = 'Ci::Build'::text) AND ((status)::text = 'scheduled'::text))", using: :btree
t.index ["stage_id", "stage_idx"], name: "tmp_build_stage_position_index", where: "(stage_idx IS NOT NULL)", using: :btree
......
......@@ -98,6 +98,7 @@ module API
optional :certificate, type: String, desc: %q(Session's certificate)
optional :authorization, type: String, desc: %q(Session's authorization)
end
optional :job_age, type: Integer, desc: %q(Job should be older than passed age in seconds to be ran on runner)
end
post '/request' do
authenticate_runner!
......
......@@ -383,6 +383,8 @@ describe Projects::EnvironmentsController do
end
describe 'GET #additional_metrics' do
let(:window_params) { { start: '1554702993.5398998', end: '1554717396.996232' } }
before do
allow(controller).to receive(:environment).and_return(environment)
end
......@@ -394,7 +396,7 @@ describe Projects::EnvironmentsController do
context 'when requesting metrics as JSON' do
it 'returns a metrics JSON document' do
additional_metrics
additional_metrics(window_params)
expect(response).to have_gitlab_http_status(204)
expect(json_response).to eq({})
......@@ -414,23 +416,19 @@ describe Projects::EnvironmentsController do
end
it 'returns a metrics JSON document' do
additional_metrics
additional_metrics(window_params)
expect(response).to be_ok
expect(json_response['success']).to be(true)
expect(json_response['data']).to eq({})
expect(json_response['last_update']).to eq(42)
end
end
context 'when time params are provided' do
it 'returns a metrics JSON document' do
additional_metrics(start: '1554702993.5398998', end: '1554717396.996232')
expect(response).to be_ok
expect(json_response['success']).to be(true)
expect(json_response['data']).to eq({})
expect(json_response['last_update']).to eq(42)
end
context 'when time params are missing' do
it 'raises an error when window params are missing' do
expect { additional_metrics }
.to raise_error(ActionController::ParameterMissing)
end
end
......@@ -450,7 +448,7 @@ describe Projects::EnvironmentsController do
end
it 'raises an error when start is missing' do
expect { additional_metrics(start: '1552647300.651094') }
expect { additional_metrics(end: '1552647300.651094') }
.to raise_error(ActionController::ParameterMissing)
end
......
......@@ -542,6 +542,30 @@ describe API::Runner, :clean_gitlab_redis_shared_state do
end
end
context 'when job filtered by job_age' do
let!(:job) { create(:ci_build, :tag, pipeline: pipeline, name: 'spinach', stage: 'test', stage_idx: 0, queued_at: 60.seconds.ago) }
context 'job is queued less than job_age parameter' do
let(:job_age) { 120 }
it 'gives 204' do
request_job(job_age: job_age)
expect(response).to have_gitlab_http_status(204)
end
end
context 'job is queued more than job_age parameter' do
let(:job_age) { 30 }
it 'picks a job' do
request_job(job_age: job_age)
expect(response).to have_gitlab_http_status(201)
end
end
end
context 'when job is made for branch' do
it 'sets tag as ref_type' do
request_job
......
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