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

Feature/historical schedules #171

Merged
merged 82 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from 81 commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
605a7fb
send to bk
fivetran-jamie Jun 3, 2024
c58b4b6
try this out
fivetran-jamie Jun 3, 2024
5f2113b
first try
fivetran-jamie Jun 3, 2024
662f3f2
use mcro
fivetran-jamie Jun 3, 2024
5bfead9
Testing
fivetran-jamie Jun 3, 2024
d36dc49
puhs
fivetran-jamie Jun 3, 2024
700589f
redshift
fivetran-jamie Jun 3, 2024
f6ada0c
try nullif
fivetran-jamie Jun 4, 2024
f07271c
feature/historical-schedules
fivetran-catfritz Sep 11, 2024
f15b4b1
Merge branch 'feature/historical-schedules' into explore/audit-log-spike
fivetran-catfritz Sep 11, 2024
fd53978
Merge pull request #170 from fivetran/explore/audit-log-spike
fivetran-catfritz Sep 11, 2024
cf89429
rework schedule_history
fivetran-catfritz Sep 12, 2024
54cdf21
update unnest logic
fivetran-catfritz Sep 13, 2024
505f343
update schedule_history
fivetran-catfritz Sep 23, 2024
4ca4099
complete schedule_history
fivetran-catfritz Sep 23, 2024
7806d83
revise holidays
fivetran-catfritz Sep 26, 2024
a54bee2
add macro
fivetran-catfritz Sep 26, 2024
0477543
typeo
fivetran-catfritz Sep 26, 2024
f980433
updates
fivetran-catfritz Sep 26, 2024
016e449
updates
fivetran-catfritz Sep 26, 2024
45fbcfe
updates
fivetran-catfritz Sep 26, 2024
3907813
updates
fivetran-catfritz Sep 26, 2024
8b32c45
try out in buildkite
fivetran-jamie Sep 27, 2024
9c49399
remove schedule days during holiday
fivetran-catfritz Sep 27, 2024
e4bf09f
revise
fivetran-catfritz Sep 27, 2024
4523d2c
revise
fivetran-catfritz Sep 27, 2024
cceae3f
add config
fivetran-catfritz Sep 27, 2024
62c5fa9
add config
fivetran-catfritz Sep 27, 2024
1db42a7
allow disable holidays
fivetran-catfritz Sep 27, 2024
f730908
streamline bk run
fivetran-jamie Sep 27, 2024
ee99616
adjust for multiple holidays in a week
fivetran-catfritz Sep 27, 2024
4f395de
add casting
fivetran-catfritz Sep 27, 2024
8613f8a
add casting
fivetran-catfritz Sep 27, 2024
f762ca1
fixes
fivetran-catfritz Sep 27, 2024
00a98cb
fixes
fivetran-catfritz Sep 27, 2024
96be5ae
fixes
fivetran-catfritz Sep 27, 2024
7517057
fixes
fivetran-catfritz Sep 27, 2024
184e639
fixes
fivetran-catfritz Sep 28, 2024
c594f3f
fix multiyear schedules
fivetran-catfritz Sep 28, 2024
e613480
add longer holiday support
fivetran-catfritz Sep 30, 2024
a49f0d6
revert multiweek
fivetran-catfritz Oct 1, 2024
e1f9d32
adjust multiweek
fivetran-catfritz Oct 1, 2024
98e6872
account for non sunday week starts
fivetran-catfritz Oct 2, 2024
0321581
updates
fivetran-catfritz Oct 2, 2024
6163942
update weeks spanned calc
fivetran-catfritz Oct 2, 2024
c774f6d
update naming
fivetran-catfritz Oct 2, 2024
b8a9f4a
update to dbt_date
fivetran-catfritz Oct 3, 2024
cfcd106
update comments
fivetran-catfritz Oct 3, 2024
781f4fd
update to dbt date weekstart
fivetran-catfritz Oct 3, 2024
28457e8
modernize calendar spine
fivetran-catfritz Oct 3, 2024
c117df9
make sure we're working with strings when replacing
fivetran-jamie Oct 3, 2024
933d62e
let's see if bk works
fivetran-jamie Oct 4, 2024
0aacff4
postgres?
fivetran-jamie Oct 4, 2024
e39919e
i think schedule history may actually be workingggg
fivetran-catfritz Oct 4, 2024
8a9d84d
get ready to merge into catherines branch
fivetran-jamie Oct 4, 2024
f691904
Merge branch 'feature/historical-schedules' into feature/historical-s…
fivetran-jamie Oct 4, 2024
b3c97ab
postgres revert
fivetran-jamie Oct 4, 2024
94b11a2
Merge branch 'feature/historical-schedules-jamie-redshift' of https:/…
fivetran-jamie Oct 4, 2024
eff6401
add comments
fivetran-catfritz Oct 4, 2024
763ca33
redshift fixes
fivetran-catfritz Oct 4, 2024
238bd96
redshift fixes
fivetran-catfritz Oct 4, 2024
4f57203
redshift fixes
fivetran-catfritz Oct 4, 2024
a6f3536
Merge branch 'feature/historical-schedules' into feature/historical-s…
fivetran-catfritz Oct 4, 2024
e342c79
Merge pull request #172 from fivetran/feature/historical-schedules-ja…
fivetran-catfritz Oct 4, 2024
5c720b5
updates
fivetran-catfritz Oct 4, 2024
6d8ff79
validation update
fivetran-catfritz Oct 6, 2024
c100e51
split models
fivetran-catfritz Oct 6, 2024
56bb954
update ymls
fivetran-catfritz Oct 7, 2024
c4929cf
revise scchedule groups
fivetran-catfritz Oct 8, 2024
1d1b2e1
updates
fivetran-catfritz Oct 9, 2024
05fefd5
add inline comments
fivetran-catfritz Oct 9, 2024
d97f714
update decision log
fivetran-catfritz Oct 9, 2024
6573314
update changelog
fivetran-catfritz Oct 9, 2024
0b0a05d
regen docs
fivetran-catfritz Oct 9, 2024
246624b
fix yml
fivetran-catfritz Oct 9, 2024
888f109
update changelog
fivetran-catfritz Oct 9, 2024
af951b1
address review comments and regen docs
fivetran-catfritz Oct 9, 2024
855dc77
address review comments
fivetran-catfritz Oct 9, 2024
73845a9
Apply suggestions from code review
fivetran-catfritz Oct 10, 2024
fd879c5
address review comments
fivetran-catfritz Oct 10, 2024
360911f
Update packages.yml
fivetran-catfritz Oct 10, 2024
56cd177
release review updates
fivetran-catfritz Oct 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .buildkite/scripts/run_models.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ cd integration_tests
dbt deps
dbt seed --target "$db" --full-refresh
dbt run --target "$db" --full-refresh
dbt run --target "$db"
dbt test --target "$db"
dbt run --vars '{zendesk__unstructured_enabled: true, using_schedules: false, using_domain_names: false, using_user_tags: false, using_ticket_form_history: false, using_organization_tags: false}' --target "$db" --full-refresh
dbt test --target "$db"
dbt run --vars '{using_schedule_histories: true, using_holidays: false}' --target "$db" --full-refresh
fivetran-jamie marked this conversation as resolved.
Show resolved Hide resolved
dbt test --target "$db"
dbt run --vars '{using_schedule_histories: true, using_holidays: true}' --target "$db" --full-refresh
dbt test --target "$db"

