Skip to content

Commit

Permalink
[hud][ch] weekly_force_merge_stats (#5608)
Browse files Browse the repository at this point in the history
The result changes slightly due to using issue_comment.created_at
instead of m._event_time as the threshold for the date

A better timestamp to use would probably be push, but I don't want to do
another join right now
  • Loading branch information
clee2000 authored Sep 3, 2024
1 parent c7f4053 commit 6d20230
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 51 deletions.
48 changes: 23 additions & 25 deletions torchci/clickhouse_queries/weekly_force_merge_stats/query.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
-- !!! Query is not converted to CH syntax yet. Delete this line when it gets converted
-- Gets percentage of total force merges, force merges with failures, and force merges without failures (impatient)
-- Specifically this query tracks the force merges kpi and metric on HUD
--
Expand All @@ -8,13 +7,13 @@
-- merge_type: If set, will return only data about the requested force merge type.
-- Can be one of: "All", "Impatience", "Failures", or " " (to get everything)
WITH issue_comments AS (
SELECT
SELECT
issue_comment.user.login,
issue_comment.author_association,
issue_comment.body,
issue_comment.issue_url,
issue_comment.html_url,
issue_comment.created,
issue_comment.created_at,
CAST(
SUBSTR(
issue_comment.issue_url,
Expand All @@ -24,7 +23,7 @@ WITH issue_comments AS (
) AS INT
) AS pr_num
FROM
commons.issue_comment
issue_comment final
WHERE
(
issue_comment.body LIKE '%pytorchbot merge%'
Expand All @@ -34,6 +33,8 @@ WITH issue_comments AS (
AND issue_comment.user.login NOT LIKE '%facebook-github-bot%'
AND issue_comment.user.login NOT LIKE '%pytorchmergebot%'
AND issue_comment.issue_url LIKE '%https://api.github.com/repos/pytorch/pytorch/issues/%'
AND issue_comment.created_at >= {startTime: DateTime64(3)}
AND issue_comment.created_at < {stopTime: DateTime64(3)}
),
all_merges AS (
SELECT
Expand All @@ -45,16 +46,14 @@ all_merges AS (
m.is_failed,
m.pr_num,
m.merge_commit_sha,
max(c.created) AS time,
max(c.created_at) AS time
FROM
commons.merges m
merges m
INNER JOIN issue_comments c ON m.pr_num = c.pr_num
WHERE
m.owner = 'pytorch'
AND m.project = 'pytorch'
AND m.merge_commit_sha != '' -- only consider successful merges
AND m._event_time >= PARSE_DATETIME_ISO8601(: startTime)
AND m._event_time < PARSE_DATETIME_ISO8601(: stopTime)
GROUP BY
m.skip_mandatory_checks,
m.failed_checks,
Expand Down Expand Up @@ -116,22 +115,21 @@ results AS (
1,
0
) AS force_merge_with_failures,
CAST(time as DATE) AS date
IF(
{one_bucket: Bool},
'Overall',
formatDateTime(
DATE_TRUNC({granularity: String}, time),
'%Y-%m-%d'
)
) AS bucket
FROM
merges_identifying_force_merges
ORDER BY
date DESC
),
bucketed_counts AS (
time DESC
) , bucketed_counts AS (
SELECT
IF(
: one_bucket,
'Overall',
FORMAT_TIMESTAMP(
'%Y-%m-%d',
DATE_TRUNC(: granularity, date)
)
) AS granularity_bucket,
bucket as granularity_bucket,
SUM(force_merge_with_failures) AS with_failures_cnt,
SUM(force_merge) - SUM(force_merge_with_failures) AS impatience_cnt,
COUNT(*) AS total,
Expand Down Expand Up @@ -160,7 +158,7 @@ rolling_raw_stats AS (
SUM(total) OVER(
ORDER BY
granularity_bucket ROWS 1 PRECEDING
) AS total,
) AS total
FROM
bucketed_counts
),
Expand All @@ -169,7 +167,7 @@ stats_per_bucket AS (
granularity_bucket,
with_failures_cnt * 100.0 / total AS with_failures_percent,
impatience_cnt * 100.0 / total AS impatience_percent,
total_force_merge_cnt * 100.0 / total AS force_merge_percent,
total_force_merge_cnt * 100.0 / total AS force_merge_percent
FROM
rolling_raw_stats
),
Expand Down Expand Up @@ -207,13 +205,13 @@ filtered_result AS (
FROM
final_table
WHERE
TRIM(: merge_type) = ''
OR name LIKE CONCAT('%', : merge_type, '%')
TRIM({merge_type: String}) = ''
OR name LIKE CONCAT('%', {merge_type: String}, '%')
)
SELECT
*
FROM
filtered_result
ORDER BY
granularity_bucket DESC,
name
name
72 changes: 46 additions & 26 deletions torchci/pages/metrics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -580,41 +580,61 @@ export default function Page() {
queryName={"weekly_force_merge_stats"}
metricName={"metric"}
valueRenderer={(value) => value.toFixed(1) + "%"}
queryParams={[
{
name: "one_bucket",
type: "bool",
value: "True",
},
{
name: "merge_type",
type: "string",
value: "Failure",
},
...timeParams,
]}
queryParams={
useClickHouse
? {
...timeParamsClickHouse,
merge_type: "Failure",
one_bucket: true,
granularity: "week", // Not used but ClickHouse requires it
}
: [
{
name: "one_bucket",
type: "bool",
value: "True",
},
{
name: "merge_type",
type: "string",
value: "Failure",
},
...timeParams,
]
}
badThreshold={(value) => value > 8.5}
useClickHouse={useClickHouse}
/>
<ScalarPanel
title={"% force merges due to impatience"}
queryCollection={"commons"}
queryName={"weekly_force_merge_stats"}
metricName={"metric"}
valueRenderer={(value) => value.toFixed(1) + "%"}
queryParams={[
{
name: "one_bucket",
type: "bool",
value: "True",
},
{
name: "merge_type",
type: "string",
value: "Impatience",
},
...timeParams,
]}
queryParams={
useClickHouse
? {
...timeParamsClickHouse,
merge_type: "Impatience",
one_bucket: true,
granularity: "week", // Not used but ClickHouse requires it
}
: [
{
name: "one_bucket",
type: "bool",
value: "True",
},
{
name: "merge_type",
type: "string",
value: "Impatience",
},
...timeParams,
]
}
badThreshold={(value) => value > 10}
useClickHouse={useClickHouse}
/>
</Stack>
</Grid>
Expand Down

0 comments on commit 6d20230

Please sign in to comment.