Skip to content

Commit 2d00cd4

Browse files
authored
feat: org dashboard metrics endpoints and copy pipe (#3344)
Signed-off-by: Gašper Grom <[email protected]>
1 parent 37ee3e9 commit 2d00cd4

3 files changed

Lines changed: 130 additions & 0 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
DESCRIPTION >
2+
Organization-project metrics for organization dashboard
3+
4+
SCHEMA >
5+
`slug` String,
6+
`accountName` String,
7+
`commits` UInt64,
8+
`orgCommits` UInt64,
9+
`prsOpened` UInt64,
10+
`orgPrsOpened` UInt64,
11+
`contributorCount` UInt64,
12+
`orgContributorCount` UInt64,
13+
`averageMergeTimeSeconds` Nullable(Float64),
14+
`orgAverageMergeTimeSeconds` Nullable(Float64),
15+
`maintainersCount` UInt64
16+
17+
ENGINE MergeTree
18+
ENGINE_SORTING_KEY accountName, slug
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
NODE org_dash_metric_copy_pipe_memberships_deduplicated
2+
SQL >
3+
SELECT accountName, organizationId FROM lfxMemberships FINAL WHERE organizationId != ''
4+
5+
NODE org_dash_metric_copy_pipe_projects_deduplicated
6+
SQL >
7+
SELECT id, slug, segmentId
8+
FROM insights_projects_populated_ds
9+
WHERE contributorCount > 0 AND organizationCount > 0
10+
GROUP BY id, slug, segmentId
11+
12+
NODE org_dash_metric_copy_pipe_org_project_options
13+
SQL >
14+
SELECT *
15+
FROM org_dash_metric_copy_pipe_memberships_deduplicated
16+
CROSS JOIN org_dash_metric_copy_pipe_projects_deduplicated
17+
18+
NODE org_dash_metric_copy_pipe_project_activities
19+
SQL >
20+
SELECT
21+
segmentId,
22+
countIf(
23+
case when activityId != '' then activityId else null end, type = 'authored-commit'
24+
) as commits,
25+
countIf(
26+
case when activityId != '' then activityId else null end, type = 'pull_request-opened'
27+
) as prsOpened,
28+
uniq(memberId) AS contributorCount
29+
FROM activityRelations_deduplicated_cleaned_ds
30+
GROUP BY segmentId
31+
32+
NODE org_dash_metric_copy_pipe_org_activities
33+
SQL >
34+
SELECT
35+
segmentId,
36+
organizationId,
37+
countIf(
38+
case when activityId != '' then activityId else null end, type = 'authored-commit'
39+
) as orgCommits,
40+
countIf(
41+
case when activityId != '' then activityId else null end, type = 'pull_request-opened'
42+
) as orgPrsOpened,
43+
uniq(memberId) AS orgContributorCount
44+
FROM activityRelations_deduplicated_cleaned_ds
45+
GROUP BY segmentId, organizationId
46+
47+
NODE org_dash_metric_copy_pipe_project_avg_merge_time
48+
SQL >
49+
SELECT segmentId, round(avg(mergedInSeconds)) as averageMergeTimeSeconds
50+
FROM pull_requests_analyzed
51+
GROUP BY segmentId
52+
53+
NODE org_dash_metric_copy_pipe_org_avg_merge_time
54+
SQL >
55+
SELECT segmentId, organizationId, round(avg(mergedInSeconds)) as orgAverageMergeTimeSeconds
56+
FROM pull_requests_analyzed
57+
GROUP BY segmentId, organizationId
58+
59+
NODE org_dash_metric_copy_pipe_org_maintainers
60+
SQL >
61+
SELECT insightsProjectId as id, organizationId, uniq(memberId) as maintainersCount
62+
FROM maintainers_roles_copy_ds
63+
WHERE role = 'maintainer' AND toYear(endDate) <= 1970 AND organizationId != ''
64+
GROUP BY insightsProjectId, organizationId
65+
66+
NODE org_dash_metric_copy_pipe_metrics
67+
SQL >
68+
SELECT
69+
slug,
70+
accountName,
71+
sum(commits) as commits,
72+
sum(orgCommits) as orgCommits,
73+
sum(prsOpened) as prsOpened,
74+
sum(orgPrsOpened) as orgPrsOpened,
75+
sum(contributorCount) as contributorCount,
76+
sum(orgContributorCount) as orgContributorCount,
77+
avg(averageMergeTimeSeconds) as averageMergeTimeSeconds,
78+
avg(orgAverageMergeTimeSeconds) as orgAverageMergeTimeSeconds,
79+
sum(maintainersCount) as maintainersCount
80+
FROM org_dash_metric_copy_pipe_org_project_options
81+
LEFT JOIN org_dash_metric_copy_pipe_project_activities USING (segmentId)
82+
LEFT JOIN org_dash_metric_copy_pipe_org_activities USING (segmentId, organizationId)
83+
LEFT JOIN org_dash_metric_copy_pipe_project_avg_merge_time USING (segmentId)
84+
LEFT JOIN org_dash_metric_copy_pipe_org_avg_merge_time USING (segmentId, organizationId)
85+
LEFT JOIN org_dash_metric_copy_pipe_org_maintainers USING (id, organizationId)
86+
GROUP BY slug, accountName
87+
88+
TYPE COPY
89+
TARGET_DATASOURCE org_dash_metric_copy_ds
90+
COPY_MODE replace
91+
COPY_SCHEDULE 50 0 * * *
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
TOKEN "org_dash_metrics_endpoint_read_9856" READ
2+
3+
NODE org_dash_metrics_results
4+
DESCRIPTION >
5+
Filters all pr opened activities in last year for given project
6+
7+
SQL >
8+
%
9+
SELECT *
10+
FROM org_dash_metric_copy_ds
11+
WHERE
12+
1 = 1
13+
{% if defined(accountName) %}
14+
AND accountName
15+
= {{ String(accountName, description="Filter accountName", required=False) }}
16+
{% end %}
17+
{% if defined(slugs) %}
18+
AND slug in {{ Array(slugs, 'String', description="Filter slugs", required=False) }}
19+
{% end %}
20+
LIMIT {{ Int32(pageSize, 20) }}
21+
OFFSET {{ Int32(page, 0) * Int32(pageSize, 20) }}

0 commit comments

Comments
 (0)