Track CI minutes notifications sent out for new monthly tracking
What does this MR do?
Related to #290961 (closed)
With the new historical monthly tracking of CI minutes done in Ci::Minutes::NamespaceMonthlyUsage
we are step by step migrating all the legacy tracking, done using Namespace
and NamespaceStatistics
model into this new mechanism.
The advantage, aside from having an historical view of CI minutes activities, is also that on a monthly basis we can automatically reset the data by creating a new record rather than doing a mass update via a cron job.
In this MR we are tackling the tracking of email notifications being sent out to namespace owners when remaining CI minutes fall below certain warning thresholds (30% and 5%) as well as when CI minutes quota is completely exceeded (0% remaining minutes). Today, the notifications that we sent out are tracked using 2 attributes:
-
namespaces.last_ci_minutes_usage_notification_level
when we notify the customer about warning levels of usage (30% and later a 5% remaining quota) -
namespaces.last_ci_minutes_notification_at
when we notify the customer that they exceeded the quota and no more jobs will be run
In the new monthly tracking we can actually condense this logic into 1 column: ci_namespace_monthly_usages.notification_level
and we migrate the behavior as:
scenario | legacy tracking (Namespace) | new monthly tracking (NamespaceMonthlyUsage) |
---|---|---|
Most/all CI minutes available (default at the beginning of each month) |
last_ci_minutes_usage_notification_level: nil and last_ci_minutes_notification_at: nil
|
notification_level: 100 |
Remaining minutes drop below 30% |
last_ci_minutes_usage_notification_level: 30 and last_ci_minutes_notification_at unchanged |
notification_level: 30 |
Remaining minutes drop below 5% |
last_ci_minutes_usage_notification_level: 5 and last_ci_minutes_notification_at unchanged |
notification_level: 5 |
Quota exceeded |
last_ci_minutes_usage_notification_level unchanged and last_ci_minutes_notification_at: Time.current
|
notification_level: 0 |
In a follow-up MR we will make changes to resetting notification_level
when those are manually reset by admins or when customer purchases additional minutes.
Database migrations
rails db:migrate:redo
== 20210824160459 AddNotificationLevelToCiNamespaceMonthlyUsages: reverting ===
-- remove_column(:ci_namespace_monthly_usages, :notification_level)
-> 0.0025s
== 20210824160459 AddNotificationLevelToCiNamespaceMonthlyUsages: reverted (0.0026s)
== 20210824160459 AddNotificationLevelToCiNamespaceMonthlyUsages: migrating ===
-- add_column(:ci_namespace_monthly_usages, :notification_level, :integer, {:limit=>2, :default=>100, :null=>false})
-> 0.0070s
== 20210824160459 AddNotificationLevelToCiNamespaceMonthlyUsages: migrated (0.0072s)
Screenshots or Screencasts (strongly suggested)
How to setup and validate locally (strongly suggested)
Does this MR meet the acceptance criteria?
Conformity
-
I have included changelog trailers, or none are needed. (Does this MR need a changelog?) -
I have added/updated documentation, or it's not needed. (Is documentation required?) -
I have properly separated EE content from FOSS, or this MR is FOSS only. (Where should EE code go?) -
I have added information for database reviewers in the MR description, or it's not needed. (Does this MR have database related changes?) -
I have self-reviewed this MR per code review guidelines. -
This MR does not harm performance, or I have asked a reviewer to help assess the performance impact. (Merge request performance guidelines) -
I have followed the style guides. -
This change is backwards compatible across updates, or this does not apply.
Availability and Testing
-
I have added/updated tests following the Testing Guide, or it's not needed. (Consider all test levels. See the Test Planning Process.) -
I have tested this MR in all supported browsers, or it's not needed. -
I have informed the Infrastructure department of a default or new setting change per definition of done, or it's not needed.
Security
Does this MR contain changes to processing or storing of credentials or tokens, authorization and authentication methods or other items described in the security review guidelines? If not, then delete this Security section.
-
Label as security and @ mention @gitlab-com/gl-security/appsec
-
The MR includes necessary changes to maintain consistency between UI, API, email, or other methods -
Security reports checked/validated by a reviewer from the AppSec team