Monitor Snowpipe with alerts¶
Snowpipe loads files in the background, so a problem such as a pipe that stops or a file that fails to load can go unnoticed until someone checks the copy history. A Snowflake alert checks a condition on a schedule, or when new rows arrive in a table, and runs an action when the condition is met. Most Snowpipe alerts check the Snowpipe events in your event table. You can create an alert in the following ways:
- By using a template. Snowflake provides templates for common Snowpipe problems, such as pipes that stop. You choose the pipes to monitor and where to send notifications, and Snowflake writes the condition and the notification for you.
- By writing your own alert. Your alert’s condition can query any Snowpipe event, such as the event for a file that fails to load. The alert’s action can run any SQL statement, such as a call to a stored procedure that pauses a pipe.
Snowpipe can also send error notifications to your cloud messaging service when a file fails to load. For Snowpipe Streaming, see Monitor Snowpipe Streaming.
Choose between alerts and error notifications¶
The following table compares alerts with error notifications:
| Characteristic | Alerts | Error notifications |
|---|---|---|
| What they report | Pipes that stop or stall because of an error, notification channel errors, throttled pipes, and files that arrive for a paused pipe. An alert that you write yourself can also report files that fail to load, or pipes that stop loading files for any reason, such as event notifications that stop arriving. | Files that fail to load. |
| How you’re notified | Email or webhook, through a notification integration. An alert created from a template can also send an email or in-app notification to the user who creates the alert, without an integration. An alert that you write yourself can also send a message to Amazon SNS, Google Cloud Pub/Sub, or Microsoft Azure Event Grid, or run any SQL statement. | A message in Amazon SNS, Google Cloud Pub/Sub, or Microsoft Azure Event Grid, through an error integration. |
| When you’re notified | The next time the alert runs. Alerts created from templates run every 5 or 15 minutes by default. | Shortly after a file fails to load. |
| Pipes covered | Every pipe in an account, database, or schema, or only the pipes whose names start with specified text. Pipes in a database that has its own event table need a separate alert. | Each pipe that you add an error integration to. |
| What you set up | An event level that records the events, the alert, and a notification integration. An alert created from a template doesn’t need an integration to notify the user who creates it. | An error integration and the ERROR_INTEGRATION property on each pipe. |
| Costs | Event logging, and the compute that the alert uses each time it runs. For more information, see Alert costs. | No event logging or alert compute. |
Use error notifications if you need to know only about files that fail to load and you already consume messages from your cloud messaging service. Use alerts if you also want to know when a pipe stops or Snowflake can’t read a notification channel, if you want email, webhook, or in-app notifications, or if you want one alert to cover many pipes. You can use both for the same pipe.
Neither option reports the following problems without extra work:
- Files that load partially. If a pipe’s
ON_ERRORsetting lets Snowpipe load the valid rows of a file that contains errors, Snowpipe doesn’t send an error notification or record aFAILEDevent for the file. To find these files, query the COPY_HISTORY table function for thePartially loadedstatus from a scheduled alert, or turn on error logging for the target table and create an alert on the error table. - Files that never reach Snowpipe. If your cloud storage service stops sending event notifications, or your application stops calling the Snowpipe REST API, no file fails and Snowpipe records no error. To catch this problem, write a scheduled alert that checks when the pipe last loaded a file.
To find out when a pipe breaks, create an alert from the SNOWPIPE_PIPE_ERROR template and an alert on pipes that haven’t loaded files recently. If your pipes use event notifications from Google Cloud Storage or Microsoft Azure, also create an alert from the SNOWPIPE_NOTIFICATION_CHANNEL_ERROR template. No template reports files that fail to load. To catch them, keep error notifications, or create an alert on files that fail to load before you remove the error integration from each pipe.
Alert costs¶
Alerts that check Snowpipe events need event logging, which incurs costs for recording the events in the event table. For more information, see Costs of telemetry data collection.
Every alert also incurs costs for the compute that it uses each time it runs, on a warehouse or on serverless compute. One alert can monitor many pipes, so the compute cost depends mostly on how many alerts you create and how often they run. For example, an alert that runs every 5 minutes runs 288 times a day. To see the credits that serverless alerts use, query the SERVERLESS_ALERT_HISTORY view.
If an alert uses a warehouse, each run resumes the warehouse if it’s suspended, and Snowflake bills at least one minute each time the warehouse resumes. If the warehouse’s AUTO_SUSPEND time is longer than the time between runs, the warehouse doesn’t suspend between runs, so you pay for the warehouse the whole time that the alert is active. To avoid this cost, use serverless compute, or make the time between runs longer than the warehouse’s AUTO_SUSPEND time. For more information, see Understanding the costs of alerts.
Snowpipe alert templates¶
The following table lists the Snowpipe alert templates. Under each template ID is the name that Snowsight shows for the template:
| Template | What it reports | Required LOG_EVENT_LEVEL | Default schedule |
|---|---|---|---|
SNOWPIPE_PIPE_ERRORPipe error alert | Pipes that stop or stall because of an error, such as a dropped stage or a missing permission. For the pipe states, see Pipe execution states. At WARN, the template also reports pipes that Snowflake stops (STOPPED_BY_SNOWFLAKE_ADMIN or STOPPED_FEATURE_DISABLED) and cloned pipes (STOPPED_CLONED). | ERROR or WARN | 5 minutes |
SNOWPIPE_NOTIFICATION_CHANNEL_ERRORNotification channel error alert | Errors reading the Google Cloud Pub/Sub subscription or Microsoft Azure storage queue that sends event notifications to your pipes. These errors usually mean a configuration problem, such as missing permissions. To fix the problem, see Event notifications don’t reach Snowflake. The alert identifies the notification channel, not the pipes that use the channel. Snowflake doesn’t record these errors for Amazon S3. To find out when event notifications stop arriving from any cloud storage service, write a scheduled alert. | ERROR, set on the account | 5 minutes |
SNOWPIPE_PIPE_THROTTLEDPipe throttled alert | Pipes that Snowflake throttles because the account, the pipe, or the target table exceeds a rate limit. For pipes that use automated loading, throttling delays loading. If you call the Snowpipe REST API, throttled requests fail, so submit those files again. | WARN | 15 minutes |
SNOWPIPE_FILES_RECEIVED_FOR_PAUSED_PIPEFiles received for paused pipe alert | Files that arrive for a paused pipe. Snowpipe keeps these files in the pipe’s queue for up to 14 days, and loads them after you resume the pipe. The template doesn’t report pipes that were paused before you set LOG_EVENT_LEVEL. To find paused pipes, each run checks every pipe_lifecycle event in the event table, so runs take longer and cost more as the event table grows. | DEBUG | 15 minutes |
At the DEBUG level, Snowpipe records at least one event for every file, so DEBUG costs more than ERROR, WARN, or INFO.
At the WARN level, an alert created from SNOWPIPE_PIPE_ERROR reports every pipe in a cloned database or schema, because each cloned pipe records the STOPPED_CLONED state. If you clone databases or schemas often, set SCOPE_ACTIVE to DATABASE or SCHEMA, and name the database or schema that contains your pipes, so that the alert doesn’t cover clones outside it. A DATABASE scope still covers schemas that someone clones within that database.
Snowflake might add templates or change their variables. To see the current templates and variables, call the functions shown in the first two steps of Create an alert from a template.
Template variables¶
The templates have the following variables, which you set in the template_variables object of the TEMPLATE_PARAMS clause:
SCOPE_ACTIVE: The pipes to monitor. Valid values areACCOUNT(the default),DATABASE, andSCHEMA. ForDATABASE, also setSCOPE_DATABASE. ForSCHEMA, also setSCOPE_DATABASEandSCOPE_SCHEMA. The database and schema names that you set aren’t case-sensitive. If you misspell a name, the alert runs but never finds a problem.PIPE_NAME_FILTER: Optional text that limits the alert to pipes whose names start with the text. The filter isn’t case-sensitive. In the filter,_matches any single character, and%matches any sequence of characters, so to match text anywhere in a pipe name, start the filter with%.NOTIFICATION_MODE: How the alert sends notifications. Valid values areEMAIL(the default),IN_APP, andWEBHOOK. Specify the value in uppercase.EMAIL_NOTIFICATION_INTEGRATIONorWEBHOOK_NOTIFICATION_INTEGRATION: The notification integration that sends the notification, for theNOTIFICATION_MODEthat you choose. ForEMAIL, omit the integration to send the email to the user who creates the alert.IN_APPdoesn’t use an integration, and sends the notification to the user who creates the alert.WEBHOOKrequires an integration.
SNOWPIPE_NOTIFICATION_CHANNEL_ERROR always monitors the whole account, so it doesn’t have the scope and pipe name variables, and Snowflake returns an error if you set them. Instead, it has a CHANNEL_NAME_FILTER variable, which limits the alert to notification channels whose names contain the filter text anywhere, not only at the start. This filter also isn’t case-sensitive, and _ and % are wildcards.
What each run reports¶
Each run checks the events that Snowpipe recorded since the previous successful run. The templates don’t remove duplicate notifications, so if Snowpipe keeps recording a problem, such as a throttled pipe, the alert sends a notification on every run. Each run of SNOWPIPE_PIPE_ERROR reports up to 50 of the most recent events. To see all the events, query the event table.
Before you create an alert¶
Make sure that you have the following:
-
Snowpipe events. Set
LOG_EVENT_LEVELon the pipes, or on their schema, database, or account, to a level that records the events that the alert checks. For the level that each template needs, see Snowpipe alert templates. For example, to record theERRORevents thatSNOWPIPE_PIPE_ERRORchecks for every pipe inmydb, runALTER DATABASE mydb SET LOG_EVENT_LEVEL = ERROR;. To set the level on a database, you need theMODIFY LOG EVENT LEVELprivilege on the account and theMODIFYprivilege on the database. For more information, see Enable Snowpipe events. If the level doesn’t record the events, the alert runs but never finds a problem. -
A way to be notified. An alert created from a template can send an email to your own verified email address, or an in-app notification to you, without a notification integration. To notify other users, or to send a webhook notification, create an email or webhook notification integration. To send notifications to a chat tool such as Slack or Microsoft Teams, use a webhook notification integration. An alert that you write yourself needs a notification integration to send any notification. For email through an integration, note the following:
- Recipients must be users in your account who have verified their email addresses. Administrators can start email verification for other users, such as a user for a team mailing list, by calling SYSTEM$START_USER_EMAIL_VERIFICATION.
- If the integration sets
ALLOWED_RECIPIENTS, every recipient must be in that list. - Alerts that don’t specify recipients, such as the alerts in Write your own alert, send email to the integration’s
DEFAULT_RECIPIENTS.
The following example uses the
ACCOUNTADMINrole, which can create integrations, to create the email notification integration that the examples in this topic use: -
Privileges. Use a role that has the privileges to create alerts and the
USAGEprivilege on the notification integration, if you use one. The examples in this topic create serverless alerts, which also require theEXECUTE MANAGED ALERTprivilege on the account. The alert runs with the privileges of the role that owns it, so that role must also be able to query the event table:- The default event table,
SNOWFLAKE.TELEMETRY.EVENTS. Templates query theSNOWFLAKE.TELEMETRY.EVENTS_VIEWview, which requires theSNOWFLAKE.EVENTS_VIEWERapplication role. The alert on files that fail to load queriesSNOWFLAKE.TELEMETRY.EVENTS, which requires theSNOWFLAKE.EVENTS_ADMINapplication role. That role can also delete events from the event table. - An event table that you created. Grant the role the
SELECTprivilege on the event table, and theUSAGEprivilege on its database and schema.
The following example creates a role and grants it to a user. The role gets the privileges to create serverless alerts from templates in the
mydb.myschemaschema when the default event table is active, and to use themy_whwarehouse for queries such as checking the alert history. For the alert on files that fail to load, grantSNOWFLAKE.EVENTS_ADMINinstead ofSNOWFLAKE.EVENTS_VIEWER. If you don’t use a notification integration, omit theGRANT USAGE ON INTEGRATIONstatement. Only theACCOUNTADMINrole can grant theEXECUTE ALERTprivilege, so the example uses that role:Before you create an alert, switch to that role and its warehouse, for example with
USE ROLE my_alert_role;andUSE WAREHOUSE my_wh;, so that the role owns the alert and can run the queries in this topic. For more information, see Roles for access to the default event table and EVENTS_VIEW. - The default event table,
-
The right database for the alert. Most templates query the event table that’s active for the database that contains the alert, and report only the events in that table. If some of your databases have their own event tables, an alert with
SCOPE_ACTIVEset toACCOUNTdoesn’t report pipes in those databases, so create an alert in each of those databases.SNOWPIPE_NOTIFICATION_CHANNEL_ERRORalways queries the account’s event table, because Snowflake records notification channel events there.
Create an alert from a template¶
To create an alert from a template in Snowsight, complete the steps in Before you create an alert, and then see Creating a new alert. To notify other users, or to send a webhook notification, select a notification integration.
To create an alert from a template with SQL, complete the following steps:
-
To list the Snowpipe templates that are available in your account, call SYSTEM$LIST_ALERT_TEMPLATES:
If the function doesn’t return any templates, contact Snowflake Support.
-
To see a template’s variables, their defaults, and their allowed values, call SYSTEM$GET_ALERT_TEMPLATE:
-
Create the alert with CREATE ALERT … FROM TEMPLATE. The following example monitors every pipe in the
mydbdatabase and sends an email when a pipe stops:Because
TEMPLATE_PARAMSdoesn’t name a notification integration, the alert sends the email to you, the user who creates the alert. If you haven’t verified your email address, theCREATE ALERTstatement fails. To send the notification another way, or to other users, do one of the following:-
To send yourself an in-app notification instead, add
"NOTIFICATION_MODE": "IN_APP"totemplate_variables. -
To send an email to other users, set
EMAIL_NOTIFICATION_INTEGRATIONintemplate_variablesto your email notification integration. Then add anotification_configobject that names the same integration and lists the recipients:If you omit
notification_config, the alert sends email to the integration’sDEFAULT_RECIPIENTS. -
To send a webhook notification, set
NOTIFICATION_MODEtoWEBHOOKandWEBHOOK_NOTIFICATION_INTEGRATIONto your webhook notification integration. If you don’t set the integration, the alert’s action fails each time the alert finds a problem.
An alert sends notifications in one mode, so to send both an email and a webhook notification, create two alerts.
The alert runs on the template’s default schedule, which is every 5 minutes for this template. To run it less often and reduce its cost, add a
SCHEDULEclause afterFROM TEMPLATE, such asSCHEDULE = '30 MINUTE'. The example doesn’t specify a warehouse, so the alert uses serverless compute. To use a warehouse instead, add aWAREHOUSEclause afterFROM TEMPLATE. For more information about how each choice affects cost, see Alert costs. -
-
Snowflake creates alerts in a suspended state. To start the alert, resume it:
The first run checks the events from the previous hour.
-
To check that the alert runs, use the role that owns the alert, or the
ACCOUNTADMINrole, to query the ALERT_HISTORY table function:In the
STATEcolumn, look for the following values:SCHEDULEDorEXECUTING: The run hasn’t started yet, or is in progress.CONDITION_FALSE: The alert ran and found no problems. You also see this state ifLOG_EVENT_LEVELdoesn’t record the events that the template checks, or if the scope names a database or schema that doesn’t exist.TRIGGERED: The alert found a problem and ran its action. If the email went only to the user who created the alert instead of to your recipients, check thattemplate_variablessetsEMAIL_NOTIFICATION_INTEGRATION.FAILED,CONDITION_FAILED, orACTION_FAILED: The alert failed. TheSQL_ERROR_MESSAGEcolumn explains why. For example, the action fails ifNOTIFICATION_MODEisWEBHOOKandtemplate_variablesdoesn’t setWEBHOOK_NOTIFICATION_INTEGRATION, if the notification integration was dropped, if the role that owns the alert no longer has theUSAGEprivilege on the integration, or if a recipient isn’t a verified user or isn’t in the integration’sALLOWED_RECIPIENTSlist.CANCELLED: The run was canceled, for example because the alert was suspended.
-
Optional: If the alert uses an email notification integration, check that the integration delivers email to your recipients before a pipe has a problem. To send a test message, call SYSTEM$SEND_SNOWFLAKE_NOTIFICATION:
Change or stop an alert created from a template¶
To change an alert’s variables or recipients, use ALTER ALERT … FROM TEMPLATE with the same template ID. The statement replaces the alert’s settings, so specify the complete TEMPLATE_PARAMS clause, and repeat any SCHEDULE, COMMENT, or RUNBOOK that you set. If you omit a setting, the following happens:
- Variables,
SCHEDULE,COMMENT, andRUNBOOK. Each setting resets to the template’s default. notification_config. If the alert sends email through an integration, it sends the email to the integration’sDEFAULT_RECIPIENTS. If the integration doesn’t setDEFAULT_RECIPIENTS, the alert’s action fails.WAREHOUSE. The alert keeps its current warehouse.
For example, the following statement limits the alert to pipes whose names start with orders:
To stop notifications while you fix a pipe, run ALTER ALERT mydb.myschema.pipe_error_alert SUSPEND;, and resume the alert when you’re done. To remove the alert, use DROP ALERT.
Write your own alert¶
Write your own alert when no template covers the problem, such as files that fail to load, or when you want the alert to do more than send a notification. To send a notification from your own alert, call SYSTEM$SEND_SNOWFLAKE_NOTIFICATION with a notification integration. Before you create an alert, complete the steps in Before you create an alert.
Create an alert on files that fail to load¶
Before you create an alert on files that fail to load, make sure of the following:
LOG_EVENT_LEVELisERRORor more verbose for the pipes that you want to monitor, so that Snowpipe records an event for each file that fails to load.- Change tracking is enabled on the event table that the alert queries. It’s already enabled on
SNOWFLAKE.TELEMETRY.EVENTS. For an event table that you created, runALTER TABLE mydb.myschema.my_events SET CHANGE_TRACKING = TRUE;. - The notification integration sets
DEFAULT_RECIPIENTS, because the example doesn’t specify recipients. - The alert queries the event table that receives your pipes’ events. Events for pipes in a database that has its own event table don’t go to the account’s event table, so create another alert that queries that database’s event table.
The following example sends an email through the my_email_int notification integration shortly after a file fails to load:
Because the alert has no schedule, it’s an alert on new data: Snowflake evaluates its condition each time new rows arrive in the event table, and checks only the new rows. Rows can arrive often, so the example uses serverless compute to limit the cost. For more information, see Alert costs.
To include details such as the pipe name and the error message in the email, use the results of the condition in the action. For more information, see Checking the results of the SQL statement for the condition in the alert action.
When you get the email, find the file and its error by running the query in Find recent errors. Snowpipe doesn’t try a failed file again, so after you fix the problem, reload the file.
Create an alert on pipes that haven’t loaded files recently¶
Error notifications and Snowpipe events report only problems that Snowflake detects. If event notifications stop arriving, for example after someone deletes the event notification on your bucket, Snowflake doesn’t record an error. To catch that problem, create a scheduled alert that calls SYSTEM$PIPE_STATUS and checks whether lastIngestedTimestamp is older than the longest normal gap between your files. This alert doesn’t query the event table, so it works even if LOG_EVENT_LEVEL is OFF, and its role doesn’t need access to the event table. The role that owns the alert needs the MONITOR or OWNERSHIP privilege on the pipe, or the MONITOR EXECUTION privilege on the account.
The following alert checks every hour and sends an email through the my_email_int notification integration if orders_pipe hasn’t loaded a file in the last two hours:
To check several pipes with one alert, call SYSTEM$PIPE_STATUS once for each pipe in the subquery, and combine the results with UNION ALL. If your pipes have different normal gaps between files, create one alert for each group of pipes that have a similar gap.
If the pipe hasn’t loaded any files yet, for example right after you create or recreate it, SYSTEM$PIPE_STATUS doesn’t return lastIngestedTimestamp, and this alert doesn’t send an email. While the pipe stays idle, the alert sends an email every hour. To stop the emails while you investigate, run ALTER ALERT mydb.myschema.orders_pipe_idle_alert SUSPEND;.
Resume alerts after a failover¶
If a failover group replicates an alert to another account, including an alert that you write yourself, the replicated alert doesn’t run while the group is read-only in that account. After a failover, resume each alert in the account that becomes the primary. Account-level parameters, such as LOG_EVENT_LEVEL set on the account, replicate only if the failover group includes ACCOUNT PARAMETERS, and notification integrations replicate only if it includes INTEGRATIONS and its ALLOWED_INTEGRATION_TYPES includes NOTIFICATION INTEGRATIONS. Otherwise, set them up in that account before you resume the alerts. Event tables aren’t replicated, so an alert checks only the events in the event table of the account where it runs. For more information, see Introduction to replication and failover across multiple accounts.