Resource Monitor
You can provide configuration to Snowflake Object Lifecycle Engine for the following operations with resource monitors:
- Manage the lifecycle of new and existing resource monitors
- Manage the lifecycle of cloned resource monitor
- Manage grants of resource monitor
Usage
- Default Configuration
- Data Products Configuration
resource_monitors:
<resource-monitor-name>:
<configuration-key>: <value>
grants:
<privilege>:
- <role-name>
- <role-name>
- resource_monitor:
name: <resource-monitor-name>
<configuration-key>: <value>
grants:
<privilege>:
- rel(role.<role-name>)
- rel(role.<role-name>)
Supported parameters
The engine supports the parameters listed below.
Configuration Key | Required/Optional | Data Types and Values | Description |
---|---|---|---|
credit_quota | Optional | Integer | The number of credits allocated to the resource monitor per frequency interval. When total usage for all warehouses assigned to the monitor reaches this number for the current frequency interval, the resource monitor is considered to be at 100% of the quota. Note: Avoid setting credit quota to 0 because it will be treated as null in Snowflake, and this will result in an infinite credit quota. |
deleted | Optional | Boolean: True enables deletion prevention, False does nothing | Specifies what objects are allowed to be deleted |
end_timestamp | Optional | String: Must be a valid date or timestamp | The date and time when the resource monitor starts monitoring credit usage for the assigned warehouses. See End Timestamp Usage for resource monitor. |
environment | Optional | String | Specifies the environment in which the resource monitor is managed. Regex can be provided as well. |
frequency | Optional | String: DAILy , WEEKLY , MONTHLY , YEARLY , NEVER | The frequency interval at which the credit usage resets to 0 |
grants | Optional | Map: See Supported Resource Monitor Grants to Roles | List of Privileges and Roles to which privileges are granted to on the current Resource Monitor |
manage_mode | Optional | Enumeration: all (default), none , grants | Configures what properties to manage for the resource monitor. See Changing Manage Mode before changing the value. |
namespacing | Optional | String: both (default), prefix , suffix , none | Specifies whether Prefix or Suffix or both are to be added to resource monitor name |
notify_triggers | Optional | Array/List of Integers | A list of percentage thresholds at which to send an alert to subscribed users |
notify_users | Optional | Array/List of Strings | Specifies the list of users to receive email notifications on resource monitors. Note: When configuring users using notify_users , only users with verified email addresses can be included. |
set_for_account | Optional | Boolean | Specifies whether the resource monitor should be applied globally to your Snowflake account. Caution: resource_monitors set for account cannot have any warehouses referencing it. |
start_timestamp | Optional | String: Must be a valid Date or timestamp | The date and time when the resource monitor starts monitoring credit usage for the assigned warehouses. See Start Timestamp Usage for resource monitor. |
suspend_immediate_triggers | Optional | Array/List of Integers | A list of percentage thresholds at which to immediately suspend all warehouses |
suspend_triggers | Optional | Array/List of Integers | A list of percentage thresholds at which to suspend all warehouses |
Timestamp
As per Snowflake Docs, the start_timestamp
and end_timestamp
parameters support valid timestamps as values — they only support DATE (YYYY-MM-DD) and cannot be created with a complete timestamp (YYYY-MM-DDTHH:MM:SS). When setting the parameter to any valid timestamp that has time mentioned in it, this leads to an SQL compilation error with the message Invalid date/time format string. This error occurs while creating as well as updating a Resource Monitor.
To bypass this error, a valid Date must be provided when creating or updating the Resource Monitor. This Date is converted to its timestamp equivalent after creation or update.
This leads to another issue when managing the resource with the Snowflake Object Lifecycle Engine engine. Each time a pipeline is run, the engine would compare the two values. The configuration defines a Date while the local state has a timestamp present in it. As the values are not similar(Date is not equal to timestamp although their values are equivalent), the engine determines that the resource monitor has to be updated. This leads to a replacement of the resource monitor (start_timestamp
and end_timestamp
lead to the replacement of the object), each-time a pipeline is run.
This replacement could be avoided if, after the creation or update of the resource monitor, the values of start_timestamp
and end_timestamp
are set to timestamp.
Example
Initial Configuration:
- default Configuration
- Data Products Configuration
resource_monitors:
RESOURCE_MONITOR_1:
frequency: "YEARLY"
start_timestamp: "2021-04-15"
end_timestamp: "2022-04-15"
notify_triggers:
- 40
suspend_triggers:
- 50
suspend_immediate_triggers:
- 90
- resource_monitor:
name: RESOURCE_MONITOR_1
frequency: "YEARLY"
start_timestamp: "2021-04-15"
end_timestamp: "2022-04-15"
notify_triggers:
- 40
suspend_triggers:
- 50
suspend_immediate_triggers:
- 90
Configuration Update after Creation/Update:
- Default Configuration
- Data Products Configuration
resource_monitors:
RESOURCE_MONITOR_1:
frequency: "YEARLY"
start_timestamp: "2021-04-15T00:00:00Z"
end_timestamp: "2022-04-15T00:00:00Z"
notify_triggers:
- 40
suspend_triggers:
- 50
suspend_immediate_triggers:
- 90
- resource_monitor:
name: RESOURCE_MONITOR_1
frequency: "YEARLY"
start_timestamp: "2021-04-15T00:00:00Z"
end_timestamp: "2022-04-15T00:00:00Z"
notify_triggers:
- 40
suspend_triggers:
- 50
suspend_immediate_triggers:
- 90
If a new branch is created from this, start_timestamp
and end_timestamp
have to be set back to dates.
Supported resource monitor grants to roles
Following is the list of the access privileges you can grant to roles in the resource monitor definition:
- ALL PRIVILEGES
- MODIFY
- MONITOR
When you define ALL PRIVILEGES in the SOLE configuration file, you grant all the privileges listed above to roles on this object. However, the management of ALL PRIVILEGES in SOLE differs from its handling in Snowflake. See Handling ALL PRIVILEGES in SOLE for more information.
Examples
- Default Configuration
- Data Products Configuration
resource_monitors:
RESOURCE_MONITOR_1:
credit_quota: 1000
frequency: "YEARLY"
start_timestamp: "2021-04-15"
end_timestamp: "2022-04-15"
notify_users:
- USER_1
- USER_2
notify_triggers:
- 40
suspend_triggers:
- 50
suspend_immediate_triggers:
- 90
grants:
MONITOR:
- DEV_ROLE
- resource_monitor:
name: RESOURCE_MONITOR_1
credit_quota: 1000
frequency: "YEARLY"
start_timestamp: "2021-04-15"
end_timestamp: "2022-04-15"
notify_triggers:
- 40
suspend_triggers:
- 50
suspend_immediate_triggers:
- 90
grants:
MONITOR:
- rel(role.DEV_ROLE)