Skip to content

Commit b3081de

Browse files
chore: split out into two notifications
1 parent 6c6240b commit b3081de

8 files changed

+263
-17
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
DELETE FROM notification_templates WHERE id = 'f047f6a3-5713-40f7-85aa-0394cce9fa3a';
12
DELETE FROM notification_templates WHERE id = 'a9d027b4-ac49-4fb1-9f6d-45af15f64e7a';

coderd/database/migrations/000288_oom_and_ood_notification.up.sql

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,27 @@ INSERT INTO notification_templates
22
(id, name, title_template, body_template, "group", actions)
33
VALUES (
44
'a9d027b4-ac49-4fb1-9f6d-45af15f64e7a',
5-
'Workspace Reached Resource Threshold',
6-
E'Workspace "{{.Labels.workspace}}" reached resource threshold',
5+
'Workspace Out Of Memory',
6+
E'Your workspace "{{.Labels.workspace}}" is low on memory',
77
E'Hi {{.UserName}},\n\n'||
8-
E'Your workspace **{{.Labels.workspace}}** has reached the {{.Labels.threshold_type}} threshold set at **{{.Labels.threshold}}**.',
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 disk',
24+
E'Hi {{.UserName}},\n\n'||
25+
E'Your workspace **{{.Labels.workspace}}** has reached the usage threshold set at **{{.Labels.threshold}}** for volume `{{.Labels.volume}}`.',
926
'Workspace Events',
1027
'[
1128
{

coderd/notifications/events.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@ import "github.com/google/uuid"
77

88
// Workspace-related events.
99
var (
10-
TemplateWorkspaceCreated = uuid.MustParse("281fdf73-c6d6-4cbb-8ff5-888baf8a2fff")
11-
TemplateWorkspaceManuallyUpdated = uuid.MustParse("d089fe7b-d5c5-4c0c-aaf5-689859f7d392")
12-
TemplateWorkspaceDeleted = uuid.MustParse("f517da0b-cdc9-410f-ab89-a86107c420ed")
13-
TemplateWorkspaceAutobuildFailed = uuid.MustParse("381df2a9-c0c0-4749-420f-80a9280c66f9")
14-
TemplateWorkspaceDormant = uuid.MustParse("0ea69165-ec14-4314-91f1-69566ac3c5a0")
15-
TemplateWorkspaceAutoUpdated = uuid.MustParse("c34a0c09-0704-4cac-bd1c-0c0146811c2b")
16-
TemplateWorkspaceMarkedForDeletion = uuid.MustParse("51ce2fdf-c9ca-4be1-8d70-628674f9bc42")
17-
TemplateWorkspaceManualBuildFailed = uuid.MustParse("2faeee0f-26cb-4e96-821c-85ccb9f71513")
18-
TemplateWorkspaceReachedResourceThreshold = uuid.MustParse("a9d027b4-ac49-4fb1-9f6d-45af15f64e7a")
10+
TemplateWorkspaceCreated = uuid.MustParse("281fdf73-c6d6-4cbb-8ff5-888baf8a2fff")
11+
TemplateWorkspaceManuallyUpdated = uuid.MustParse("d089fe7b-d5c5-4c0c-aaf5-689859f7d392")
12+
TemplateWorkspaceDeleted = uuid.MustParse("f517da0b-cdc9-410f-ab89-a86107c420ed")
13+
TemplateWorkspaceAutobuildFailed = uuid.MustParse("381df2a9-c0c0-4749-420f-80a9280c66f9")
14+
TemplateWorkspaceDormant = uuid.MustParse("0ea69165-ec14-4314-91f1-69566ac3c5a0")
15+
TemplateWorkspaceAutoUpdated = uuid.MustParse("c34a0c09-0704-4cac-bd1c-0c0146811c2b")
16+
TemplateWorkspaceMarkedForDeletion = uuid.MustParse("51ce2fdf-c9ca-4be1-8d70-628674f9bc42")
17+
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")
1920
)
2021

2122
// Account-related events.

coderd/notifications/notifications_test.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,16 +1065,29 @@ func TestNotificationTemplates_Golden(t *testing.T) {
10651065
},
10661066
},
10671067
{
1068-
name: "TemplateWorkspaceReachedResourceThreshold",
1069-
id: notifications.TemplateWorkspaceReachedResourceThreshold,
1068+
name: "TemplateWorkspaceOutOfMemory",
1069+
id: notifications.TemplateWorkspaceOutOfMemory,
10701070
payload: types.MessagePayload{
10711071
UserName: "Bobby",
10721072
UserEmail: "bobby@coder.com",
10731073
UserUsername: "bobby",
10741074
Labels: map[string]string{
1075-
"workspace": "bobby-workspace",
1076-
"threshold_type": "memory usage",
1077-
"threshold": "90%",
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: "bobby@coder.com",
1086+
UserUsername: "bobby",
1087+
Labels: map[string]string{
1088+
"workspace": "bobby-workspace",
1089+
"threshold": "90%",
1090+
"volume": "/home/coder",
10781091
},
10791092
},
10801093
},
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
From: system@coder.com
2+
To: bobby@coder.com
3+
Subject: Your workspace "bobby-workspace" is low on disk
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 volume 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 disk</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 disk
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 volume 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=3Df04=
72+
7f6a3-5713-40f7-85aa-0394cce9fa3a" 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--
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
From: system@coder.com
2+
To: bobby@coder.com
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--
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"_version": "1.1",
3+
"msg_id": "00000000-0000-0000-0000-000000000000",
4+
"payload": {
5+
"_version": "1.1",
6+
"notification_name": "Workspace Out Of Disk",
7+
"notification_template_id": "00000000-0000-0000-0000-000000000000",
8+
"user_id": "00000000-0000-0000-0000-000000000000",
9+
"user_email": "bobby@coder.com",
10+
"user_name": "Bobby",
11+
"user_username": "bobby",
12+
"actions": [
13+
{
14+
"label": "View workspace",
15+
"url": "http://test.com/@bobby/bobby-workspace"
16+
}
17+
],
18+
"labels": {
19+
"threshold": "90%",
20+
"workspace": "bobby-workspace"
21+
},
22+
"data": null
23+
},
24+
"title": "Your workspace \"bobby-workspace\" is low on disk",
25+
"title_markdown": "Your workspace \"bobby-workspace\" is low on disk",
26+
"body": "Hi Bobby,\n\nYour workspace bobby-workspace has reached the volume usage threshold set at 90%.",
27+
"body_markdown": "Hi Bobby,\n\nYour workspace **bobby-workspace** has reached the volume usage threshold set at **90%**."
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"_version": "1.1",
3+
"msg_id": "00000000-0000-0000-0000-000000000000",
4+
"payload": {
5+
"_version": "1.1",
6+
"notification_name": "Workspace Out Of Memory",
7+
"notification_template_id": "00000000-0000-0000-0000-000000000000",
8+
"user_id": "00000000-0000-0000-0000-000000000000",
9+
"user_email": "bobby@coder.com",
10+
"user_name": "Bobby",
11+
"user_username": "bobby",
12+
"actions": [
13+
{
14+
"label": "View workspace",
15+
"url": "http://test.com/@bobby/bobby-workspace"
16+
}
17+
],
18+
"labels": {
19+
"threshold": "90%",
20+
"workspace": "bobby-workspace"
21+
},
22+
"data": null
23+
},
24+
"title": "Your workspace \"bobby-workspace\" is low on memory",
25+
"title_markdown": "Your workspace \"bobby-workspace\" is low on memory",
26+
"body": "Hi Bobby,\n\nYour workspace bobby-workspace has reached the memory usage threshold set at 90%.",
27+
"body_markdown": "Hi Bobby,\n\nYour workspace **bobby-workspace** has reached the memory usage threshold set at **90%**."
28+
}

0 commit comments

Comments
 (0)