Commit 2d79fae1 authored by Fabio Pitino's avatar Fabio Pitino

Track Shared Runners duration separate from CI minutes consumption

shared_runners_duration will always be tracked for a namespace
even though the CI minutes consumption is 0 because the project
is public or the namespace has unlimited CI minutes.

Changelog: added
EE: true
parent 5e510997
......@@ -6,33 +6,17 @@ module Ci
# Calculates consumption and updates the project and namespace statistics(legacy)
# or ProjectMonthlyUsage and NamespaceMonthlyUsage(not legacy) based on the passed build.
def execute(build)
if Feature.enabled?(:ci_always_track_shared_runners_usage, build.project, default_enabled: :yaml)
return unless build.complete?
return unless build.duration&.positive?
return unless build.shared_runner_build?
ci_minutes_consumed = ::Gitlab::Ci::Minutes::BuildConsumption.new(build, build.duration).amount
update_usage(build, ci_minutes_consumed)
else
legacy_update_minutes(build)
end
end
private
def legacy_update_minutes(build)
return unless build.cost_factor_enabled?
return unless build.complete?
return unless build.duration&.positive?
return unless build.shared_runner_build?
consumption = ::Gitlab::Ci::Minutes::BuildConsumption.new(build, build.duration).amount
return unless consumption > 0
ci_minutes_consumed = ::Gitlab::Ci::Minutes::BuildConsumption.new(build, build.duration).amount
::Ci::Minutes::UpdateProjectAndNamespaceUsageWorker.perform_async(consumption, project.id, namespace.id, build.id)
update_usage(build, ci_minutes_consumed)
end
private
def update_usage(build, ci_minutes_consumed)
::Ci::Minutes::UpdateProjectAndNamespaceUsageWorker
.perform_async(ci_minutes_consumed, project.id, namespace.id, build.id, { duration: build.duration })
......
---
name: ci_always_track_shared_runners_usage
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/72316
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/343258
milestone: '14.4'
type: development
group: group::pipeline execution
default_enabled: false
......@@ -128,14 +128,6 @@ RSpec.describe Ci::Minutes::UpdateBuildMinutesService do
subject
end
context 'when feature flag ci_always_track_shared_runners_usage is disabled' do
before do
stub_feature_flags(ci_always_track_shared_runners_usage: false)
end
it_behaves_like 'does nothing'
end
end
context 'when statistics and usage have existing amounts' do
......
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