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 filter in filtered reply times CTE in int_zendesk__reply_time_combined #134

Closed
wants to merge 12 commits into from
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# dbt_zendesk v0.13.2

[PR #134](https://github.com/fivetran/dbt_zendesk/pull/134) includes the following changes:

## Bug Fixes
- Updated the `int_zendesk__reply_time_combined` model to additionally account for the following scenarios as they were erroneously being filtered out in previous versions of the package:
- A ticket is first replied to outside SLA schedules
- A ticket is has not yet received an agent reply
> Note: This update only impacts first reply time business metrics

# dbt_zendesk v0.13.1

[PR #128](https://github.com/fivetran/dbt_zendesk/pull/128) includes the following changes:
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
- Calculates SLA policy breaches for Zendesk Professional or Enterprise users
- Generates a comprehensive data dictionary of your source and modeled Zendesk data through the [dbt docs site](https://fivetran.github.io/dbt_zendesk/).

> Note: Tickets from the Zendesk Chat channel will not populate in this package as the Fivetran connector does not currently support Chat based tickets. This is a feature request that has been flagged.

<!--section="zendesk_transformation_model"-->
The following table provides a detailed list of final models materialized within this package by default.
> TIP: See more details about these models in the package's [dbt docs site](https://fivetran.github.io/dbt_zendesk/#!/overview?g_v=1).
Expand Down
2 changes: 1 addition & 1 deletion dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 'zendesk'
version: '0.13.1'
version: '0.13.2'


config-version: 2
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.

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

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion 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.13.1'
version: '0.13.2'

profile: 'integration_tests'

Expand Down
27 changes: 16 additions & 11 deletions models/sla_policy/reply_time/int_zendesk__reply_time_combined.sql
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ with reply_time_calendar_hours_sla as (
*,
lead(sla_schedule_start_at) over (partition by ticket_id, sla_policy_name, metric, sla_applied_at order by sla_schedule_start_at) as next_schedule_start,
min(sla_breach_at) over (partition by sla_policy_name, metric, sla_applied_at order by sla_schedule_start_at rows unbounded preceding) as first_sla_breach_at,
coalesce(lag(sum_lapsed_business_minutes) over (partition by sla_policy_name, metric, sla_applied_at order by sla_schedule_start_at), 0) as sum_lapsed_business_minutes_new
coalesce(lag(sum_lapsed_business_minutes) over (partition by sla_policy_name, metric, sla_applied_at order by sla_schedule_start_at), 0) as sum_lapsed_business_minutes_new,
{{ dbt.datediff("sla_schedule_start_at", "agent_reply_at", 'minute') }} as total_runtime_minutes -- total minutes from sla_schedule_start_at and agent reply time, before taking into account SLA end time
from reply_time_breached_at_with_next_reply_timestamp

), filtered_reply_times as (
Expand All @@ -119,7 +120,8 @@ with reply_time_calendar_hours_sla as (
and ((
agent_reply_at >= sla_schedule_start_at and agent_reply_at <= sla_schedule_end_at) -- ticket is replied to between a schedule window
or (agent_reply_at < sla_schedule_start_at and sum_lapsed_business_minutes_new = 0 and sla_breach_at = first_sla_breach_at) -- ticket is replied to before a schedule window and no business minutes have been spent on it
or (agent_reply_at is null and {{ dbt.current_timestamp() }} >= sla_schedule_start_at and {{ dbt.current_timestamp() }} < next_schedule_start) -- ticket is not replied to and therefore active. But only bring through the active SLA record that is most recent (after the last SLA schedule starts but before the next)
or (agent_reply_at is null and {{ dbt.current_timestamp() }} >= sla_schedule_start_at and ({{ dbt.current_timestamp() }} < next_schedule_start or next_schedule_start is null)) -- ticket is not replied to and therefore active. But only bring through the active SLA record that is most recent (after the last SLA schedule starts but before the next, or if there does not exist a next SLA schedule start time)
or (agent_reply_at > sla_schedule_end_at and (agent_reply_at < next_schedule_start or next_schedule_start is null)) -- ticket is replied to outside sla schedule hours
))
or not in_business_hours

Expand All @@ -137,18 +139,21 @@ with reply_time_calendar_hours_sla as (
or (agent_reply_at is null and next_solved_at is null)
then true
else false
end as is_sla_breached
end as is_sla_breached,
sum_lapsed_business_minutes_new + total_runtime_minutes as total_new_minutes -- add total runtime to sum_lapsed_business_minutes_new (the sum_lapsed_business_minutes from prior row)
from filtered_reply_times
), reply_time_breach as (
select

), reply_time_breach as (
select
*,
case when {{ dbt.datediff("sla_schedule_start_at", "agent_reply_at", 'minute') }} < 0
then 0
else sum_lapsed_business_minutes_new + {{ dbt.datediff("sla_schedule_start_at", "coalesce(agent_reply_at, current_time_check)", 'minute') }}
case when total_runtime_minutes < 0 -- agent has already replied to prior to this SLA schedule
then 0 -- so don't add new minutes to the SLA
when total_new_minutes > sum_lapsed_business_minutes -- if total runtime, regardless of when the SLA schedule ended, is more than the total lapsed business minutes, that means the agent replied after the SLA schedule
then sum_lapsed_business_minutes -- the elapsed time after the SLA end time should not be calculated as part of the business minutes, therefore sla_elapsed_time should only be sum_lapsed_business_minutes
else sum_lapsed_business_minutes_new + {{ dbt.datediff("sla_schedule_start_at", "coalesce(agent_reply_at, current_time_check)", 'minute') }} -- otherwise, the sla_elapsed_time will be sum_lapsed_business_minutes_new (the prior record's sum_lapsed_business_minutes) plus the minutes between SLA schedule start and agent_reply_time. If the agent hasn't replied yet, then the minute counter is still running, hence the coalesce of agent_reply_time and current_time_check.
end as sla_elapsed_time
from reply_time_breached_at_remove_old_sla
from reply_time_breached_at_remove_old_sla
)

select *
from reply_time_breach
from reply_time_breach