Skip to content

Commit

Permalink
feat(sqlmesh): add model for time to first response
Browse files Browse the repository at this point in the history
  • Loading branch information
ccerv1 committed Nov 22, 2024
1 parent f2dc33f commit 181db3c
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions warehouse/metrics_mesh/oso_metrics/time_to_first_response.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
select
@metrics_sample_date(time_to_first_response_events.time) as metrics_sample_date,
time_to_first_response_events.event_source,
time_to_first_response_events.to_artifact_id,
'' as from_artifact_id,
@metric_name() as metric,
AVG(time_to_first_response_events.amount) as amount
from (
select
responded_at as `time`,
to_artifact_id,
event_source,
time_to_first_response_days as amount
from (
select
start_events.issue_number,
start_events.to_artifact_id,
start_events.created_at,
start_events.event_source,
min(resp.responded_at) as responded_at,
cast(
timestamp_diff(min(resp.responded_at), start_events.created_at, minute)
as float64
) / 60.0 / 24.0 as time_to_first_response_days
from (
select
issue_number,
from_artifact_id as creator_id,
to_artifact_id,
time,
event_type
from metrics.timeseries_events_aux_issues_by_artifact_v0
where event_type in ('PULL_REQUEST_OPENED', 'ISSUE_OPENED')
) as start_events
inner join (
select
issue_number,
from_artifact_id as responder_id,
to_artifact_id,
time as responded_at,
event_type
from metrics.timeseries_events_aux_issues_by_artifact_v0
where event_type in (
'PULL_REQUEST_MERGED',
'PULL_REQUEST_REVIEW_COMMENT',
'ISSUE_CLOSED',
'ISSUE_COMMENT'
)
) as resp
on
start_events.issue_number = resp.issue_number
and start_events.to_artifact_id = resp.to_artifact_id
and start_events.creator_id != resp.responder_id
and (
(
start_events.event_type = 'ISSUE_OPENED'
and resp.event_type in (
'ISSUE_COMMENT', 'ISSUE_CLOSED'
)
)
or
(
start_events.event_type = 'PULL_REQUEST_OPENED'
and resp.event_type in (
'PULL_REQUEST_REVIEW_COMMENT', 'PULL_REQUEST_MERGED'
)
)
)
group by
start_events.issue_number,
start_events.to_artifact_id,
start_events.created_at
) as time_to_first_response
) as time_to_first_response_events
where time_to_first_response_events.time BETWEEN @metrics_start('DATE') AND @metrics_end('DATE')
group by
metrics_sample_date,
time_to_first_response_events.event_source,
time_to_first_response_events.to_artifact_id,
from_artifact_id,
metric

0 comments on commit 181db3c

Please sign in to comment.