Add cost_factor params to Runner API
What does this MR do?
It adds cost factor params to Runners API, only available for gitlab.com.
It is intended to be used by Gitlab SREs to update the factors automatically if needed.
Currently, it could be done via UI only, which works while we have a relatively small amount of runners that need to be updated. Using rails-console is another option, but the API approach will be safer and more consistent.
.com case, as I have an issue with routes reloading.
I tried:
context 'when runner is shared' do
it 'updates runner' do
...
end
# THIS ONE WORKS
context 'when it is not gitlab.com' do
it 'does not update cost factors' do
update_runner(shared_runner.id,admin,
public_projects_minutes_cost_factor: 1.1,
private_projects_minutes_cost_factor: 2.2)
shared_runner.reload
expect(shared_runner.public_projects_minutes_cost_factor).to eq(0.0)
expect(shared_runner.private_projects_minutes_cost_factor).to eq(1.0)
end
end
# THIS ONE DOESN'T AS IT WON'T RELOAD THE CODE
context 'when on gitlab.com' do
before do
allow(Gitlab).to receive(:com?) { true }
Rails.application.reload_routes!
end
after do
allow(Gitlab).to receive(:com?) { false }
Rails.application.reload_routes!
end
it 'updates cost factors' do
update_runner(shared_runner.id,admin,
public_projects_minutes_cost_factor: 1.1,
private_projects_minutes_cost_factor: 2.2)
shared_runner.reload
expect(shared_runner.public_projects_minutes_cost_factor).to eq(1.1)
expect(shared_runner.private_projects_minutes_cost_factor).to eq(2.2)
end
end
end
Does this MR meet the acceptance criteria?
Conformity
- [-] Changelog entry
- [-] Documentation (if required)
-
Code review guidelines -
Merge request performance guidelines -
Style guides - [-] Database guides
- [-] Separation of EE specific content
Availability and Testing
For testing an updated API you could run something like this: curl --request PUT --header "PRIVATE-TOKEN: <YOUR_TOKEN>" --form "public_projects_minutes_cost_factor=7.7" http://localhost:3000/api/v4/runners/6
You should mock Gitlab#com? to return true on your instance.
Security
N/A
Related to #213822