Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update api_calls to extract_summary #138

Merged
merged 14 commits into from
Nov 21, 2024
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# dbt_fivetran_log v1.9.1
[PR #138](https://github.com/fivetran/dbt_fivetran_log/pull/138) includes the following updates:

## Features
- For Fivetran Platform Connectors created after November 2024, Fivetran has deprecated the `api_call` event in favor of `extract_summary` ([release notes](https://fivetran.com/docs/logs/changelog)).
- Accordingly, we have updated the `fivetran_platform__connector_daily_events` model to support the new `extract_summary` event while maintaining backward compatibility with the `api_call` event for connectors created before November 2024.

## Under the Hood
- Replaced the deprecated `dbt.current_timestamp_backcompat()` function with `dbt.current_timestamp()` to ensure all timestamps are captured in UTC.
- Updated `fivetran_platform__connector_daily_events` to support running `dbt compile` prior to the initial `dbt run` on a new schema.

# dbt_fivetran_log v1.9.0
[PR #132](https://github.com/fivetran/dbt_fivetran_log/pull/132) includes the following updates:

Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<p align="center">
# Fivetran Platform dbt Package ([Docs](https://fivetran.github.io/dbt_fivetran_log/))

<p align="left">
Comment on lines +1 to +3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making this change as well!

<a alt="License"
href="https://github.com/fivetran/dbt_fivetran_log/blob/main/LICENSE">
<img src="https://img.shields.io/badge/License-Apache%202.0-blue.svg" /></a>
Expand All @@ -13,7 +15,6 @@
<img src="https://img.shields.io/badge/Fivetran_Quickstart_Compatible%3F-yes-green.svg" /></a>
</p>

# Fivetran Platform dbt Package ([Docs](https://fivetran.github.io/dbt_fivetran_log/))
## What does this dbt package do?
- Generates a comprehensive data dictionary of your Fivetran Platform connector (previously called Fivetran Log) data via the [dbt docs site](https://fivetran.github.io/dbt_fivetran_log/)

Expand Down
2 changes: 1 addition & 1 deletion dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
config-version: 2
name: 'fivetran_log'
version: '1.9.0'
version: '1.9.1'
require-dbt-version: [">=1.3.0", "<2.0.0"]

models:
Expand Down
2 changes: 1 addition & 1 deletion docs/catalog.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/manifest.json

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion docs/run_results.json

This file was deleted.

2 changes: 1 addition & 1 deletion integration_tests/dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 'fivetran_log_integration_tests'
version: '1.9.0'
version: '1.9.1'

config-version: 2
profile: 'integration_tests'
Expand Down
4 changes: 3 additions & 1 deletion integration_tests/seeds/log.csv
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ ZZLSXVYxirh8aKlgdCzo5fvd71g=,2021-12-10 14:26:42.029,2021-12-10 20:30:53.949,thi
D7UqnKYn6OT04HkUcPNjXA95ttI=,2021-12-10 14:26:29.719,2021-12-10 20:30:53.878,this_connector,INFO,"{""table"":""media_insights""}",write_to_table_start,123,456abc
V3H62Gj5c6nB8bY+OdxMHvp/hNs=,2021-12-10 14:26:05.907,2021-12-10 20:30:53.778,this_connector,INFO,,sync_start,123,456abc
jkLxnPUfQ/9mHaWCmxUQEhul8ZA=,2023-11-09 11:31:31.579000,2023-11-09 15:55:12.560000,protestations_mourned,INFO,"{""actor"":""me@me.com"",""properties"":{""endpoint"":""************"",""apiKey"":""************"",""customEvents"":[],""syncMode"":""AllEvents"",""isE2ETest"":false,""events"":[],""customEventSyncMode"":""AllEvents""},""id"":""iterable""}",create_connector,,
R7UqnKYn6OT04HkUcPNjXA95qqI=,2021-12-10 16:26:29.719,2021-12-10 20:30:53.878,intrinsic_departed,INFO,says actor but not a json,status,,456abc
R7UqnKYn6OT04HkUcPNjXA95qqI=,2021-12-10 16:26:29.719,2021-12-10 20:30:53.878,intrinsic_departed,INFO,says actor but not a json,status,,456abc
D7UqnKYn6OT04HkUcPNjXA95qqp=,2024-11-18 16:26:29.719,2024-11-19 20:30:53.878,aft_gleeful,INFO,"{""total_queries"":15,""total_rows"":4810}",extract_summary,,456abc
h7UqnKYn6OT04HkUcPNjXA95qlp=,2024-11-19 16:26:29.719,2024-11-19 20:30:53.878,aft_gleeful,INFO,"{""total_queries"":5,""total_rows"":4810}",extract_summary,,456abc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ spine as (
{{ fivetran_utils.fivetran_date_spine(
datepart = "day",
start_date = "cast('" ~ first_date[0:10] ~ "' as date)",
end_date = dbt.dateadd("week", 1, dbt.date_trunc('day', dbt.current_timestamp_backcompat() if target.type != 'sqlserver' else dbt.current_timestamp()))
end_date = dbt.dateadd("week", 1, dbt.date_trunc('day', dbt.current_timestamp()))
)
}}
) as date_spine
Expand Down
49 changes: 33 additions & 16 deletions models/fivetran_platform__connector_daily_events.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,56 @@ with connector as (
),

-- grab api calls, schema changes, and record modifications

log_events as (

select
connector_id,
cast( {{ dbt.date_trunc('day', 'created_at') }} as date) as date_day,
case
when event_subtype in ('create_table', 'alter_table', 'create_schema', 'change_schema_config') then 'schema_change'
else event_subtype end as event_subtype,

sum(case when event_subtype = 'records_modified' then cast( {{ fivetran_log.fivetran_log_json_parse(string='message_data', string_path=['count']) }} as {{ dbt.type_bigint()}} )
else 1 end) as count_events
event_subtype,
message_data

from {{ ref('stg_fivetran_platform__log') }}

where event_subtype in ('api_call',
'records_modified',
'create_table', 'alter_table', 'create_schema', 'change_schema_config') -- all schema changes

where event_subtype in (
'api_call', 'extract_summary', 'records_modified', 'create_table', 'alter_table',
'create_schema', 'change_schema_config') -- all relevant event subtypes
and connector_id is not null
),

agg_log_events as (

group by connector_id, cast( {{ dbt.date_trunc('day', 'created_at') }} as date), event_subtype
select
connector_id,
date_day,
case
when event_subtype in ('create_table', 'alter_table', 'create_schema', 'change_schema_config') then 'schema_change'
else event_subtype end as event_subtype,

sum(
case
when event_subtype = 'records_modified'
then cast({{ fivetran_log.fivetran_log_json_parse(string='message_data', string_path=['count']) }} as {{ dbt.type_bigint()}} )
when event_subtype = 'extract_summary'
then cast({{ fivetran_log.fivetran_log_json_parse(string='message_data', string_path=['total_queries']) }} as {{ dbt.type_bigint()}})
else 1
end
) as count_events

from log_events
group by connector_id, date_day, event_subtype
),

pivot_out_events as (

select
connector_id,
date_day,
max(case when event_subtype = 'api_call' then count_events else 0 end) as count_api_calls,
max(case when event_subtype = 'api_call' or event_subtype = 'extract_summary' then count_events else 0 end) as count_api_calls,
max(case when event_subtype = 'records_modified' then count_events else 0 end) as count_record_modifications,
max(case when event_subtype = 'schema_change' then count_events else 0 end) as count_schema_changes

from log_events
from agg_log_events
group by connector_id, date_day
),

Expand All @@ -63,7 +80,7 @@ connector_event_counts as (

spine as (

{% if execute %}
{% if execute and flags.WHICH in ('run', 'build') %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you note in the "under the hood" section of the CHANGELOG that this release supports dbt compile on a new schema before dbt run due to the above change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, updated!

{% set first_date_query %}
select min( signed_up ) as min_date from {{ var('connector') }}
{% endset %}
Expand All @@ -78,7 +95,7 @@ spine as (
{{ fivetran_utils.fivetran_date_spine(
datepart = "day",
start_date = "cast('" ~ first_date[0:10] ~ "' as date)",
end_date = dbt.dateadd("week", 1, dbt.date_trunc('day', dbt.current_timestamp_backcompat() if target.type != 'sqlserver' else dbt.current_timestamp()))
end_date = dbt.dateadd("week", 1, dbt.date_trunc('day', dbt.current_timestamp()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super duper minor -- would you mind updating the parallel line in the row_count__connector_daily_events test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. updated!

)
}}
) as date_spine
Expand Down Expand Up @@ -138,7 +155,7 @@ final as (
select *
from join_event_history

where date_day <= cast({{ dbt.current_timestamp_backcompat() if target.type != 'sqlserver' else dbt.current_timestamp() }} as date)
where date_day <= cast({{ dbt.current_timestamp() }} as date)
)

select *
Expand Down
2 changes: 1 addition & 1 deletion models/fivetran_platform__connector_status.sql
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ schema_changes as (
from {{ ref('stg_fivetran_platform__log') }}

where
{{ dbt.datediff('created_at', dbt.current_timestamp_backcompat() if target.type != 'sqlserver' else dbt.current_timestamp(), 'day') }} <= 30
{{ dbt.datediff('created_at', dbt.current_timestamp(), 'day') }} <= 30
and event_subtype in ('create_table', 'alter_table', 'create_schema', 'change_schema_config')

group by connector_id
Expand Down