Alerts as Code
Overview
Alerts in Rill allow you to monitor your data and receive notifications when specific conditions are met. While alerts can be created through the UI, defining them as code in YAML files provides version control, reproducibility, and the ability to manage complex alerting logic programmatically.
When you create an alert via a YAML file, it appears in the UI marked as Created through code.
If you're using live connectors (ClickHouse, Druid, Pinot, StarRocks, etc.), alerts are your primary tool for data quality monitoring. Since live connectors don't create local models, data quality tests won't run. Use alerts instead to validate your data on a schedule.
Alert Structure
An alert YAML file has the following core components:
type: alert
display_name: My Alert Name
# A brief description of what this alert monitors
# When to check the alert
refresh:
cron: "0 * * * *" # Every hour
# What data to check
data:
sql: SELECT * FROM my_model WHERE condition_is_bad
# Where to send notifications
notify:
email:
recipients:
- team@example.com
Scheduling Alerts
The refresh property defines when and how often the alert runs.
Cron Schedule
Use standard cron expressions to define the schedule:
refresh:
cron: "0 * * * *" # Every hour
time_zone: "America/New_York" # Optional timezone
Interval-Based Monitoring
Use intervals when you need to check data across multiple time windows, such as validating metrics for each hour or day. This is useful for time-series monitoring where you want to ensure data quality across a rolling window of time periods. Interval-based monitoring is more flexible than simple cron schedules when you need to check multiple historical periods on each evaluation.
refresh:
cron: "5 * * * *" # 5 minutes past each hour
intervals:
duration: PT1H # 1 hour intervals
limit: 24 # Check last 24 intervals
check_unclosed: false
Data Sources
Alerts support multiple data source types to query your data.
SQL Query
Execute raw SQL against your models:
data:
sql: |
SELECT *
FROM orders
WHERE created_at < NOW() - INTERVAL '24 hours'
AND status = 'pending'
The alert triggers when the query returns any rows.
Metrics SQL
Use metrics_sql when you want to query a metrics view using its defined dimensions and measures, rather than writing raw SQL against the underlying model. This approach leverages the metrics view's security policies and allows you to reference measures and dimensions by name. For details on the metrics_sql syntax, see Metrics SQL APIs.
data:
metrics_sql: |
SELECT *
FROM sales_metrics
WHERE total_revenue < 1000
Custom API
Use a custom API when you want to reuse complex query logic that's already defined as a Custom API in your project. This approach is useful for sharing validation logic between alerts and other integrations, or when you need to pass dynamic arguments to your alert queries.
data:
api: my_custom_validation_api
args:
threshold: 100
date_range: "7d"
Resource Status
Monitor the health of your Rill resources to catch pipeline failures and reconciliation errors. This is useful for monitoring pipeline health and catching reconciliation failures before they impact downstream processes.
data:
resource_status:
where_error: true
This triggers when any resource in your project has a reconciliation error.
Notification Configuration
Configure where and how you receive notifications when alerts trigger. You can send notifications via email, Slack, or both. Notifications are sent when the alert condition is met (when the data query returns rows), and optionally when the alert recovers or encounters evaluation errors.