dbt run-operation fivetran_utils.drop_schemas_automation --target "$db"
5 changes: 4 additions & 1 deletion .quickstart/quickstart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ dbt_versions: ">=1.3.0 <2.0.0"
table_variables:
using_schedules:
- daylight_time
- schedule_holiday
- schedule
- time_zone
using_domain_names:
Expand All @@ -17,6 +16,10 @@ table_variables:
- ticket_form_history
using_organization_tags:
- organization_tag
using_schedule_histories:
- audit_log
using_holidays:
fivetran-joemarkiewicz marked this conversation as resolved.
Show resolved Hide resolved
- schedule_holiday

destination_configurations:
databricks:
Expand Down
49 changes: 48 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,52 @@
# dbt_zendesk v0.17.0
# dbt_zendesk v0.18.0
[PR #171](https://github.com/fivetran/dbt_zendesk/pull/171) includes the following changes:

## Breaking Changes (Full refresh required after upgrading)
### Schedule Change Support
- Support for schedule changes has been added. This feature is disabled by default since most users do not sync the required source `audit_table`. To enable this feature set the variable `using_schedule_histories` to `true` in your `dbt_project.yml`:
```yml
vars:
using_schedule_histories: true
```
- Schedule changes can now be extracted directly from the audit log, providing a view of schedule modifications over time.
- The `int_zendesk__schedule_spine` model is now able to incorporate these schedule changes, making it possible for downstream models to reflect the most up-to-date schedule data.
- Note this is only in effect when `using_schedule_histories` is true.
- This improves granularity for Zendesk metrics related to agent availability, SLA tracking, and time-based performance analysis.
#### dbt_zendesk_source changes (see the [Release Notes](https://github.com/fivetran/dbt_zendesk_source/releases/tag/v0.13.0) for more details)
- Introduced the `stg_zendesk__audit_log` table for capturing schedule changes from Zendesk's audit log.
- This model is disabled by default, to enable it set variable `using_schedule_histories` to `true` in `dbt_project.yml`.

## New Features
- Holiday support: Users can now choose to disable holiday tracking, while continuing to use schedules, by setting variable `using_holidays` to `false` in `dbt_project.yml`.
- New intermediate models have been introduced to streamline both the readability and maintainability:
- [`int_zendesk__timezone_daylight`](https://github.com/fivetran/dbt_zendesk/blob/main/models/intermediate/int_zendesk__timezone_daylight.sql): A utility model that maintains a record of daylight savings adjustments for each time zone.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- [`int_zendesk__timezone_daylight`](https://github.com/fivetran/dbt_zendesk/blob/main/models/intermediate/int_zendesk__timezone_daylight.sql): A utility model that maintains a record of daylight savings adjustments for each time zone.
- [`int_zendesk__timezone_daylight`](https://github.com/fivetran/dbt_zendesk/blob/main/models/utils/int_zendesk__timezone_daylight.sql): A utility model that maintains a record of daylight savings adjustments for each time zone.

unless you wanna move it to intermediate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ooo good catch. Updated!

- materialization: ephemeral
- [`int_zendesk__schedule_history`](https://github.com/fivetran/dbt_zendesk/blob/main/models/intermediate/int_zendesk__schedule_history.sql): Captures a full history of schedule changes for each `schedule_id`.
- materialization: table (if enabled)
- [`int_zendesk__schedule_timezones`](https://github.com/fivetran/dbt_zendesk/blob/main/models/intermediate/int_zendesk__schedule_timezones.sql): Merges schedule history with time zone shifts.
- materialization: ephemeral
- [`int_zendesk__schedule_holiday`](https://github.com/fivetran/dbt_zendesk/blob/main/models/intermediate/int_zendesk__schedule_holiday.sql): Identifies and calculates holiday periods for each schedule.
- materialization: ephemeral
- Rebuilt logic in [`int_zendesk__schedule_spine`](https://github.com/fivetran/dbt_zendesk/blob/main/models/intermediate/int_zendesk__schedule_spine.sql) to consolidate updates from the new intermediate models.
#### dbt_zendesk_source changes (see the [Release Notes](https://github.com/fivetran/dbt_zendesk_source/releases/tag/v0.13.0) for more details)
- Updated the `stg_zendesk__schedule_holidays` model to allow users to disable holiday processing by setting variable `using_holidays` to `false`.

## Bug Fixes
- Resolved a bug in the `int_zendesk__schedule_spine` model where users experienced large gaps in non-holiday periods. The updated logic addresses this issue.

fivetran-joemarkiewicz marked this conversation as resolved.
Show resolved Hide resolved
## Decision log
- Added the following [DECISIONLOG](https://github.com/fivetran/dbt_zendesk/blob/main/DECISIONLOG.md) entries:
- Entry addressing how multiple schedule changes in a single day are handled. Only the last change of the day is captured to align with day-based downstream logic.
- Entry to clarify backfilling of schedule history. The most recent schedule is sourced from `stg_zendesk__schedule`, while historical changes are managed separately, allowing users to disable the history feature if needed.

## Under the Hood
- Replaced instances of `dbt.date_trunc` with `dbt_date.week_start` to standardize week start dates to Sunday across all warehouses, since our schedule logic relies on consistent weeks.
- Replaced the deprecated `dbt.current_timestamp_backcompat()` function with `dbt.current_timestamp()` to ensure all timestamps are captured in UTC.
fivetran-jamie marked this conversation as resolved.
Show resolved Hide resolved
- Added seed data for `audit_log` to enhance integration testing capabilities.
- Introduced new helper macros, `clean_data` and `regex_extract`, to process complex text of the schedule changes extracted from audit logs.
- Updated `int_zendesk__calendar_spine` logic to prevent errors during compilation before the first full run, ensuring a smoother development experience.

# dbt_zendesk v0.17.0
## New model ([#161](https://github.com/fivetran/dbt_zendesk/pull/161))
- Addition of the `zendesk__document` model, designed to structure Zendesk textual data for vectorization and integration into NLP workflows. The model outputs a table with:
- `document_id`: Corresponding to the `ticket_id`
Expand Down
12 changes: 7 additions & 5 deletions DECISIONLOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# Decision Log

## Tracking Ticket SLA Policies Into the Future
In our models we generate a future time series for ticket SLA policies. This is limited to a year to maintain performance.
## Schedule History
### Handling Multiple Schedule Changes in a Day
While integrating schedule changes from the audit_log source, we observed that multiple changes can occur on the same day, often when users are still finalizing a schedule. To maintain clarity and align with our day-based downstream logic, we decided to capture only the last change made on any given day. If this approach proves insufficient for your use case, please submit a [feature request](https://github.com/fivetran/dbt_zendesk/issues/new/choose) for enabling support for multiple changes within a single day.

## No Historical Schedule Reference
At the current moment the Fivetran Zendesk Support connector does not contain historical data of schedules. This means if a schedule is created in the Zendesk Support UI and remains untouched for years, but then is adjusted in the current month you will see the data synced in the raw `schedule` table to reflect the current adjusted schedule. As a result the raw data will lose all historical reference of what this schedule range was previously.
### Backfilling the Schedule History
Although the schedule history extracted from the audit log includes the most recent schedule, we exclude it in the `int_zendesk__schedule_history` model. Instead, we rely on the schedule from `stg_zendesk__schedule`, since it represents the live schedule. This approach also allows users who are not using schedule histories to easily disable the history feature. We join the live schedule with the schedule history model and bridge the valid_from and valid_until dates to maintain consistency.

Therefore, if you are leveraging the `using_schedule` variable as `true` to replicate business hour metrics this data model will only have a reference to the current range of any given schedule. This means tickets from the previous two years that were leveraging the __old__ schedule will not be reported as using the __new__ schedule. If this data limitation is a concern to you, we recommend opening a [Fivetran Support Feature Request](https://support.fivetran.com/hc/en-us/community/topics/360001909373-Feature-Requests?sort_by=votes) to enhance the Zendesk Support connector to include historical schedule data.
## Tracking Ticket SLA Policies Into the Future
In our models we generate a future time series for ticket SLA policies. This is limited to a year to maintain performance.

## Zendesk Support First Reply Time SLA Opinionated Logic
The logic for `first_reply_time` breach/achievement metrics within the `zendesk__ticket_metrics` and `zendesk__sla_policies` models are structured on the Zendesk Support definition of [first reply time SLA events](https://support.zendesk.com/hc/en-us/articles/4408821871642-Understanding-ticket-reply-time?page=2#topic_jvw_nqd_1hb). For example, this data model calculates first reply time to be the duration of time (business or calendar) between the creation of the ticket and the first public comment from either an `agent` or `admin`. This holds true regardless of when the first reply time SLA was applied to the ticket.
Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Include the following zendesk package version in your `packages.yml` file:
```yml
packages:
- package: fivetran/zendesk
version: [">=0.17.0", "<0.18.0"]
version: [">=0.18.0", "<0.19.0"]
fivetran-joemarkiewicz marked this conversation as resolved.
Show resolved Hide resolved

```
> **Note**: Do not include the Zendesk Support source package. The Zendesk Support transform package already has a dependency on the source in its own `packages.yml` file.
Expand All @@ -79,11 +79,13 @@ vars:
zendesk_schema: your_schema_name
```

### Step 4: Disable models for non-existent sources
This package takes into consideration that not every Zendesk Support account utilizes the `schedule`, `schedule_holiday`, `ticket_schedule` `daylight_time`, `time_zone`, `domain_name`, `user_tag`, `organization_tag`, or `ticket_form_history` features, and allows you to disable the corresponding functionality. By default, all variables' values are assumed to be `true`. Add variables for only the tables you want to disable:
### Step 4: Enable/Disable models for non-existent sources
This package takes into consideration that not every Zendesk Support account utilizes the `schedule`, `schedule_holiday`, `ticket_schedule`, `daylight_time`, `time_zone`, `audit_log`, `domain_name`, `user_tag`, `organization_tag`, or `ticket_form_history` features, and allows you to disable the corresponding functionality. By default, all variables' values are assumed to be `true`, except for `using_schedule_histories`. Add variables for only the tables you want to enable/disable:
```yml
vars:
using_schedules: False #Disable if you are not using schedules
using_schedule_histories: True #Enable if you are using audit_logs for schedule histories
using_schedules: False #Disable if you are not using schedules, which requires source tables ticket_schedule, daylight_time, and time_zone
using_holidays: False #Disable if you are not using schedule_holidays for holidays
using_domain_names: False #Disable if you are not using domain names
using_user_tags: False #Disable if you are not using user tags
using_ticket_form_history: False #Disable if you are not using ticket form history
Expand Down Expand Up @@ -231,7 +233,7 @@ This dbt package is dependent on the following dbt packages. These dependencies
```yml
packages:
- package: fivetran/zendesk_source
version: [">=0.12.0", "<0.13.0"]
version: [">=0.13.0", "<0.14.0"]

- package: fivetran/fivetran_utils
version: [">=0.4.0", "<0.5.0"]
Expand Down
22 changes: 13 additions & 9 deletions dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
name: 'zendesk'
version: '0.17.0'

version: '0.18.0'

config-version: 2
require-dbt-version: [">=1.3.0", "<2.0.0"]
Expand All @@ -14,6 +13,10 @@ models:
intermediate:
+schema: zendesk_intermediate
+materialized: table
int_zendesk__schedule_timezones:
+materialized: ephemeral
int_zendesk__schedule_holiday:
+materialized: ephemeral
reply_times:
+materialized: ephemeral
resolution_times:
Expand All @@ -33,23 +36,24 @@ vars:
zendesk:
ticket_field_history_columns: ['assignee_id', 'status', 'priority']
ticket_field_history_updater_columns: []
group: "{{ ref('stg_zendesk__group') }}"
audit_log: "{{ ref('stg_zendesk__audit_log') }}"
brand: "{{ ref('stg_zendesk__brand') }}"
daylight_time: "{{ ref('stg_zendesk__daylight_time') }}"
domain_name: "{{ ref('stg_zendesk__domain_name') }}"
field_history: "{{ ref('stg_zendesk__ticket_field_history') }}"
group: "{{ ref('stg_zendesk__group') }}"
organization_tag: "{{ ref('stg_zendesk__organization_tag') }}"
organization: "{{ ref('stg_zendesk__organization') }}"
schedule: "{{ ref('stg_zendesk__schedule') }}"
schedule_holiday: "{{ ref('stg_zendesk__schedule_holiday') }}"
ticket: "{{ ref('stg_zendesk__ticket') }}"
ticket_form_history: "{{ ref('stg_zendesk__ticket_form_history') }}"
schedule: "{{ ref('stg_zendesk__schedule') }}"
ticket_comment: "{{ ref('stg_zendesk__ticket_comment') }}"
field_history: "{{ ref('stg_zendesk__ticket_field_history') }}"
ticket_form_history: "{{ ref('stg_zendesk__ticket_form_history') }}"
ticket_schedule: "{{ ref('stg_zendesk__ticket_schedule') }}"
ticket_tag: "{{ ref('stg_zendesk__ticket_tag') }}"
ticket: "{{ ref('stg_zendesk__ticket') }}"
time_zone: "{{ ref('stg_zendesk__time_zone') }}"
user_tag: "{{ ref('stg_zendesk__user_tag') }}"
user: "{{ ref('stg_zendesk__user') }}"
daylight_time: "{{ ref('stg_zendesk__daylight_time') }}"
time_zone: "{{ ref('stg_zendesk__time_zone') }}"
using_schedules: true
using_domain_names: true
using_user_tags: true
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.

11 changes: 5 additions & 6 deletions integration_tests/dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
config-version: 2

name: 'zendesk_integration_tests'
version: '0.17.0'
version: '0.18.0'

profile: 'integration_tests'

Expand All @@ -25,27 +25,26 @@ vars:
zendesk_organization_tag_identifier: "organization_tag_data"
zendesk_user_identifier: "user_data"
zendesk_user_tag_identifier: "user_tag_data"
zendesk_audit_log_identifier: "audit_log_data"

## Uncomment for docs generation
# zendesk__unstructured_enabled: True
# using_schedule_histories: True

## For validation testing. To be commented out before release.
# zendesk_schema: zendesk_test_env
# using_domain_names: false
# using_user_tags: false
# using_organization_tags: false
# fivetran_integrity_sla_first_reply_time_exclusion_tickets: (1,56,80)
# fivetran_consistency_ticket_metrics_exclusion_tickets: (11092,11093,11094)
# fivetran_integrity_sla_count_match_tickets: (76)
# fivetran_integrity_sla_metric_parity_exclusion_tickets: (56,80)
# fivetran_integrity_sla_first_reply_time_exclusion_tickets: (56,80)

models:
+schema: "zendesk_{{ var('directed_schema','dev') }}"

seeds:
+quote_columns: "{{ true if target.type == 'redshift' else false }}"
zendesk_integration_tests:
+column_types:
_fivetran_synced: timestamp
+column_types:
_fivetran_synced: timestamp
group_data:
Expand Down
Loading