Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dbad69d

Browse files
chore: add workspace oom/ood notification templates (#16250)
1 parent 7cbd77f commit dbad69d

10 files changed

+457
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
DELETE FROM notification_templates WHERE id = 'f047f6a3-5713-40f7-85aa-0394cce9fa3a';
2+
DELETE FROM notification_templates WHERE id = 'a9d027b4-ac49-4fb1-9f6d-45af15f64e7a';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
INSERT INTO notification_templates
2+
(id, name, title_template, body_template, "group", actions)
3+
VALUES (
4+
'a9d027b4-ac49-4fb1-9f6d-45af15f64e7a',
5+
'Workspace Out Of Memory',
6+
E'Your workspace "{{.Labels.workspace}}" is low on memory',
7+
E'Hi {{.UserName}},\n\n'||
8+
E'Your workspace **{{.Labels.workspace}}** has reached the memory usage threshold set at **{{.Labels.threshold}}**.',
9+
'Workspace Events',
10+
'[
11+
{
12+
"label": "View workspace",
13+
"url": "{{base_url}}/@{{.UserUsername}}/{{.Labels.workspace}}"
14+
}
15+
]'::jsonb
16+
);
17+
18+
INSERT INTO notification_templates
19+
(id, name, title_template, body_template, "group", actions)
20+
VALUES (
21+
'f047f6a3-5713-40f7-85aa-0394cce9fa3a',
22+
'Workspace Out Of Disk',
23+
E'Your workspace "{{.Labels.workspace}}" is low on volume space',
24+
E'Hi {{.UserName}},\n\n'||
25+
E'{{ if eq (len .Data.volumes) 1 }}{{ $volume := index .Data.volumes 0 }}'||
26+
E'Volume **`{{$volume.path}}`** is over {{$volume.threshold}} full in workspace **{{.Labels.workspace}}**.'||
27+
E'{{ else }}'||
28+
E'The following volumes are nearly full in workspace **{{.Labels.workspace}}**\n\n'||
29+
E'{{ range $volume := .Data.volumes }}'||
30+
E'- **`{{$volume.path}}`** is over {{$volume.threshold}} full\n'||
31+
E'{{ end }}'||
32+
E'{{ end }}',
33+
'Workspace Events',
34+
'[
35+
{
36+
"label": "View workspace",
37+
"url": "{{base_url}}/@{{.UserUsername}}/{{.Labels.workspace}}"
38+
}
39+
]'::jsonb
40+
);

coderd/notifications/events.go

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ var (
1515
TemplateWorkspaceAutoUpdated = uuid.MustParse("c34a0c09-0704-4cac-bd1c-0c0146811c2b")
1616
TemplateWorkspaceMarkedForDeletion = uuid.MustParse("51ce2fdf-c9ca-4be1-8d70-628674f9bc42")
1717
TemplateWorkspaceManualBuildFailed = uuid.MustParse("2faeee0f-26cb-4e96-821c-85ccb9f71513")
18+
TemplateWorkspaceOutOfMemory = uuid.MustParse("a9d027b4-ac49-4fb1-9f6d-45af15f64e7a")
19+
TemplateWorkspaceOutOfDisk = uuid.MustParse("f047f6a3-5713-40f7-85aa-0394cce9fa3a")
1820
)
1921

2022
// Account-related events.

coderd/notifications/notifications_test.go

