Notifications and actions for per-user quotas¶
A per-user quota can notify users and administrators as spending approaches or exceeds a threshold, and it can run stored procedures as custom actions. This topic covers notifications, custom actions, cycle-start actions, and the events Snowflake records for them. Thresholds are a percentage of the per-user limit, evaluated on actual or projected spend. For more information, see Threshold types.
Configure notifications¶
Quotas support two types of notifications: individual user notifications that alert users when they approach or exceed thresholds, and admin summary notifications that provide aggregated reports to administrators.
Notify individual users¶
You can configure notifications that are sent to individual users when they cross specified thresholds of their per-user quota. For each threshold, you specify the following:
- The threshold percentage (for example,
80for 80% of the quota). - The threshold type:
PROJECTED(default) orACTUAL. - Whether to notify the user directly (
TRUEorFALSE). - Which limit the notification is based on (
'MONTHLY','WEEKLY', or'DAILY').
Add a notification threshold:
Remove a notification threshold:
View all configured notification thresholds:
The method returns the following columns:
| Column name | Data type | Description |
|---|---|---|
THRESHOLD | NUMBER | Threshold percentage at which the notification is triggered. |
SPEND_STRATEGY | VARCHAR | Type of threshold: PROJECTED or ACTUAL. |
NOTIFY_USER | BOOLEAN | Indicates whether the user is notified when they cross the threshold. |
ADDED_TIMESTAMP | TIMESTAMP_TZ(9) | Indicates when the notification was added. |
Note
- Notifications for projected spend thresholds are sent at most once per threshold within a 24-hour period. If a user stays projected to cross the threshold, Snowflake sends the notification again once every 24 hours.
- Notifications for actual spend thresholds are sent at most once per quota cycle, when the user’s spend crosses the threshold.
Send admin summaries¶
Quota admins can configure admin summary notifications to receive aggregated reports of users who breach per-user quota thresholds. A summary is sent after a quota evaluation when new threshold breaches are detected.
Each summary includes the following information:
- User name
- Threshold breached
- Threshold type (Actual or Projected)
- User credit usage at evaluation time
Snowflake delivers summaries through a notification integration, a list of email recipients, or both. If neither is configured, summary notifications are suppressed.
Configure a notification integration for admin summaries:
ADD_NOTIFICATION_INTEGRATION accepts only webhook and queue notification integrations, including Amazon SNS, Azure Event Grid, and Google Cloud Pub/Sub queue integrations. Email integrations (TYPE = EMAIL) aren’t accepted. To send admin summaries by email, use SET_ADMIN_EMAILS.
Remove the notification integration:
View configured notification integrations:
Configure email recipients for admin summaries:
Verify notification email addresses¶
Each email address used for notifications, for users and for admin summaries, must be verified. If
a user’s email address isn’t available, an informational event is logged in the event table. By
default, events are logged in SNOWFLAKE.TELEMETRY.EVENTS, but you can configure your own event
table. To verify a whole email domain, use
SYSTEM$VERIFY_DNS_DOMAIN.
Configure custom actions¶
Quota admins can configure custom actions that run when a user breaches a per-user quota threshold. Custom actions are implemented as stored procedures. When a threshold is breached, the stored procedure is invoked for each user who has exceeded the threshold.
Custom actions are evaluated against the monthly per-user limit only. You can configure them with SQL for any resource scope, but Snowsight offers them only for quotas scoped to warehouses.
For quotas scoped to warehouses, a custom action runs only after Snowflake attributes the warehouse usage to the quota, which can happen several hours after the query finishes. Users can keep running queries during that delay, so set thresholds with some buffer for that additional usage.
The quota evaluation process passes the list of user IDs who have exceeded their quota thresholds during the current quota run as the first argument to the stored procedure. Every quota run covers the aggregated usage from the beginning of the current month to the quota run time. Any additional configured parameters are passed after the list of user IDs.
Note
Stored procedures used as custom actions must use EXECUTE AS OWNER. Before you can register a stored
procedure, the SNOWFLAKE application must be granted the USAGE privilege on the stored procedure and on the
database and schema that contain it. For example, for cost_mgmt_db.actions.disable_user_proc(VARCHAR):
Add a custom action at a specified threshold:
Remove custom actions:
Note
The stored procedure name must include the argument signature. Copy the value from the
PROCEDURE_FQN column of GET_CUSTOM_ACTIONS(). If the remove call finds no match,
it returns a success message with “0 custom actions removed”.
View all configured custom actions:
The method returns the following columns:
| Column name | Data type | Description |
|---|---|---|
ACTION_ID | VARCHAR | Internal ID to distinguish the various actions. |
PROCEDURE_FQN | VARCHAR | Fully qualified name of the stored procedure. |
PROCEDURE_ARGS | ARRAY | JSON array of additional parameters passed to the stored procedure. |
SPEND_STRATEGY | VARCHAR | Spend strategy: PROJECTED or ACTUAL. |
THRESHOLD | NUMBER | Threshold percentage at which the custom action is triggered. |
LAST_TRIGGER_ATTEMPT_TIME | TIMESTAMP_TZ(9) | Specifies the time when the custom action was last triggered. |
ADDED_TIMESTAMP | TIMESTAMP_TZ(9) | Specifies the time when the custom action was added to the quota. |
Note
For projected spend thresholds, the custom action is triggered at most once per user within a 24-hour period. For actual spend thresholds, the action is triggered once per user per quota cycle.
Example: Disable users at 100% of their quota¶
The following example creates a stored procedure that disables users who have exceeded their
quota, then configures it as a custom action at 100% actual spend. Because the procedure runs with
owner’s rights, its owner role must be able to alter the affected users: only the role with the
OWNERSHIP privilege on a user, or a higher role, can change most user properties. For more
information, see ALTER USER. The owner role also needs access to the
SNOWFLAKE.ACCOUNT_USAGE.USERS view, which can lag behind recent user changes, so a user created
shortly before the threshold is crossed might be skipped:
Configure a cycle-start action¶
Quota admins can optionally configure a cycle-start (reset) action that runs automatically at the beginning of each UTC calendar month. The reset action is implemented as a stored procedure and is intended to restore states affected by quota enforcement, such as re-enabling users or restoring access to resources.
Cycle-start actions run on the monthly cycle only. You can configure them with SQL for any resource scope, but Snowsight offers them only for quotas scoped to warehouses.
You can configure only one reset action per quota. The reset action:
- Runs once at the beginning of each UTC calendar month.
- Runs independently of user-level threshold evaluations.
- Receives any configured parameters defined by the admin.
Set the cycle-start action:
View the current cycle-start action:
Remove the cycle-start action:
Example: Cycle-start action skeleton¶
The following example shows the structure of a cycle-start action: the procedure, the grant, and the configuration call. Replace the placeholder logic with your own. To re-enable users that a custom action disabled, the procedure needs to know which users those are, for example by having the custom action record each disabled user in a table that the cycle-start action reads and then clears.
Monitor quota events¶
Quota-related operational events are recorded in the Snowflake event table, providing visibility into whether notifications and custom actions ran successfully. Events include the following:
INFO: Successful per-user notification delivery, and successful execution of custom actions and cycle-start actions.ERROR: Failures of custom actions or cycle-start actions, invalid or inaccessible admin notification integrations, and unverified admin email recipients.
To query quota events, use a role that is granted the SNOWFLAKE.EVENTS_ADMIN application role. For
more information, see Roles for access to the default event table and EVENTS_VIEW.
To query quota events from the event table: