Commit 251420dc authored by Pedro Pombeiro's avatar Pedro Pombeiro

Capture job executor value in ci_runners table

Changelog: added
parent 70a1dc76
......@@ -26,6 +26,21 @@ module Ci
project_type: 3
}
enum executor_type: {
unknown: 0,
custom: 1,
shell: 2,
docker: 3,
docker_windows: 4,
docker_ssh: 5,
ssh: 6,
parallels: 7,
virtualbox: 8,
docker_machine: 9,
docker_ssh_machine: 10,
kubernetes: 11
}, _suffix: true
# This `ONLINE_CONTACT_TIMEOUT` needs to be larger than
# `RUNNER_QUEUE_EXPIRY_TIME+UPDATE_CONTACT_COLUMN_EVERY`
#
......@@ -152,7 +167,7 @@ module Ci
after_destroy :cleanup_runner_queue
cached_attr_reader :version, :revision, :platform, :architecture, :ip_address, :contacted_at
cached_attr_reader :version, :revision, :platform, :architecture, :ip_address, :contacted_at, :executor_type
chronic_duration_attr :maximum_timeout_human_readable, :maximum_timeout,
error_message: 'Maximum job timeout has a value which could not be accepted'
......@@ -398,8 +413,9 @@ module Ci
# database after heartbeat write happens.
#
::Gitlab::Database::LoadBalancing::Session.without_sticky_writes do
values = values&.slice(:version, :revision, :platform, :architecture, :ip_address, :config) || {}
values = values&.slice(:version, :revision, :platform, :architecture, :ip_address, :config, :executor) || {}
values[:contacted_at] = Time.current
values[:executor_type] = EXECUTOR_NAME_TO_TYPES.fetch(values.delete(:executor), :unknown)
cache_attributes(values)
......@@ -424,6 +440,20 @@ module Ci
private
EXECUTOR_NAME_TO_TYPES = {
'custom' => :custom,
'shell' => :shell,
'docker' => :docker,
'docker-windows' => :docker_windows,
'docker-ssh' => :docker_ssh,
'ssh' => :ssh,
'parallels' => :parallels,
'virtualbox' => :virtualbox,
'docker+machine' => :docker_machine,
'docker-ssh+machine' => :docker_ssh_machine,
'kubernetes' => :kubernetes
}.freeze
def cleanup_runner_queue
Gitlab::Redis::SharedState.with do |redis|
redis.del(runner_queue_key)
......
# frozen_string_literal: true
class AddExecutorTypeColumnToCiRunners < Gitlab::Database::Migration[1.0]
def change
add_column :ci_runners, :executor_type, :smallint, null: true
end
end
1e3f29ed1a820588da9fe135fbdd0feaa960038b99397dbd7921d4804dce1e1f
\ No newline at end of file
......@@ -12175,7 +12175,8 @@ CREATE TABLE ci_runners (
token_encrypted character varying,
public_projects_minutes_cost_factor double precision DEFAULT 0.0 NOT NULL,
private_projects_minutes_cost_factor double precision DEFAULT 1.0 NOT NULL,
config jsonb DEFAULT '{}'::jsonb NOT NULL
config jsonb DEFAULT '{}'::jsonb NOT NULL,
executor_type smallint
);
CREATE SEQUENCE ci_runners_id_seq
......@@ -29,7 +29,7 @@ module API
def get_runner_details_from_request
return get_runner_ip unless params['info'].present?
attributes_for_keys(%w(name version revision platform architecture), params['info'])
attributes_for_keys(%w(name version revision platform architecture executor), params['info'])
.merge(get_runner_config_from_request)
.merge(get_runner_ip)
end
......
......@@ -38,6 +38,7 @@ RSpec.describe API::Ci::Helpers::Runner do
let(:revision) { '10.0' }
let(:platform) { 'test' }
let(:architecture) { 'arm' }
let(:executor) { 'shell' }
let(:config) { { 'gpus' => 'all' } }
let(:runner_params) do
{
......@@ -48,6 +49,7 @@ RSpec.describe API::Ci::Helpers::Runner do
'revision' => revision,
'platform' => platform,
'architecture' => architecture,
'executor' => executor,
'config' => config,
'ignored' => 1
}
......@@ -57,12 +59,13 @@ RSpec.describe API::Ci::Helpers::Runner do
subject(:details) { runner_helper.get_runner_details_from_request }
it 'extracts the runner details', :aggregate_failures do
expect(details.keys).to match_array(%w(name version revision platform architecture config ip_address))
expect(details.keys).to match_array(%w(name version revision platform architecture executor config ip_address))
expect(details['name']).to eq(name)
expect(details['version']).to eq(version)
expect(details['revision']).to eq(revision)
expect(details['platform']).to eq(platform)
expect(details['architecture']).to eq(architecture)
expect(details['executor']).to eq(executor)
expect(details['config']).to eq(config)
expect(details['ip_address']).to eq(ip_address)
end
......
......@@ -903,8 +903,9 @@ RSpec.describe Ci::Runner do
describe '#heartbeat' do
let(:runner) { create(:ci_runner, :project) }
let(:executor) { 'shell' }
subject { runner.heartbeat(architecture: '18-bit', config: { gpus: "all" }) }
subject { runner.heartbeat(architecture: '18-bit', config: { gpus: "all" }, executor: executor) }
context 'when database was updated recently' do
before do
......@@ -940,6 +941,26 @@ RSpec.describe Ci::Runner do
expect_redis_update
does_db_update
end
%w(custom shell docker docker-windows docker-ssh ssh parallels virtualbox docker+machine docker-ssh+machine kubernetes some-unknown-type).each do |executor|
context "with #{executor} executor" do
let(:executor) { executor }
it 'updates with expected executor type' do
expect_redis_update
subject
expect(runner.reload.read_attribute(:executor_type)).to eq(expected_executor_type)
end
def expected_executor_type
return 'unknown' if executor == 'some-unknown-type'
executor.gsub(/[+-]/, '_')
end
end
end
end
def expect_redis_update
......@@ -953,6 +974,7 @@ RSpec.describe Ci::Runner do
expect { subject }.to change { runner.reload.read_attribute(:contacted_at) }
.and change { runner.reload.read_attribute(:architecture) }
.and change { runner.reload.read_attribute(:config) }
.and change { runner.reload.read_attribute(:executor_type) }
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