+61
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,67 @@ func TestNotificationTemplates_Golden(t *testing.T) {
10641064
},
10651065
},
10661066
},
1067+
{
1068+
name: "TemplateWorkspaceOutOfMemory",
1069+
id: notifications.TemplateWorkspaceOutOfMemory,
1070+
payload: types.MessagePayload{
1071+
UserName: "Bobby",
1072+
UserEmail: "[email protected]",
1073+
UserUsername: "bobby",
1074+
Labels: map[string]string{
1075+
"workspace": "bobby-workspace",
1076+
"threshold": "90%",
1077+
},
1078+
},
1079+
},
1080+
{
1081+
name: "TemplateWorkspaceOutOfDisk",
1082+
id: notifications.TemplateWorkspaceOutOfDisk,
1083+
payload: types.MessagePayload{
1084+
UserName: "Bobby",
1085+
UserEmail: "[email protected]",
1086+
UserUsername: "bobby",
1087+
Labels: map[string]string{
1088+
"workspace": "bobby-workspace",
1089+
},
1090+
Data: map[string]any{
1091+
"volumes": []map[string]any{
1092+
{
1093+
"path": "/home/coder",
1094+
"threshold": "90%",
1095+
},
1096+
},
1097+
},
1098+
},
1099+
},
1100+
{
1101+
name: "TemplateWorkspaceOutOfDisk_MultipleVolumes",
1102+
id: notifications.TemplateWorkspaceOutOfDisk,
1103+
payload: types.MessagePayload{
1104+
UserName: "Bobby",
1105+
UserEmail: "[email protected]",
1106+
UserUsername: "bobby",
1107+
Labels: map[string]string{
1108+
"workspace": "bobby-workspace",
1109+
},
1110+
Data: map[string]any{
1111+
"volumes": []map[string]any{
1112+
{
1113+
"path": "/home/coder",
1114+
"threshold": "90%",
1115+
},
1116+
{
1117+
"path": "/dev/coder",
1118+
"threshold": "80%",
1119+
},
1120+
{
1121+
"path": "/etc/coder",
1122+
"threshold": "95%",
1123+
},
1124+
},
1125+
},
1126+
},
1127+
},
10671128
}
10681129

