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

(cherrypick to release-v1.0) fix: update weekly report (#7678) #7679

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 24 additions & 31 deletions grafana/dashboards/WeeklyReport.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"editable": true,
"fiscalYearStartMonth": 0,
"graphTooltip": 0,
"id": 40,
"id": 21,
"links": [],
"liveNow": false,
"panels": [
Expand All @@ -43,7 +43,7 @@
"content": "- This dashboard shows all the key metrics in the weekly report.",
"mode": "markdown"
},
"pluginVersion": "10.4.1",
"pluginVersion": "11.0.0",
"targets": [
{
"datasource": {
Expand Down Expand Up @@ -87,6 +87,7 @@
"mode": "off"
}
},
"decimals": 1,
"mappings": [
{
"options": {
Expand All @@ -108,7 +109,7 @@
}
]
},
"unit": "none"
"unit": "d"
},
"overrides": []
},
Expand Down Expand Up @@ -144,6 +145,7 @@
"valueSize": 12
},
"tooltip": {
"maxHeight": 600,
"mode": "single",
"sort": "none"
},
Expand All @@ -160,7 +162,7 @@
"hide": false,
"metricColumn": "none",
"rawQuery": true,
"rawSql": "with _deployed_prs as(\n SELECT\n pr.id,\n cdc.finished_date as pr_deployed_date,\n -- convert null to 0 if a PR has no cycle_time to make sure cycle_time equals the sum of the four metrics below\n\t\tcoalesce(prm.pr_cycle_time/60,0) as cycle_time\n FROM pull_requests pr\n left join project_pr_metrics prm on pr.id = prm.id\n join project_mapping pm on pr.base_repo_id = pm.row_id and pm.table = 'repos' \n join cicd_deployment_commits cdc on prm.deployment_commit_id = cdc.id\n WHERE\n -- filter the deployed PRs\n cdc.finished_date >= curdate() - INTERVAL WEEKDAY(curdate()) + 7 DAY - INTERVAL 6 MONTH\n and pm.project_name in (${project})\n GROUP BY 1,2,3\n)\n\nSELECT\n\t'Last week' as period,\n\tIFNULL(avg(cycle_time),0.00001) as avg_cycle_time_in_hour_per_week\nFROM \n\t_deployed_prs\nWHERE \n\tpr_deployed_date >= curdate() - INTERVAL WEEKDAY(curdate()) + 7 DAY \n\tand pr_deployed_date < curdate() - INTERVAL WEEKDAY(curdate()) DAY\n\nunion\n\nSELECT \n\t'3 months before last week' as period,\n\tIFNULL(avg(cycle_time), 0.00001) as avg_cycle_time_in_hour_per_week\nFROM \n\t_deployed_prs\nWHERE \n\tpr_deployed_date >= curdate() - INTERVAL WEEKDAY(curdate()) + 7 DAY - INTERVAL 6 MONTH \n\tand pr_deployed_date < curdate() - INTERVAL WEEKDAY(curdate()) + 7 DAY \n",
"rawSql": "with _deployed_prs as(\n SELECT\n pr.id,\n cdc.finished_date as pr_deployed_date,\n -- convert null to 0 if a PR has no cycle_time\n\t prm.pr_cycle_time\n FROM pull_requests pr\n left join project_pr_metrics prm on pr.id = prm.id\n join project_mapping pm on pr.base_repo_id = pm.row_id and pm.table = 'repos' \n join cicd_deployment_commits cdc on prm.deployment_commit_id = cdc.id\n WHERE\n -- filter the deployed PRs\n cdc.finished_date is not NULL\n and prm.pr_cycle_time is not null \n and cdc.result = 'SUCCESS' \n and cdc.environment = 'PRODUCTION' \n and pm.project_name in (${project})\n GROUP BY 1,2,3\n)\n\nSELECT\n\tcase when DATEDIFF($__timeTo(), $__timeFrom()) = 7 then 'Last week' else concat('Last ', DATEDIFF($__timeTo(), $__timeFrom()), ' days') end as period,\n\tIFNULL(round(avg(pr_cycle_time)/1440,1),0.00001) as avg_cycle_time_in_days\nFROM \n\t_deployed_prs\nWHERE \n\tpr_deployed_date >= $__timeFrom()\n\tand pr_deployed_date < $__timeTo()\n\nunion\n\nSELECT \n\t'3 months before the above period' as period,\n\tIFNULL(round(avg(pr_cycle_time)/1440,1), 0.00001) as avg_cycle_time_in_days\nFROM \n\t_deployed_prs\nWHERE \n pr_deployed_date >= $__timeFrom() - INTERVAL 3 MONTH \n\tand pr_deployed_date < $__timeFrom()\n",
"refId": "A",
"select": [
[
Expand Down Expand Up @@ -276,6 +278,7 @@
"options": {
"barRadius": 0,
"barWidth": 0.5,
"colorByField": "period",
"fullHighlight": false,
"groupWidth": 0.7,
"legend": {
Expand All @@ -285,12 +288,13 @@
"showLegend": true
},
"orientation": "horizontal",
"showValue": "auto",
"showValue": "always",
"stacking": "none",
"text": {
"valueSize": 12
},
"tooltip": {
"maxHeight": 600,
"mode": "single",
"sort": "none"
},
Expand All @@ -307,7 +311,7 @@
"hide": false,
"metricColumn": "none",
"rawQuery": true,
"rawSql": "with _deployed_prs as(\n SELECT\n pr.id,\n cdc.finished_date as pr_deployed_date,\n -- convert null to 0 if a PR has no cycle_time to make sure cycle_time equals the sum of the four metrics below\n\t\tcoalesce(prm.pr_cycle_time/60,0) as cycle_time\n FROM pull_requests pr\n left join project_pr_metrics prm on pr.id = prm.id\n join project_mapping pm on pr.base_repo_id = pm.row_id and pm.table = 'repos' \n join cicd_deployment_commits cdc on prm.deployment_commit_id = cdc.id\n WHERE\n -- filter the deployed PRs\n pr.merged_date is not null and prm.pr_cycle_time is not null and cdc.result = 'SUCCESS' and cdc.environment = 'PRODUCTION' \n and cdc.finished_date >= curdate() - INTERVAL WEEKDAY(curdate()) + 7 DAY - INTERVAL 6 MONTH\n and pm.project_name in (${project})\n GROUP BY 1,2,3\n)\n\nSELECT\n\t'Last week' as period,\n\tcase when count(distinct id) = 0 then 0.00001 else count(distinct id) end as avg_pr_count_per_week\nFROM \n\t_deployed_prs\nWHERE \n\tpr_deployed_date >= curdate() - INTERVAL WEEKDAY(curdate()) + 7 DAY \n\tand pr_deployed_date < curdate() - INTERVAL WEEKDAY(curdate()) DAY\n\nunion\n\nSELECT \n\t'3 months before last week' as period,\n\tcount(distinct id)/(DATEDIFF(curdate() - INTERVAL WEEKDAY(curdate())+7 DAY, curdate() - INTERVAL WEEKDAY(curdate()) + 7 DAY - INTERVAL 3 MONTH))*7 as avg_pr_count_per_week\nFROM \n\t_deployed_prs\nWHERE \n\tpr_deployed_date >= curdate() - INTERVAL WEEKDAY(curdate()) + 7 DAY - INTERVAL 6 MONTH \n\tand pr_deployed_date < curdate() - INTERVAL WEEKDAY(curdate()) + 7 DAY \n",
"rawSql": "with _deployed_prs as(\n SELECT\n pr.id,\n cdc.finished_date as pr_deployed_date,\n -- convert null to 0 if a PR has no cycle_time to make sure cycle_time equals the sum of the four metrics below\n\t\tcoalesce(prm.pr_cycle_time/60,0) as cycle_time\n FROM pull_requests pr\n left join project_pr_metrics prm on pr.id = prm.id\n join project_mapping pm on pr.base_repo_id = pm.row_id and pm.table = 'repos' \n join cicd_deployment_commits cdc on prm.deployment_commit_id = cdc.id\n WHERE\n -- filter the deployed PRs\n cdc.finished_date is not NULL\n and prm.pr_cycle_time is not null \n and cdc.result = 'SUCCESS' \n and cdc.environment = 'PRODUCTION' \n and pm.project_name in (${project})\n GROUP BY 1,2,3\n)\n\nSELECT\n\tcase when DATEDIFF($__timeTo(), $__timeFrom()) = 7 then 'Last week' else concat('Last ', DATEDIFF($__timeTo(), $__timeFrom()), ' days') end as period,\n case when count(distinct id) = 0 then 0.00001 else round(count(id)/DATEDIFF($__timeTo(), $__timeFrom())*7, 1) end as avg_deployed_pr_per_week\nFROM \n\t_deployed_prs\nWHERE \n\tpr_deployed_date >= $__timeFrom()\n\tand pr_deployed_date < $__timeTo()\n\nunion\n\nSELECT \n\t'3 months before the above period' as period,\n case when count(distinct id) = 0 then 0.00001 else round(count(id)/DATEDIFF($__timeFrom(), $__timeFrom() - INTERVAL 3 MONTH)*7, 1) end as avg_deployed_pr_per_week\nFROM \n\t_deployed_prs\nWHERE \n\tpr_deployed_date >= $__timeFrom() - INTERVAL 3 MONTH \n\tand pr_deployed_date < $__timeFrom()\n",
"refId": "A",
"select": [
[
Expand Down Expand Up @@ -383,15 +387,16 @@
"mappings": [
{
"options": {
"0.0001": {
"0.00001": {
"color": "red",
"index": 0,
"text": "No deployments in PROD environment in this period."
"text": "No production deployments in this period"
}
},
"type": "value"
}
],
"noValue": "No production deployments in this period",
"thresholds": {
"mode": "absolute",
"steps": [
Expand Down Expand Up @@ -435,6 +440,7 @@
"valueSize": 12
},
"tooltip": {
"maxHeight": 600,
"mode": "multi",
"sort": "none"
},
Expand All @@ -451,7 +457,7 @@
"metricColumn": "none",
"queryType": "randomWalk",
"rawQuery": true,
"rawSql": "-- Metric 1: Number of deployments per month\nwith _deployments as(\n-- When deploying multiple commits in one pipeline, GitLab and BitBucket may generate more than one deployment. However, DevLake consider these deployments as ONE production deployment and use the last one's finished_date as the finished date.\n\t\tSELECT\n\t\t\tcdc.cicd_deployment_id,\n\t\t\tmax(cdc.finished_date) as deployment_finished_date\n\t\tFROM cicd_deployment_commits cdc\n\t\tJOIN project_mapping pm on cdc.cicd_scope_id = pm.row_id and pm.`table` = 'cicd_scopes'\n\t\tWHERE\n\t\t\tpm.project_name in (${project})\n\t\t\tand cdc.result = 'SUCCESS'\n\t\t\tand cdc.environment = 'PRODUCTION'\n\t\tGROUP BY 1\n\t\tHAVING max(cdc.finished_date) >= curdate() - INTERVAL WEEKDAY(curdate()) + 7 DAY - INTERVAL 6 MONTH\n)\n\nSELECT\n\t'Last week' as period,\n\tcase when count(cicd_deployment_id) = 0 then 0.0001 else count(cicd_deployment_id) end as avg_deployment_count_per_week\nFROM \n\t_deployments\nWHERE \n\tdeployment_finished_date >= curdate() - INTERVAL WEEKDAY(curdate()) + 7 DAY \n\tand deployment_finished_date < curdate() - INTERVAL WEEKDAY(curdate()) DAY\n\nunion\n\nSELECT \n\t'3 months before last week' as period,\n\tround(count(cicd_deployment_id)/(DATEDIFF(curdate() - INTERVAL WEEKDAY(curdate())+7 DAY, curdate() - INTERVAL WEEKDAY(curdate()) + 7 DAY - INTERVAL 3 MONTH))*7, 1) as avg_deployment_count_per_week\nFROM \n\t_deployments\nWHERE \n\tdeployment_finished_date >= curdate() - INTERVAL WEEKDAY(curdate()) + 7 DAY - INTERVAL 6 MONTH \n\tand deployment_finished_date < curdate() - INTERVAL WEEKDAY(curdate()) + 7 DAY \n",
"rawSql": "with _deployments as(\n-- When deploying multiple commits in one pipeline, GitLab and BitBucket may generate more than one deployment. However, DevLake consider these deployments as ONE production deployment and use the last one's finished_date as the finished date.\n\t\tSELECT\n\t\t\tcdc.cicd_deployment_id,\n\t\t\tmax(cdc.finished_date) as deployment_finished_date\n\t\tFROM cicd_deployment_commits cdc\n\t\tJOIN project_mapping pm on cdc.cicd_scope_id = pm.row_id and pm.`table` = 'cicd_scopes'\n\t\tWHERE\n\t\t\tpm.project_name in (${project})\n\t\t\tand cdc.result = 'SUCCESS'\n\t\t\tand cdc.environment = 'PRODUCTION'\n\t\tGROUP BY 1\n)\n\nSELECT\n\tcase when DATEDIFF($__timeTo(), $__timeFrom()) = 7 then 'Last week' else concat('Last ', DATEDIFF($__timeTo(), $__timeFrom()), ' days') end as period,\n\tcase when count(cicd_deployment_id) = 0 then 0.00001 else round(count(cicd_deployment_id)/DATEDIFF($__timeTo(), $__timeFrom())*7, 1) end as avg_deployments_per_week\nFROM \n\t_deployments\nWHERE \n\tdeployment_finished_date >= $__timeFrom()\n\tand deployment_finished_date < $__timeTo()\n\nunion\n\nSELECT \n\t'3 months before the above period' as period,\n\tcase when count(cicd_deployment_id) = 0 then 0.00001 else round(count(cicd_deployment_id)/DATEDIFF($__timeFrom(), $__timeFrom() - INTERVAL 3 MONTH)*7, 1) end as avg_deployments_per_week\nFROM \n\t_deployments\nWHERE \n\tdeployment_finished_date >= $__timeFrom() - INTERVAL 3 MONTH \n\tand deployment_finished_date < $__timeFrom()\n",
"refId": "A",
"select": [
[
Expand Down Expand Up @@ -501,7 +507,8 @@
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
"fixedColor": "green",
"mode": "fixed"
},
"custom": {
"axisBorderShow": false,
Expand Down Expand Up @@ -531,7 +538,7 @@
"0.00001": {
"color": "red",
"index": 0,
"text": "No deployments in PROD environment in this period."
"text": "No production deployments in this period"
}
},
"type": "value"
Expand All @@ -548,23 +555,7 @@
},
"unit": "percentunit"
},
"overrides": [
{
"matcher": {
"id": "byName",
"options": "change_failure_rate"
},
"properties": [
{
"id": "color",
"value": {
"fixedColor": "blue",
"mode": "fixed"
}
}
]
}
]
"overrides": []
},
"gridPos": {
"h": 8,
Expand Down Expand Up @@ -597,6 +588,7 @@
"valueSize": 12
},
"tooltip": {
"maxHeight": 600,
"mode": "single",
"sort": "none"
},
Expand All @@ -614,7 +606,7 @@
"hide": false,
"metricColumn": "none",
"rawQuery": true,
"rawSql": "-- Metric 3: change failure rate per month\nwith _deployments as (\n-- When deploying multiple commits in one pipeline, GitLab and BitBucket may generate more than one deployment. However, DevLake consider these deployments as ONE production deployment and use the last one's finished_date as the finished date.\n\tSELECT\n\t\tcdc.cicd_deployment_id as deployment_id,\n\t\tmax(cdc.finished_date) as deployment_finished_date\n\tFROM \n\t\tcicd_deployment_commits cdc\n\t\tJOIN project_mapping pm on cdc.cicd_scope_id = pm.row_id and pm.`table` = 'cicd_scopes'\n\tWHERE\n\t\tpm.project_name in (${project})\n\t\tand cdc.result = 'SUCCESS'\n\t\tand cdc.environment = 'PRODUCTION'\n\tGROUP BY 1\n\tHAVING max(cdc.finished_date) >= curdate() - INTERVAL WEEKDAY(curdate()) + 7 DAY - INTERVAL 6 MONTH\n),\n\n_failure_caused_by_deployments as (\n-- calculate the number of incidents caused by each deployment\n\tSELECT\n\t\td.deployment_id,\n\t\td.deployment_finished_date,\n\t\tcount(distinct case when i.type = 'INCIDENT' then d.deployment_id else null end) as has_incident\n\tFROM\n\t\t_deployments d\n\t\tleft join project_issue_metrics pim on d.deployment_id = pim.deployment_id\n\t\tleft join issues i on pim.id = i.id\n\tGROUP BY 1,2\n)\n\nSELECT\n\t'Last week' as period,\n\tIFNULL(sum(has_incident)/count(deployment_id), 0.00001) as change_failure_rate\nFROM _failure_caused_by_deployments\nWHERE deployment_finished_date >= curdate() - INTERVAL WEEKDAY(curdate()) + 7 DAY and deployment_finished_date < curdate() - INTERVAL WEEKDAY(curdate()) DAY\n\nunion\n\nSELECT \n\t'3 months before last week' as period,\n\tIFNULL(sum(has_incident)/count(deployment_id), 0) as change_failure_rate\nFROM _failure_caused_by_deployments\nWHERE deployment_finished_date >= curdate() - INTERVAL WEEKDAY(curdate()) + 7 DAY - INTERVAL 6 MONTH and deployment_finished_date < curdate() - INTERVAL WEEKDAY(curdate()) + 7 DAY\n",
"rawSql": "with _deployments as (\n-- When deploying multiple commits in one pipeline, GitLab and BitBucket may generate more than one deployment. However, DevLake consider these deployments as ONE production deployment and use the last one's finished_date as the finished date.\n\tSELECT\n\t\tcdc.cicd_deployment_id as deployment_id,\n\t\tmax(cdc.finished_date) as deployment_finished_date\n\tFROM \n\t\tcicd_deployment_commits cdc\n\t\tJOIN project_mapping pm on cdc.cicd_scope_id = pm.row_id and pm.`table` = 'cicd_scopes'\n\tWHERE\n\t\tpm.project_name in (${project})\n\t\tand cdc.result = 'SUCCESS'\n\t\tand cdc.environment = 'PRODUCTION'\n\tGROUP BY 1\n),\n\n_failure_caused_by_deployments as (\n-- calculate the number of incidents caused by each deployment\n\tSELECT\n\t\td.deployment_id,\n\t\td.deployment_finished_date,\n\t\tcount(distinct case when i.type = 'INCIDENT' then d.deployment_id else null end) as has_incident\n\tFROM\n\t\t_deployments d\n\t\tleft join project_issue_metrics pim on d.deployment_id = pim.deployment_id\n\t\tleft join issues i on pim.id = i.id\n\tGROUP BY 1,2\n)\n\nSELECT\n\tcase when DATEDIFF($__timeTo(), $__timeFrom()) = 7 then 'Last week' else concat('Last ', DATEDIFF($__timeTo(), $__timeFrom()), ' days') end as period,\n\tIFNULL(sum(has_incident)/count(deployment_id), 0.00001) as change_failure_rate\nFROM _failure_caused_by_deployments\nWHERE \n\tdeployment_finished_date >= $__timeFrom()\n\tand deployment_finished_date < $__timeTo()\n\nunion\n\nSELECT \n\t'3 months before the above period' as period,\n\tIFNULL(sum(has_incident)/count(deployment_id), 0) as change_failure_rate\nFROM _failure_caused_by_deployments\nWHERE \n\tdeployment_finished_date >= $__timeFrom() - INTERVAL 3 MONTH \n\tand deployment_finished_date < $__timeFrom()\n",
"refId": "A",
"select": [
[
Expand Down Expand Up @@ -714,13 +706,14 @@
]
},
"time": {
"from": "now-6M",
"from": "now-7d",
"to": "now"
},
"timeRangeUpdatedDuringEditOrView": false,
"timepicker": {},
"timezone": "",
"title": "Weekly Report",
"uid": "fdpx91qgjm0owb",
"version": 17,
"version": 11,
"weekStart": ""
}
Loading