Notify the user when CI usage falls below a threshold (with existing notifications UX)
Problem to solve
The notification mechanism for CI usage relies on the legacy cronjob reset. In order to deprecate the legacy cronjob we need to move the notification data to the monthly tracking table in order to effectively notify users when a threshold for CI usage is reached.
User experience
When the usage falls below a specific threshold or the user has exceeded their limit, we should notify the user that their limit has been reached
Proposal
Given that the rollout of monthly tracking of CI minutes will occur side-by-side with the existing global tracking in namespace_statistics
, this issue is about switching the data that the notification uses to send out the email to the customer from the global tracking to the monthly tracking.
When we notify the customer about CI minutes usage we store some information in namespaces
table:
-
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
To migrate this data to the new monthly tracking to also benefit from these values to be lazily reset on a monthly basis we could take 2 routes:
Route 1
Add 2 new columns to ci_namespace_monthly_usages
:
-
notified_level
to replacelast_ci_minutes_usage_notification_level
-
notified_at
to replacelast_ci_minutes_notification_at
- Update
Ci::Minutes::EmailNotificationService
to also update the new columns inci_namespace_monthly_usages
Route 2 (preferred if possible)
Add 1 new column to ci_namespace_monthly_usages
:
-
notified_level
to replacelast_ci_minutes_usage_notification_level
andlast_ci_minutes_notification_at
.
When looking at the usage of last_ci_minutes_notification_at
it is used only in the scenario when the namespace has exceeded the quota. It seems that originally we only had last_ci_minutes_notification_at
but later on we added notification for warning levels (30% and 5% remaining) that we decided to add last_ci_usage_notification_level
.
In the scenario when the user runs out of minutes, the notified_level
would be 0
since 0%
is the remaining quota. We don't have a use case for explicitly indicate "when" the notification was sent since we don't have the timestamp for when we send out other warning notifications.