10691130
// We must have a test case for every notification_template. This is enforced below:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
2+
3+
Subject: Your workspace "bobby-workspace" is low on volume space
4+
Message-Id: 02ee4935-73be-4fa1-a290-ff9999026b13@blush-whale-48
5+
Date: Fri, 11 Oct 2024 09:03:06 +0000
6+
Content-Type: multipart/alternative; boundary=bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4
7+
MIME-Version: 1.0
8+
9+
--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4
10+
Content-Transfer-Encoding: quoted-printable
11+
Content-Type: text/plain; charset=UTF-8
12+
13+
Hi Bobby,
14+
15+
Volume /home/coder is over 90% full in workspace bobby-workspace.
16+
17+
18+
View workspace: http://test.com/@bobby/bobby-workspace
19+
20+
--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4
21+
Content-Transfer-Encoding: quoted-printable
22+
Content-Type: text/html; charset=UTF-8
23+
24+
<!doctype html>
25+
<html lang=3D"en">
26+
<head>
27+
<meta charset=3D"UTF-8" />
28+
<meta name=3D"viewport" content=3D"width=3Ddevice-width, initial-scale=
29+
=3D1.0" />
30+
<title>Your workspace "bobby-workspace" is low on volume space</title>
31+
</head>
32+
<body style=3D"margin: 0; padding: 0; font-family: -apple-system, system-=
33+
ui, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarel=
34+
l', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif; color: #020617=
35+
; background: #f8fafc;">
36+
<div style=3D"max-width: 600px; margin: 20px auto; padding: 60px; borde=
37+
r: 1px solid #e2e8f0; border-radius: 8px; background-color: #fff; text-alig=
38+
n: left; font-size: 14px; line-height: 1.5;">
39+
<div style=3D"text-align: center;">
40+
<img src=3D"https://coder.com/coder-logo-horizontal.png" alt=3D"Cod=
41+
er Logo" style=3D"height: 40px;" />
42+
</div>
43+
<h1 style=3D"text-align: center; font-size: 24px; font-weight: 400; m=
44+
argin: 8px 0 32px; line-height: 1.5;">
45+
Your workspace "bobby-workspace" is low on volume space
46+
</h1>
47+
<div style=3D"line-height: 1.5;">
48+
<p>Hi Bobby,</p>
49+
50+
<p>Volume <strong><code>/home/coder</code></strong> is over 90% full in wor=
51+
kspace <strong>bobby-workspace</strong>.</p>
52+
</div>
53+
<div style=3D"text-align: center; margin-top: 32px;">
54+
=20
55+
<a href=3D"http://test.com/@bobby/bobby-workspace" style=3D"display=
56+
: inline-block; padding: 13px 24px; background-color: #020617; color: #f8fa=
57+
fc; text-decoration: none; border-radius: 8px; margin: 0 4px;">
58+
View workspace
59+
</a>
60+
=20
61+
</div>
62+
<div style=3D"border-top: 1px solid #e2e8f0; color: #475569; font-siz=
63+
e: 12px; margin-top: 64px; padding-top: 24px; line-height: 1.6;">
64+
<p>&copy;&nbsp;2024&nbsp;Coder. All rights reserved&nbsp;-&nbsp;<a =
65+
href=3D"http://test.com" style=3D"color: #2563eb; text-decoration: none;">h=
66+
ttp://test.com</a></p>
67+
<p><a href=3D"http://test.com/settings/notifications" style=3D"colo=
68+
r: #2563eb; text-decoration: none;">Click here to manage your notification =
69+
settings</a></p>
70+
<p><a href=3D"http://test.com/settings/notifications?disabled=3Df04=
71+
7f6a3-5713-40f7-85aa-0394cce9fa3a" style=3D"color: #2563eb; text-decoration=
72+
: none;">Stop receiving emails like this</a></p>
73+
</div>
74+
</div>
75+
</body>
76+
</html>
77+
78+
--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4--
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
2+
3+
Subject: Your workspace "bobby-workspace" is low on volume space
4+
Message-Id: 02ee4935-73be-4fa1-a290-ff9999026b13@blush-whale-48
5+
Date: Fri, 11 Oct 2024 09:03:06 +0000
6+
Content-Type: multipart/alternative; boundary=bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4
7+
MIME-Version: 1.0
8+
9+
--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4
10+
Content-Transfer-Encoding: quoted-printable
11+
Content-Type: text/plain; charset=UTF-8
12+
13+
Hi Bobby,
14+
15+
The following volumes are nearly full in workspace bobby-workspace
16+
17+
/home/coder is over 90% full
18+
/dev/coder is over 80% full
19+
/etc/coder is over 95% full
20+
21+
22+
View workspace: http://test.com/@bobby/bobby-workspace
23+
24+
--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4
25+
Content-Transfer-Encoding: quoted-printable
26+
Content-Type: text/html; charset=UTF-8
27+
28+
<!doctype html>
29+
<html lang=3D"en">
30+
<head>
31+
<meta charset=3D"UTF-8" />
32+
<meta name=3D"viewport" content=3D"width=3Ddevice-width, initial-scale=
33+
=3D1.0" />
34+
<title>Your workspace "bobby-workspace" is low on volume space</title>
35+
</head>
36+
<body style=3D"margin: 0; padding: 0; font-family: -apple-system, system-=
37+
ui, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarel=
38+
l', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif; color: #020617=
39+
; background: #f8fafc;">
40+
<div style=3D"max-width: 600px; margin: 20px auto; padding: 60px; borde=
41+
r: 1px solid #e2e8f0; border-radius: 8px; background-color: #fff; text-alig=
42+
n: left; font-size: 14px; line-height: 1.5;">
43+
<div style=3D"text-align: center;">
44+
<img src=3D"https://coder.com/coder-logo-horizontal.png" alt=3D"Cod=
45+
er Logo" style=3D"height: 40px;" />
46+
</div>
47+
<h1 style=3D"text-align: center; font-size: 24px; font-weight: 400; m=
48+
argin: 8px 0 32px; line-height: 1.5;">
49+
Your workspace "bobby-workspace" is low on volume space
50+
</h1>
51+
<div style=3D"line-height: 1.5;">
52+
<p>Hi Bobby,</p>
53+
54+
<p>The following volumes are nearly full in workspace <strong>bobby-workspa=
55+
ce</strong></p>
56+
57+
<ul>
58+
<li><strong><code>/home/coder</code></strong> is over 90% full<br>
59+
</li>
60+
<li><strong><code>/dev/coder</code></strong> is over 80% full<br>
61+
</li>
62+
<li><strong><code>/etc/coder</code></strong> is over 95% full<br>
63+
</li>
64+
</ul>
65+
</div>
66+
<div style=3D"text-align: center; margin-top: 32px;">
67+
=20
68+
<a href=3D"http://test.com/@bobby/bobby-workspace" style=3D"display=
69+
: inline-block; padding: 13px 24px; background-color: #020617; color: #f8fa=
70+
fc; text-decoration: none; border-radius: 8px; margin: 0 4px;">
71+
View workspace
72+
</a>
73+
=20
74+
</div>
75+
<div style=3D"border-top: 1px solid #e2e8f0; color: #475569; font-siz=
76+
e: 12px; margin-top: 64px; padding-top: 24px; line-height: 1.6;">
77+
<p>&copy;&nbsp;2024&nbsp;Coder. All rights reserved&nbsp;-&nbsp;<a =
78+
href=3D"http://test.com" style=3D"color: #2563eb; text-decoration: none;">h=
79+
ttp://test.com</a></p>
80+
<p><a href=3D"http://test.com/settings/notifications" style=3D"colo=
81+
r: #2563eb; text-decoration: none;">Click here to manage your notification =
82+
settings</a></p>
83+
<p><a href=3D"http://test.com/settings/notifications?disabled=3Df04=
84+
7f6a3-5713-40f7-85aa-0394cce9fa3a" style=3D"color: #2563eb; text-decoration=
85+
: none;">Stop receiving emails like this</a></p>
86+
</div>
87+
</div>
88+
</body>
89+
</html>
90+
91+
--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4--
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
2+
3+
Subject: Your workspace "bobby-workspace" is low on memory
4+
Message-Id: 02ee4935-73be-4fa1-a290-ff9999026b13@blush-whale-48
5+
Date: Fri, 11 Oct 2024 09:03:06 +0000
6+
Content-Type: multipart/alternative; boundary=bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4
7+
MIME-Version: 1.0
8+
9+
--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4
10+
Content-Transfer-Encoding: quoted-printable
11+
Content-Type: text/plain; charset=UTF-8
12+
13+
Hi Bobby,
14+
15+
Your workspace bobby-workspace has reached the memory usage threshold set a=
16+
t 90%.
17+
18+
19+
View workspace: http://test.com/@bobby/bobby-workspace
20+
21+
--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4
22+
Content-Transfer-Encoding: quoted-printable
23+
Content-Type: text/html; charset=UTF-8
24+
25+
<!doctype html>
26+
<html lang=3D"en">
27+
<head>
28+
<meta charset=3D"UTF-8" />
29+
<meta name=3D"viewport" content=3D"width=3Ddevice-width, initial-scale=
30+
=3D1.0" />
31+
<title>Your workspace "bobby-workspace" is low on memory</title>
32+
</head>
33+
<body style=3D"margin: 0; padding: 0; font-family: -apple-system, system-=
34+
ui, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarel=
35+
l', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif; color: #020617=
36+
; background: #f8fafc;">
37+
<div style=3D"max-width: 600px; margin: 20px auto; padding: 60px; borde=
38+
r: 1px solid #e2e8f0; border-radius: 8px; background-color: #fff; text-alig=
39+
n: left; font-size: 14px; line-height: 1.5;">
40+
<div style=3D"text-align: center;">
41+
<img src=3D"https://coder.com/coder-logo-horizontal.png" alt=3D"Cod=
42+
er Logo" style=3D"height: 40px;" />
43+
</div>
44+
<h1 style=3D"text-align: center; font-size: 24px; font-weight: 400; m=
45+
argin: 8px 0 32px; line-height: 1.5;">
46+
Your workspace "bobby-workspace" is low on memory
47+
</h1>
48+
<div style=3D"line-height: 1.5;">
49+
<p>Hi Bobby,</p>
50+
51+
<p>Your workspace <strong>bobby-workspace</strong> has reached the memory u=
52+
sage threshold set at <strong>90%</strong>.</p>
53+
</div>
54+
<div style=3D"text-align: center; margin-top: 32px;">
55+
=20
56+
<a href=3D"http://test.com/@bobby/bobby-workspace" style=3D"display=
57+
: inline-block; padding: 13px 24px; background-color: #020617; color: #f8fa=
58+
fc; text-decoration: none; border-radius: 8px; margin: 0 4px;">
59+
View workspace
60+
</a>
61+
=20
62+
</div>
63+
<div style=3D"border-top: 1px solid #e2e8f0; color: #475569; font-siz=
64+
e: 12px; margin-top: 64px; padding-top: 24px; line-height: 1.6;">
65+
<p>&copy;&nbsp;2024&nbsp;Coder. All rights reserved&nbsp;-&nbsp;<a =
66+
href=3D"http://test.com" style=3D"color: #2563eb; text-decoration: none;">h=
67+
ttp://test.com</a></p>
68+
<p><a href=3D"http://test.com/settings/notifications" style=3D"colo=
69+
r: #2563eb; text-decoration: none;">Click here to manage your notification =
70+
settings</a></p>
71+
<p><a href=3D"http://test.com/settings/notifications?disabled=3Da9d=
72+
027b4-ac49-4fb1-9f6d-45af15f64e7a" style=3D"color: #2563eb; text-decoration=
73+
: none;">Stop receiving emails like this</a></p>
74+
</div>
75+
</div>
76+
</body>
77+
</html>
78+
79+
--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4--

0 commit comments

Comments
 (0)