Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4ca425d

Browse files
feat(coderd/notifications): group workspace build failure report (cherry-pick#17306) (#17338)
Co-authored-by: Danielle Maywood <danielle@themaywoods.com>Closes#15745
1 parent9ea3910 commit4ca425d

10 files changed

+551
-245
lines changed

‎coderd/database/dbmem/dbmem.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3283,6 +3283,7 @@ func (q *FakeQuerier) GetFailedWorkspaceBuildsByTemplateID(ctx context.Context,
32833283
}
32843284

32853285
workspaceBuildStats=append(workspaceBuildStats, database.GetFailedWorkspaceBuildsByTemplateIDRow{
3286+
WorkspaceID:w.ID,
32863287
WorkspaceName:w.Name,
32873288
WorkspaceOwnerUsername:workspaceOwner.Username,
32883289
TemplateVersionName:templateVersion.Name,
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
UPDATE notification_templates
2+
SET
3+
name='Report: Workspace Builds Failed For Template',
4+
title_template= E'Workspace builds failed for template "{{.Labels.template_display_name}}"',
5+
body_template= E'Template **{{.Labels.template_display_name}}** has failed to build {{.Data.failed_builds}}/{{.Data.total_builds}} times over the last {{.Data.report_frequency}}.
6+
7+
**Report:**
8+
{{range $version := .Data.template_versions}}
9+
**{{$version.template_version_name}}** failed {{$version.failed_count}} time{{if gt $version.failed_count 1.0}}s{{end}}:
10+
{{range $build := $version.failed_builds}}
11+
* [{{$build.workspace_owner_username}} / {{$build.workspace_name}} / #{{$build.build_number}}]({{base_url}}/@{{$build.workspace_owner_username}}/{{$build.workspace_name}}/builds/{{$build.build_number}})
12+
{{- end}}
13+
{{end}}
14+
We recommend reviewing these issues to ensure future builds are successful.',
15+
actions='[
16+
{
17+
"label": "View workspaces",
18+
"url": "{{ base_url }}/workspaces?filter=template%3A{{.Labels.template_name}}"
19+
}
20+
]'::jsonb
21+
WHERE id='34a20db2-e9cc-4a93-b0e4-8569699d7a00';
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
UPDATE notification_templates
2+
SET
3+
name='Report: Workspace Builds Failed',
4+
title_template='Failed workspace builds report',
5+
body_template=
6+
E'The following templates have had build failures over the last {{.Data.report_frequency}}:
7+
{{range $template := .Data.templates}}
8+
- **{{$template.display_name}}** failed to build {{$template.failed_builds}}/{{$template.total_builds}} times
9+
{{end}}
10+
11+
**Report:**
12+
{{range $template := .Data.templates}}
13+
**{{$template.display_name}}**
14+
{{range $version := $template.versions}}
15+
- **{{$version.template_version_name}}** failed {{$version.failed_count}} time{{if gt $version.failed_count 1.0}}s{{end}}:
16+
{{range $build := $version.failed_builds}}
17+
- [{{$build.workspace_owner_username}} / {{$build.workspace_name}} / #{{$build.build_number}}]({{base_url}}/@{{$build.workspace_owner_username}}/{{$build.workspace_name}}/builds/{{$build.build_number}})
18+
{{end}}
19+
{{end}}
20+
{{end}}
21+
22+
We recommend reviewing these issues to ensure future builds are successful.',
23+
actions='[
24+
{
25+
"label": "View workspaces",
26+
"url": "{{ base_url }}/workspaces?filter={{$first := true}}{{range $template := .Data.templates}}{{range $version := $template.versions}}{{range $build := $version.failed_builds}}{{if not $first}}+{{else}}{{$first = false}}{{end}}id%3A{{$build.workspace_id}}{{end}}{{end}}{{end}}"
27+
}
28+
]'::jsonb
29+
WHERE id='34a20db2-e9cc-4a93-b0e4-8569699d7a00';

‎coderd/database/queries.sql.go

Lines changed: 7 additions & 4 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/queries/workspacebuilds.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ SELECT
213213
tv.nameAS template_version_name,
214214
u.usernameAS workspace_owner_username,
215215
w.nameAS workspace_name,
216+
w.idAS workspace_id,
216217
wb.build_numberAS workspace_build_number
217218
FROM
218219
workspace_build_with_userAS wb

‎coderd/notifications/notifications_test.go

Lines changed: 84 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -978,45 +978,102 @@ func TestNotificationTemplates_Golden(t *testing.T) {
978978
UserName:"Bobby",
979979
UserEmail:"bobby@coder.com",
980980
UserUsername:"bobby",
981-
Labels:map[string]string{
982-
"template_name":"bobby-first-template",
983-
"template_display_name":"Bobby First Template",
984-
},
981+
Labels:map[string]string{},
985982
// We need to use floats as `json.Unmarshal` unmarshal numbers in `map[string]any` to floats.
986983
Data:map[string]any{
987-
"failed_builds":4.0,
988-
"total_builds":55.0,
989984
"report_frequency":"week",
990-
"template_versions": []map[string]any{
985+
"templates": []map[string]any{
991986
{
992-
"template_version_name":"bobby-template-version-1",
993-
"failed_count":3.0,
994-
"failed_builds": []map[string]any{
987+
"name":"bobby-first-template",
988+
"display_name":"Bobby First Template",
989+
"failed_builds":4.0,
990+
"total_builds":55.0,
991+
"versions": []map[string]any{
995992
{
996-
"workspace_owner_username":"mtojek",
997-
"workspace_name":"workspace-1",
998-
"build_number":1234.0,
993+
"template_version_name":"bobby-template-version-1",
994+
"failed_count":3.0,
995+
"failed_builds": []map[string]any{
996+
{
997+
"workspace_owner_username":"mtojek",
998+
"workspace_name":"workspace-1",
999+
"workspace_id":"24f5bd8f-1566-4374-9734-c3efa0454dc7",
1000+
"build_number":1234.0,
1001+
},
1002+
{
1003+
"workspace_owner_username":"johndoe",
1004+
"workspace_name":"my-workspace-3",
1005+
"workspace_id":"372a194b-dcde-43f1-b7cf-8a2f3d3114a0",
1006+
"build_number":5678.0,
1007+
},
1008+
{
1009+
"workspace_owner_username":"jack",
1010+
"workspace_name":"workwork",
1011+
"workspace_id":"1386d294-19c1-4351-89e2-6cae1afb9bfe",
1012+
"build_number":774.0,
1013+
},
1014+
},
9991015
},
10001016
{
1001-
"workspace_owner_username":"johndoe",
1002-
"workspace_name":"my-workspace-3",
1003-
"build_number":5678.0,
1004-
},
1005-
{
1006-
"workspace_owner_username":"jack",
1007-
"workspace_name":"workwork",
1008-
"build_number":774.0,
1017+
"template_version_name":"bobby-template-version-2",
1018+
"failed_count":1.0,
1019+
"failed_builds": []map[string]any{
1020+
{
1021+
"workspace_owner_username":"ben",
1022+
"workspace_name":"cool-workspace",
1023+
"workspace_id":"86fd99b1-1b6e-4b7e-b58e-0aee6e35c159",
1024+
"build_number":8888.0,
1025+
},
1026+
},
10091027
},
10101028
},
10111029
},
10121030
{
1013-
"template_version_name":"bobby-template-version-2",
1014-
"failed_count":1.0,
1015-
"failed_builds": []map[string]any{
1031+
"name":"bobby-second-template",
1032+
"display_name":"Bobby Second Template",
1033+
"failed_builds":5.0,
1034+
"total_builds":50.0,
1035+
"versions": []map[string]any{
1036+
{
1037+
"template_version_name":"bobby-template-version-1",
1038+
"failed_count":3.0,
1039+
"failed_builds": []map[string]any{
1040+
{
1041+
"workspace_owner_username":"daniellemaywood",
1042+
"workspace_name":"workspace-9",
1043+
"workspace_id":"cd469690-b6eb-4123-b759-980be7a7b278",
1044+
"build_number":9234.0,
1045+
},
1046+
{
1047+
"workspace_owner_username":"johndoe",
1048+
"workspace_name":"my-workspace-7",
1049+
"workspace_id":"c447d472-0800-4529-a836-788754d5e27d",
1050+
"build_number":8678.0,
1051+
},
1052+
{
1053+
"workspace_owner_username":"jack",
1054+
"workspace_name":"workworkwork",
1055+
"workspace_id":"919db6df-48f0-4dc1-b357-9036a2c40f86",
1056+
"build_number":374.0,
1057+
},
1058+
},
1059+
},
10161060
{
1017-
"workspace_owner_username":"ben",
1018-
"workspace_name":"cool-workspace",
1019-
"build_number":8888.0,
1061+
"template_version_name":"bobby-template-version-2",
1062+
"failed_count":2.0,
1063+
"failed_builds": []map[string]any{
1064+
{
1065+
"workspace_owner_username":"ben",
1066+
"workspace_name":"more-cool-workspace",
1067+
"workspace_id":"c8fb0652-9290-4bf2-a711-71b910243ac2",
1068+
"build_number":8878.0,
1069+
},
1070+
{
1071+
"workspace_owner_username":"ben",
1072+
"workspace_name":"less-cool-workspace",
1073+
"workspace_id":"703d718d-2234-4990-9a02-5b1df6cf462a",
1074+
"build_number":8848.0,
1075+
},
1076+
},
10201077
},
10211078
},
10221079
},

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp