Skip to content

Track CI minutes notifications sent out for new monthly tracking

Fabio Pitino requested to merge track-ci-minutes-notifications-monthly into master

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

Availability and Testing

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
Edited by Fabio Pitino

Merge request reports