🛠️Implementation details
SnowKill is a tool for Data Engineers and DevOps engineers.
SnowKill application is usually implemented as Python script, which consists of multiple interchangeable parts. These parts are meant to be extended and adapted for your specific organization needs.
The parts are:
Engine - accepts Snowflake connection, communicates with REST API and performs checks.
Condition(s) - implement logic for specific query check conditions.
Formatter(s) - implement notification formatting for matched queries.
Storage(s) - implement log storage and deduplication functionality.
SnowKill does not have built-in functions to send formatted notifications. There are many other packages, SDKs and cloud native services solving this problem. However, we provide some basic examples and guidance to get you started.
Python Script structure
1) Open Snowflake connection
You should pre-configure an administration user for SnowKill with correct privileges.
You have full control over construction of connection object so you can use any connection method supported by Snowflake. For example:
2) Init engine, storage and formatter
In this example we're going to store logs in Snowflake and format messages for Slack.
You may use any other built-in storage and built-in formatter.
You may also create your own custom storage or custom formatter.
3) Define conditions
You may use built-in conditions and / or create your own custom conditions.
You may use query filters to narrow down conditions. If query filter is not specified, condition will be applied to ALL queries running on Snowflake account.
Here is a good list of conditions for starters:
4) Optionally allow some conditions to "kill" queries
By default no queries are "killed". You should explicitly set enable_kill=True
and specify kill_duration
for each individual condition.
If query would be killed according to conditions, but enable_kill
was not set, this query is reported as "would be killed" instead of being actually killed. You may read more about it on "Check result levels" page.
You may additionally narrow down kill conditions using enable_kill_query_filter
.
For example:
5) Run checks
Run checks using engine function:
It returns list of Check Results, one entry for each query matching conditions.
If one query matches multiple conditions at the same time, the result with highest level will be returned.
6) Run deduplication and store logs
Run deduplication using storage function:
It returns list of filtered Check Results. The results which appeared earlier are removed.
Problematic queries may run for a long time. We have to remember which queries were reported previously, so we would not send notifications again.
However, if query was previously reported with lower level, but now the result contains higher level, such query will be reported again with higher level.
7) Format messages and send notifications
Format and send notifications using list of filtered Check Results.
Formatter returns "message blocks", which should be used for Slack API calls.
For example:
You may read a bit more about Slack integration on a dedicated documentation page.
Last updated