You can send your team email alerts directly from Snowflake. This is useful when you want to monitor:
- When snowflakes credit usage increases by a percentage
- Resource consumption for snow pipes increases
You can do this by pairing a Snowflake Alert with a Notification Integration. Notification Integrations are Snowflake constructs that provide an interface to 3rd party services (e.g. queues, email, etc). Email-type integrations are natively supported.
- Create a Notification Integration for Email
CREATE NOTIFICATION INTEGRATION email_integ
TYPE=EMAIL
ENABLED=TRUE
ALLOWED_RECIPIENTS=('rigomoran@mail.com');
- Define a query to watch for a specific condition
SELECT SUM(credits_used) AS credits_used
FROM snowflake.account_usage.WAREHOUSE_METERING_HISTORY
WHERE start_time between CURRENT_DATE() and CURRENT_TIMESTAMP()
AND credits_used > 1;
This query shows the total credit consumption over the current day. This helps ensure we keep our consumption low.
- Send a test email
CALL SYSTEM$SEND_EMAIL(
'email_integ',
'rigomoran@mail.com',
'Email Alert: High Credit Usage for Warehouse',
'Credit usage has exceeded 1 credit for today'
)
Snowflake provides a stored procedure to the email.
- Create an Alert
CREATE OR REPLACE ALERT ALERT_HIGH_CREDIT_USAGE
WAREHOUSE = COMPUTE_WH
SCHEDULE = '30 MINUTES'
IF (EXISTS (
-- Check for a specific condition
)
THEN
-- Send an email
;
This is the basic syntax for an Alert. It requires a WAREHOUSE
to handle the compute, a SCHEDULE
to set the interval, an IF
condition to check for, and THEN
the action to perform.
- Put everything together
CREATE OR REPLACE ALERT ALERT_HIGH_CREDIT_USAGE
WAREHOUSE = COMPUTE_WH
SCHEDULE = '30 MINUTES'
IF (EXISTS (
-- Check for a specific condition
SELECT SUM(credits_used) AS credits_used
FROM snowflake.account_usage.WAREHOUSE_METERING_HISTORY
WHERE start_time between CURRENT_DATE() and SNOWFLAKE.ALERT.SCHEDULED_TIME()
AND credits_used > 1;
)
THEN
-- Send an email
CALL SYSTEM$SEND_EMAIL(
'email_integ',
'rigomoran@mail.com',
'Email Alert: High Credit Usage for Warehouse',
'Credit usage has exceeded 1 credit for today'
);
References
- Alerts Overview Snowflake Docs. snowflake.com
- Snowflake Alerts AICG Channel. youtube.com