Skip to content

Commit

Permalink
Get response times and time to merge
Browse files Browse the repository at this point in the history
  • Loading branch information
ravenac95 committed Nov 25, 2024
1 parent fe7a46d commit 045a0de
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 113 deletions.
31 changes: 31 additions & 0 deletions warehouse/metrics_mesh/models/code/issue_event_time_deltas.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
-- Model that records the delta (in seconds) since the creation of the issue or
-- pr.
MODEL (
name metrics.issue_event_time_deltas,
kind VIEW
);
select `time`,
event_type,
event_source,
@oso_id(
event_source,
to_artifact_id,
issue_number
) as issue_id,
issue_number,
to_artifact_id,
from_artifact_id,
created_at,
merged_at,
closed_at,
date_diff('second', created_at, `time`) as created_delta,
case
when merged_at is null then null
else date_diff('second', merged_at, `time`)
end as merged_delta,
case
when closed_at is null then null
else date_diff('second', closed_at, `time`)
end as closed_delta,
comments
from @oso_source.timeseries_events_aux_issues_by_artifact_v0
22 changes: 22 additions & 0 deletions warehouse/metrics_mesh/models/first_of_event_from_artifact.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
MODEL (
name metrics.first_of_event_from_artifact,
kind FULL,
partitioned_by (day("time"), "event_type", "event_source"),
grain (
time,
event_type,
event_source,
from_artifact_id,
to_artifact_id
),
);
select MIN(time) as time,
event_type,
event_source,
from_artifact_id,
to_artifact_id
from @oso_source.timeseries_events_by_artifact_v0
group by event_type,
event_source,
from_artifact_id,
to_artifact_id
22 changes: 22 additions & 0 deletions warehouse/metrics_mesh/models/last_of_event_from_artifact.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
MODEL (
name metrics.last_of_event_from_artifact,
kind FULL,
partitioned_by (day("time"), "event_type", "event_source"),
grain (
time,
event_type,
event_source,
from_artifact_id,
to_artifact_id
),
);
select MAX(time) as time,
event_type,
event_source,
from_artifact_id,
to_artifact_id
from @oso_source.timeseries_events_by_artifact_v0
group by event_type,
event_source,
from_artifact_id,
to_artifact_id
24 changes: 23 additions & 1 deletion warehouse/metrics_mesh/models/metrics_factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
start="2015-01-01",
catalog="metrics",
model_prefix="timeseries",
timeseries_sources=[
"events_daily_to_artifact",
"issue_event_time_deltas",
],
metric_queries={
# This will automatically generate star counts for the given roll up periods.
# A time_aggregation is just a simple addition of the aggregation. So basically we
Expand Down Expand Up @@ -165,7 +169,7 @@
),
entity_types=["artifact", "project", "collection"],
),
"closed_issues_6_months": MetricQueryDef(
"closed_issues": MetricQueryDef(
ref="issues_closed.sql",
rolling=RollingConfig(
windows=[180],
Expand All @@ -174,6 +178,24 @@
),
entity_types=["artifact", "project", "collection"],
),
"avg_prs_time_to_merge": MetricQueryDef(
ref="prs_time_to_merge.sql",
rolling=RollingConfig(
windows=[90, 180],
unit="day",
cron="@daily",
),
entity_types=["artifact", "project", "collection"],
),
"avg_time_to_first_response": MetricQueryDef(
ref="prs_time_to_merge.sql",
rolling=RollingConfig(
windows=[90, 180],
unit="day",
cron="@daily",
),
entity_types=["artifact", "project", "collection"],
),
},
default_dialect="clickhouse",
)
34 changes: 0 additions & 34 deletions warehouse/metrics_mesh/oso_metrics/prs_days_to_merge.sql

This file was deleted.

14 changes: 14 additions & 0 deletions warehouse/metrics_mesh/oso_metrics/prs_time_to_merge.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
select @metrics_sample_date(time) as metrics_sample_date,
event_source,
to_artifact_id,
'' as from_artifact_id,
@metric_name() as metric,
AVG(created_delta) as amount
from metrics.issue_event_time_deltas
where event_type = 'PULL_REQUEST_MERGED'
and `time` BETWEEN @metrics_start('DATE') and @metrics_end('DATE')
group by 1,
metric,
from_artifact_id,
to_artifact_id,
event_source,
98 changes: 20 additions & 78 deletions warehouse/metrics_mesh/oso_metrics/time_to_first_response.sql
Original file line number Diff line number Diff line change
@@ -1,81 +1,23 @@
select
@metrics_sample_date(time_to_first_response_events.responded_at) as metrics_sample_date,
time_to_first_response_events.event_source,
time_to_first_response_events.to_artifact_id,
select @metrics_sample_date(time) as metrics_sample_date,
event_source,
to_artifact_id,
'' as from_artifact_id,
@metric_name() as metric,
AVG(time_to_first_response_events.amount) as amount
from (
select
responded_at,
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_events
on
start_events.issue_number = resp_events.issue_number
and start_events.to_artifact_id = resp_events.to_artifact_id
and start_events.creator_id != resp_events.responder_id
and (
(
start_events.event_type = 'ISSUE_OPENED'
and resp_events.event_type in (
'ISSUE_COMMENT', 'ISSUE_CLOSED'
)
)
or
(
start_events.event_type = 'PULL_REQUEST_OPENED'
and resp_events.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.responded_at 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,
AVG(created_delta) as amount
from metrics.issue_event_time_deltas
where (
(
event_type in ("PULL_REQUEST_MERGED", "ISSUE_CLOSED")
and comments = 0
)
or (
event_type in ("PULL_REQUEST_REVIEW_COMMENT", "ISSUE_COMMENT")
and comments = 1
)
)
and `time` BETWEEN @metrics_start('DATE') and @metrics_end('DATE')
group by 1,
metric,
from_artifact_id,
metric
to_artifact_id,
event_source,

0 comments on commit 045a0de

Please sign in to comment.