Monitors as Code - Legacy Metric Monitor
Starting March 1, 2025, new monitors can no longer be created using the field_health property.
We strongly recommend using the more up to datemetric property. However, users can still deploy the legacy version of this monitor under the field_health property until March 1, 2025.
Monitors created with the field_health property do not receive any new improvements.
These are the parameters currently supported by field_health monitor definitions:
Parameters
table: MC global table ID (format<database>:<schema>.<table name>alert_conditions: List of configurations for metrics, fields, and breach conditions. A field may only be included once in a monitor for a given metric. See section below for details.segmented_expressions: List of fields or SQL expressions used to segment the field (must have exactly one field infields). Enables Monitoring by Dimension.segmentation_type:fieldorcustom_sql_expression. Defaults tofield.fieldsupports up to 2 fields. The fields must exist in the table.custom_sql_expressionsupports 1 custom SQL expression.
timestamp_field: Timestamp fieldtimestamp_field_expression: Arbitrary SQL expression to be used as timestamp field, e.g.DATE(created). Must use eithertimestamp_fieldortimestamp_field_expressionor neither.where_condition: SQL snippet of where condition monitor's querylookback_days: Lookback period in days. Default: 3. This option is optional and will be ignored unlesstimestamp_fieldis set.aggregation_time_interval: Aggregation bucket time interval, eitherhour(default) orday. This option is optional and will be ignored unlesstimestamp_fieldis set.min_segment_size: Minimum number of rows for a segment to be fetched. Defaults to 1. Can be used to avoid cardinality limits for datasets with a long tail of less-relevant segments.sensitivity_level: Set sensitivity level to One ofhigh,mediumorlow.scheduletype: One offixedordynamicinterval_minutes: For fixed, how frequently to run the monitorstart_time: When to start the schedule. If unspecified, for fixed schedules, then start sometime within the next hour.timezone: Optional - select regional timezone for daylight savings ex. America/Los_Angeles
connection_name: Specify the connection (also known as query-engine) to use. Obtain the warehouse UUID via thegetUserAPI as described here. Then obtain names of the connections in the warehouse via the getWarehouseConnections API as described here. Use["sql_query"]as thejobTypeparameter in thegetWarehouseConnectionsAPI call.
Each Metric Monitor supports up to 300 monitored fields (or custom metrics).
Metric monitor alert conditions
operator: acceptsAUTO,GT,GTE,LT,LTE,EQ,NEQ,OUTSIDE_RANGE,INSIDE_RANGE.AUTOuses ML to detect breaches. All other operators require an explicit threshold.fields: List of field names that should be monitored for this metric, operator, and threshold. This field is optional and defaults to all fields in the table. The field type must be compatible with the metric.- Each field may only be included once in the monitor for a given metric (including as part of an "all fields" metric).
- When using a custom metric,
fieldsshould not be included; the fields used should be included directly in the SQL expression.
threshold_value: Breach threshold for the operator. Not used forAUTO,OUTSIDE_RANGE, orINSIDE_RANGE. For rate metrics, ensure the threshold is between 0 and 1 (not 0%-100%).lower_threshold: Lower end of threshold range for operatorsOUTSIDE_RANGEandINSIDE_RANGEupper_threshold: Upper end of threshold range for operatorsOUTSIDE_RANGEandINSIDE_RANGEmetric: See the list of available metrics for full details, including whether AUTO is supported for each metric and which field types are compatible. All operators besidesAUTOare compatible with every metric. Use the value from theMaC Namecolumn in this field.custom_metric: Allows defining a custom metric based on a SQL expression instead of a predefined metric indicated inmetric. It can use any operator exceptAUTO.
Converting field_health property to metric property
field_health property to metric propertyMost of the parameters in the old format have the same representation in the new one, but under different names:
Legacy Name | New Name |
|---|---|
name | name |
connection_name | connection_name |
data_source | data_source |
schedule | schedule |
sensitivity_level | sensitivity |
table: <table id> | data_source: |
alert_conditions | alert_conditions |
comparisons | comparisons |
segmented_expressions: [ | segment_fields: [ |
segmented_expressions: | segment_sql: [ |
timestamp_field: | aggregate_time_field: |
timestamp_field_expression: | aggregate_time_sql: |
aggregation_time_interval: hour | day | aggregate_by: hour | day |
where_condition | where_condition |
min_segment_size | Not supported. |
lookback_days | Not supported. Use For reference, a good rule of thumb is using the following table for conversion: When aggregate_by: hour When aggregate_by: day |
Converting using the CLI
You can use the export-as-latest command from the CLI to export the current field_metric monitors using the new metric definition. Provide the namespace of the monitors you want to export using metric, and the command will return all legacy monitors converted to use the new metric definitions.
Bare in mind that these will be new monitors that, once created, will need to be retrained. There's no way to preserve the history and training of current field_health monitors when converting. However, this training period is rapidly accelerated by backfills, which happen automatically when the metric monitor is created.
Legacy monitors and new monitors behave differently with respect to the monitored data time window when using a timestamp field or expression. Legacy monitors will look at all data since the time of execution and the 'lookback_days' parameter, while new monitors will look at all data since the last collection, ignoring up to the 'collection_lag' hours. These differences might require you to tweak the converted collection_lag parameter if you know data arrives with some significant delay to your warehouse with respect to the monitor's scheduled run time.
The legacy monitors also have some different restrictions compared to new style monitors:
- Legacy monitors cannot have more than 1,000 segments when monitoring more than one metric or field
- New monitors cannot monitor more than 10,000 time series, with each time series being defined by the combination of segment, metric and field.
These differences might cause some old style monitors to be rejected when specified in the new format. For example, an 'all fields, all metrics' legacy monitor might easily exceed the 10,000 time series limit for tables with more than 300 fields. You will need to break these apart if you want to preserve the same coverage, or narrow down your metric and field selection.
Converting using 'clone'
You can use the clone button on the UI to clone an existing legacy monitor. The cloned monitor will be automatically converted to a new style monitor. Using the 'Generate YAML' button at the bottom of the create monitor screen, you can export the definition using the new metric property.
Updated 4 months ago
