Skip to content

Commit

Permalink
Keep old alerts tables for backwards
Browse files Browse the repository at this point in the history
  • Loading branch information
IDoneShaveIt committed Jan 17, 2024
1 parent 32e8aeb commit 7d3deef
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
44 changes: 44 additions & 0 deletions elementary/monitor/dbt_project/models/alerts/deprecated/alerts.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{{
config(
materialized = 'incremental',
unique_key = 'alert_id',
merge_update_columns = ['alert_id'],
on_schema_change = 'sync_all_columns',
table_type=elementary.get_default_table_type(),
incremental_strategy=elementary.get_default_incremental_strategy()
)
}}

{% set anomaly_detection_relation = adapter.get_relation(this.database, this.schema, 'alerts_anomaly_detection') %}
{# Backwards compatibility support for a renamed model. #}
{% set data_monitoring_relation = adapter.get_relation(this.database, this.schema, 'alerts_data_monitoring') %}
{% set schema_changes_relation = adapter.get_relation(this.database, this.schema, 'alerts_schema_changes') %}

with failed_tests as (
select * from {{ ref('elementary', 'alerts_dbt_tests') }}

{% if schema_changes_relation %}
union all
select * from {{ schema_changes_relation }}
{% endif %}

{% if anomaly_detection_relation %}
union all
select * from {{ anomaly_detection_relation }}
{% elif data_monitoring_relation %}
union all
select * from {{ data_monitoring_relation }}
{% endif %}
)

select
{{ dbt_utils.star(from=ref('elementary', 'alerts_dbt_tests'), except=["detected_at"]) }},
{{ elementary_cli.get_alerts_model_detected_at_expr(this) }} as detected_at,
false as alert_sent, {# backwards compatibility #}
'pending' as suppression_status,
{{ elementary.edr_cast_as_string('NULL') }} as sent_at
from failed_tests

{%- if is_incremental() %}
{{ elementary_cli.get_new_alerts_where_clause(this) }}
{%- endif %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{{
config(
materialized = 'incremental',
unique_key = 'alert_id',
merge_update_columns = ['alert_id'],
on_schema_change = 'sync_all_columns',
table_type=elementary.get_default_table_type(),
incremental_strategy=elementary.get_default_incremental_strategy()
)
}}

{% set error_models_relation = adapter.get_relation(this.database, this.schema, 'alerts_dbt_models') %}
{% if error_models_relation %}
select
{{ dbt_utils.star(from=error_models_relation, except=["detected_at"]) }},
{{ elementary_cli.get_alerts_model_detected_at_expr(this) }} as detected_at,
false as alert_sent, {# backwards compatibility #}
'pending' as suppression_status,
{{ elementary.edr_cast_as_string('NULL') }} as sent_at
from {{ error_models_relation }}
{% if is_incremental() %}
{{ elementary_cli.get_new_alerts_where_clause(this) }}
{% endif %}
{% else %}
{{ elementary_cli.empty_alerts_models() }}
{% endif %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{{
config(
materialized = 'incremental',
unique_key = 'alert_id',
merge_update_columns = ['alert_id'],
on_schema_change = 'sync_all_columns',
table_type=elementary.get_default_table_type(),
incremental_strategy=elementary.get_default_incremental_strategy()
)
}}

{% set alerts_source_freshness_relation = adapter.get_relation(this.database, this.schema, 'alerts_dbt_source_freshness') %}
{% if alerts_source_freshness_relation %}
select
{{ dbt_utils.star(from=alerts_source_freshness_relation, except=["detected_at"]) }},
{{ elementary_cli.get_alerts_model_detected_at_expr(this) }} as detected_at,
false as alert_sent, {# backwards compatibility #}
'pending' as suppression_status,
{{ elementary.edr_cast_as_string('NULL') }} as sent_at
from {{ alerts_source_freshness_relation }}
{% if is_incremental() %}
{{ elementary_cli.get_new_alerts_where_clause(this) }}
{% endif %}
{% else %}
{{ elementary_cli.empty_alerts_source_freshness() }}
{% endif %}

0 comments on commit 7d3deef

Please sign in to comment.