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