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

Merge branch 'merge-new-ci-minutes-tracking-flags' into 'master'

Merge feature flags related to new CI minutes tracking

See merge request gitlab-org/gitlab!75755
parents 38db26f1 28fd1d2c
......@@ -66,7 +66,7 @@ module Ci
end
def should_recalculate_purchased_minutes?
Feature.enabled?(:ci_reset_purchased_minutes_lazily, namespace, default_enabled: :yaml) &&
namespace.new_monthly_ci_minutes_enabled? &&
enabled? &&
any_purchased?
end
......
......@@ -62,7 +62,7 @@ module Ci
# We prefer to keep the queries here rather than scatter them across classes.
# rubocop: disable CodeReuse/ActiveRecord
def recalculate_extra_shared_runners_minutes_limits!(namespaces)
return if Feature.enabled?(:ci_reset_purchased_minutes_lazily, default_enabled: :yaml)
return if Feature.enabled?(:ci_use_new_monthly_minutes, default_enabled: :yaml)
namespaces
.joins(:namespace_statistics)
......
......@@ -31,7 +31,7 @@ module Ci
namespace_usage.update!(notification_level: current_alert_percentage)
if ci_minutes_use_notification_level?
if namespace.new_monthly_ci_minutes_enabled?
CiMinutesUsageMailer.notify(namespace, recipients).deliver_later
end
elsif notification.running_out?
......@@ -39,7 +39,7 @@ module Ci
namespace_usage.update!(notification_level: current_alert_percentage)
if ci_minutes_use_notification_level?
if namespace.new_monthly_ci_minutes_enabled?
CiMinutesUsageMailer.notify_limit(namespace, recipients, current_alert_percentage).deliver_later
end
end
......@@ -51,7 +51,7 @@ module Ci
namespace.update_columns(last_ci_minutes_notification_at: Time.current)
unless ci_minutes_use_notification_level?
unless namespace.new_monthly_ci_minutes_enabled?
CiMinutesUsageMailer.notify(namespace, recipients).deliver_later
end
elsif legacy_notification.running_out?
......@@ -62,7 +62,7 @@ module Ci
namespace.update_columns(last_ci_minutes_usage_notification_level: current_alert_percentage)
unless ci_minutes_use_notification_level?
unless namespace.new_monthly_ci_minutes_enabled?
CiMinutesUsageMailer.notify_limit(namespace, recipients, current_alert_percentage).deliver_later
end
end
......@@ -84,12 +84,6 @@ module Ci
def current_alert_percentage
notification.stage_percentage
end
def ci_minutes_use_notification_level?
strong_memoize(:ci_minutes_use_notification_level) do
Feature.enabled?(:ci_minutes_use_notification_level, namespace, default_enabled: :yaml)
end
end
end
end
end
---
name: ci_minutes_use_notification_level
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/69059
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/339324
milestone: '14.3'
type: development
group: group::pipeline execution
default_enabled: false
---
name: ci_reset_purchased_minutes_lazily
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/73338
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/344821
milestone: '14.5'
type: development
group: group::pipeline execution
default_enabled: false
......@@ -111,6 +111,8 @@ RSpec.describe Ci::Minutes::Limit do
with_them do
before do
namespace.clear_memoization(:new_monthly_ci_minutes_enabled)
if previous_amount_used
create(:ci_namespace_monthly_usage,
namespace: namespace,
......@@ -123,7 +125,7 @@ RSpec.describe Ci::Minutes::Limit do
amount_used: 5_000)
end
stub_feature_flags(ci_reset_purchased_minutes_lazily: ff_enabled)
stub_feature_flags(ci_use_new_monthly_minutes: ff_enabled)
end
it 'has the expected purchased minutes' do
......
......@@ -77,9 +77,9 @@ RSpec.describe Ci::Minutes::NamespaceMonthlyUsage do
end
end
context 'when ci_reset_purchased_minutes_lazily feature flag is disabled' do
context 'when ci_use_new_monthly_minutes feature flag is disabled' do
before do
stub_feature_flags(ci_reset_purchased_minutes_lazily: false)
stub_feature_flags(ci_use_new_monthly_minutes: false)
end
it_behaves_like 'does not update the additional minutes'
......
......@@ -53,7 +53,7 @@ RSpec.describe Ci::Minutes::BatchResetService do
subject
end
context 'when feature flag ci_reset_purchased_minutes_lazily is enabled' do
context 'when feature flag ci_use_new_monthly_minutes is enabled' do
it 'resets CI minutes but does not recalculate purchased minutes for the namespace exceeding the monthly minutes' do
subject
......@@ -71,9 +71,9 @@ RSpec.describe Ci::Minutes::BatchResetService do
end
end
context 'when feature flag ci_reset_purchased_minutes_lazily is disabled' do
context 'when feature flag ci_use_new_monthly_minutes is disabled' do
before do
stub_feature_flags(ci_reset_purchased_minutes_lazily: false)
stub_feature_flags(ci_use_new_monthly_minutes: false)
end
it 'resets CI minutes and recalculates purchased minutes for the namespace exceeding the monthly minutes' do
......@@ -153,7 +153,7 @@ RSpec.describe Ci::Minutes::BatchResetService do
before do
allow(::Gitlab::CurrentSettings).to receive(:shared_runners_minutes).and_return(global_limit)
stub_feature_flags(ci_reset_purchased_minutes_lazily: false)
stub_feature_flags(ci_use_new_monthly_minutes: false)
end
it 'does not recalculate purchased minutes for any namespaces' do
......
......@@ -104,7 +104,7 @@ RSpec.describe Ci::Minutes::EmailNotificationService do
end
before do
stub_feature_flags(ci_minutes_use_notification_level: ff_enabled)
stub_feature_flags(ci_use_new_monthly_minutes: ff_enabled)
if namespace.namespace_statistics
namespace.namespace_statistics.update!(shared_runners_seconds: legacy_minutes_used.minutes)
......@@ -250,9 +250,9 @@ RSpec.describe Ci::Minutes::EmailNotificationService do
it_behaves_like 'matches the expectation'
context 'when feature flag ci_minutes_use_notification_level is disabled' do
context 'when feature flag ci_use_new_monthly_minutes is disabled' do
before do
stub_feature_flags(ci_minutes_use_notification_level: false)
stub_feature_flags(ci_use_new_monthly_minutes: false)
end
it_behaves_like 'matches the expectation'
......@@ -270,9 +270,9 @@ RSpec.describe Ci::Minutes::EmailNotificationService do
it_behaves_like 'matches the expectation'
context 'when feature flag ci_minutes_use_notification_level is disabled' do
context 'when feature flag ci_use_new_monthly_minutes is disabled' do
before do
stub_feature_flags(ci_minutes_use_notification_level: false)
stub_feature_flags(ci_use_new_monthly_minutes: false)
end
it_behaves_like 'matches the expectation'
......
......@@ -66,7 +66,7 @@ RSpec.describe Ci::BatchResetMinutesWorker do
let(:namespace) { last_namespace }
end
context 'when ci_reset_purchased_minutes_lazily is enabled' do
context 'when ci_use_new_monthly_minutes is enabled' do
it 'does not recalculate purchased minutes for the namespace exceeding the monthly minutes' do
subject
......@@ -74,9 +74,9 @@ RSpec.describe Ci::BatchResetMinutesWorker do
end
end
context 'when ci_reset_purchased_minutes_lazily is disabled' do
context 'when ci_use_new_monthly_minutes is disabled' do
before do
stub_feature_flags(ci_reset_purchased_minutes_lazily: false)
stub_feature_flags(ci_use_new_monthly_minutes: false)
end
it 'recalculates purchased minutes for the namespace exceeding the monthly minutes' 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