-
Notifications
You must be signed in to change notification settings - Fork 928
feat: track resource replacements when claiming a prebuilt workspace #17571
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
Merged
Merged
Changes from 29 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
b32923a
feat: log resource replacements
dannykopping 0b0830f
feat: show terraform state drift diff in build logs
dannykopping 256395a
feat: only highlight lines which mention replacement
dannykopping 61ef61a
feat: notify template admins when prebuild claim results in resource …
dannykopping a66559f
chore: appease linter
dannykopping 222892b
chore: fix notifications test
dannykopping f34e011
fix: don't panic
dannykopping 5168c01
fix: renaming type
dannykopping 41e5e0c
chore: updating migration numbers
dannykopping b29e8fa
chore: minor touch-ups
dannykopping b31ed5e
feat: add resource replacements metric
dannykopping adf98d2
feat: add resource replacement notification
dannykopping f24aef0
8000
make lint; make fmt
dannykopping 70f9a53
chore: adding tests
dannykopping 1e8385d
feat: pass flag to terraform provider when prebuilt workspace claimed
dannykopping d0f00ce
chore: update provider, add test for is_prebuild_claim
dannykopping 11a2c5a
Merge branch 'main' of github.com:/coder/coder into dk/logreplacements
dannykopping ce63b24
Merge branch 'dk/is-prebuild-claim' of github.com:/coder/coder into d…
dannykopping d2c5d43
chore: replace GetTemplatePresetsByID with GetPresetByID
dannykopping 22d82a4
chore: correcting docs link
dannykopping 5209aae
Merge branch 'main' of github.com:/coder/coder into dk/logreplacement
dannykopping 39ce658
Merge branch 'main' of github.com:/coder/coder into dk/logreplacements
dannykopping ac5655f
Merge branch 'main' of github.com:/coder/coder into dk/logreplacements
dannykopping 82c3f58
chore: note provisioner API change
dannykopping 7577a90
chore: fixups
dannykopping a893b79
chore: adding note about immutable resources
dannykopping d9c906a
chore: review feedback
dannykopping 471198a
Merge branch 'main' of github.com:/coder/coder into dk/logreplacements
dannykopping 7d694e6
chore: merge conflicts
dannykopping 6b7a8b7
chore: fix 'is not iterable' bullshit
dannykopping 5df2cb3
Merge branch 'main' of github.com:/coder/coder into dk/logreplacements
dannykopping 6d1c3ea
chore: rename migrations
dannykopping 5f62702
chore: set notifications manager before enterprise server initializes…
dannykopping f74d799
chore: completing refactor since https://github.com/coder/coder/pull/…
dannykopping 971f65c
chore: remove unnecessary atomicity since map is protected by mutex a…
dannykopping bc362b0
chore: appeasing linter's Very Important Suggestion
dannykopping 4fbd356
Merge branch 'main' of github.com:/coder/coder into dk/logreplacements
dannykopping b9eb8be
chore: remove old replacement logging
dannykopping File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
coderd/database/migrations/000322_resource_replacements_notification.down.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number 8000 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DELETE FROM notification_templates WHERE id = '89d9745a-816e-4695-a17f-3d0a229e2b8d'; |
34 changes: 34 additions & 0 deletions
34
coderd/database/migrations/000322_resource_replacements_notification.up.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
INSERT INTO notification_templates | ||
(id, name, title_template, body_template, "group", actions) | ||
VALUES ('89d9745a-816e-4695-a17f-3d0a229e2b8d', | ||
'Prebuilt Workspace Resource Replaced', | ||
E'There might be a problem with a recently claimed prebuilt workspace', | ||
$$ | ||
Workspace **{{.Labels.workspace}}** was claimed from a prebuilt workspace by **{{.Labels.claimant}}**. | ||
|
||
During the claim, Terraform destroyed and recreated the following resources | ||
because one or more immutable attributes changed: | ||
|
||
{{range $resource, $paths := .Data.replacements -}} | ||
- _{{ $resource }}_ was replaced due to changes to _{{ $paths }}_ | ||
{{end}} | ||
|
||
When Terraform must change an immutable attribute, it replaces the entire resource. | ||
If you’re using prebuilds to speed up provisioning, unexpected replacements will slow down | ||
workspace startup—even when claiming a prebuilt environment. | ||
|
||
For tips on preventing replacements and improving claim performance, see [this guide](https://coder.com/docs/admin/templates/extending-templates/prebuilt-workspaces#preventing-resource-replacement). | ||
|
||
NOTE: this prebuilt workspace used the **{{.Labels.preset}}** preset. | ||
$$, | ||
'Template Events', | ||
'[ | ||
{ | ||
"label": "View workspace build", | ||
"url": "{{base_url}}/@{{.Labels.claimant}}/{{.Labels.workspace}}/builds/{{.Labels.workspace_build_num}}" | ||
}, | ||
{ | ||
"label": "View template version", | ||
"url": "{{base_url}}/templates/{{.Labels.org}}/{{.Labels.template}}/versions/{{.Labels.template_version}}" | ||
} | ||
]'::jsonb); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
...ifications/testdata/rendered-templates/smtp/TemplateWorkspaceResourceReplaced.html.golden
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
From: system@coder.com | ||
To: bobby@coder.com | ||
Subject: There might be a problem with a recently claimed prebuilt workspace | ||
Message-Id: 02ee4935-73be-4fa1-a290-ff9999026b13@blush-whale-48 | ||
Date: Fri, 11 Oct 2024 09:03:06 +0000 | ||
Content-Type: multipart/alternative; boundary=bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 | ||
MIME-Version: 1.0 | ||
|
||
--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 | ||
Content-Transfer-Encoding: quoted-printable | ||
Content-Type: text/plain; charset=UTF-8 | ||
|
||
Hi Bobby, | ||
|
||
Workspace my-workspace was claimed from a prebuilt workspace by prebuilds-c= | ||
laimer. | ||
|
||
During the claim, Terraform destroyed and recreated the following resources | ||
because one or more immutable attributes changed: | ||
|
||
docker_container[0] was replaced due to changes to env, hostname | ||
|
||
When Terraform must change an immutable attribute, it replaces the entire r= | ||
esource. | ||
If you=E2=80=99re using prebuilds to speed up provisioning, unexpected repl= | ||
acements will slow down | ||
workspace startup=E2=80=94even when claiming a prebuilt environment. | ||
|
||
For tips on preventing replacements and improving claim performance, see th= | ||
is guide (https://coder.com/docs/admin/templates/extending-templates/prebui= | ||
lt-workspaces#preventing-resource-replacement). | ||
|
||
NOTE: this prebuilt workspace used the particle-accelerator preset. | ||
|
||
|
||
View workspace build: http://test.com/@prebuilds-claimer/my-workspace/build= | ||
s/2 | ||
|
||
View template version: http://test.com/templates/cern/docker/versions/angry= | ||
_torvalds | ||
|
||
--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 | ||
Content-Transfer-Encoding: quoted-printable | ||
Content-Type: text/html; charset=UTF-8 | ||
|
||
<!doctype html> | ||
<html lang=3D"en"> | ||
<head> | ||
<meta charset=3D"UTF-8" /> | ||
<meta name=3D"viewport" content=3D"width=3Ddevice-width, initial-scale= | ||
=3D1.0" /> | ||
<title>There might be a problem with a recently claimed prebuilt worksp= | ||
ace</title> | ||
</head> | ||
<body style=3D"margin: 0; padding: 0; font-family: -apple-system, system-= | ||
ui, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarel= | ||
l', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif; color: #020617= | ||
; background: #f8fafc;"> | ||
<div style=3D"max-width: 600px; margin: 20px auto; padding: 60px; borde= | ||
r: 1px solid #e2e8f0; border-radius: 8px; background-color: #fff; text-alig= | ||
n: left; font-size: 14px; line-height: 1.5;"> | ||
<div style=3D"text-align: center;"> | ||
<img src=3D"https://coder.com/coder-logo-horizontal.png" alt=3D"Cod= | ||
er Logo" style=3D"height: 40px;" /> | ||
</div> | ||
<h1 style=3D"text-align: center; font-size: 24px; font-weight: 400; m= | ||
argin: 8px 0 32px; line-height: 1.5;"> | ||
There might be a problem with a recently claimed prebuilt workspace | ||
</h1> | ||
<div style=3D"line-height: 1.5;"> | ||
<p>Hi Bobby,</p> | ||
<p>Workspace <strong>my-workspace</strong> was claimed from a prebu= | ||
ilt workspace by <strong>prebuilds-claimer</strong>.</p> | ||
|
||
<p>During the claim, Terraform destroyed and recreated the following resour= | ||
ces<br> | ||
because one or more immutable attributes changed:</p> | ||
|
||
<ul> | ||
<li>_docker<em>container[0]</em> was replaced due to changes to <em>env, h= | ||
ostname</em><br> | ||
</li> | ||
</ul> | ||
|
||
<p>When Terraform must change an immutable attribute, it replaces the entir= | ||
e resource.<br> | ||
If you=E2=80=99re using prebuilds to speed up provisioning, unexpected repl= | ||
acements will slow down<br> | ||
workspace startup=E2=80=94even when claiming a prebuilt environment.</p> | ||
|
||
<p>For tips on preventing replacements and improving claim performance, see= | ||
<a href=3D"https://coder.com/docs/admin/templates/extending-templates/preb= | ||
uilt-workspaces#preventing-resource-replacement">this guide</a>.</p> | ||
|
||
<p>NOTE: this prebuilt workspace used the <strong>particle-accelerator</str= | ||
ong> preset.</p> | ||
</div> | ||
<div style=3D"text-align: center; margin-top: 32px;"> | ||
=20 | ||
<a href=3D"http://test.com/@prebuilds-claimer/my-workspace/builds/2= | ||
" style=3D"display: inline-block; padding: 13px 24px; background-color: #02= | ||
0617; color: #f8fafc; text-decoration: none; border-radius: 8px; margin: 0 = | ||
4px;"> | ||
View workspace build | ||
</a> | ||
=20 | ||
<a href=3D"http://test.com/templates/cern/docker/versions/angry_tor= | ||
valds" style=3D"display: inline-block; padding: 13px 24px; background-color= | ||
: #020617; color: #f8fafc; text-decoration: none; border-radius: 8px; margi= | ||
n: 0 4px;"> | ||
View template version | ||
</a> | ||
=20 | ||
</div> | ||
<div style=3D"border-top: 1px solid #e2e8f0; color: #475569; font-siz= | ||
e: 12px; margin-top: 64px; padding-top: 24px; line-height: 1.6;"> | ||
<p>© 2024 Coder. All rights reserved - <a = | ||
href=3D"http://test.com" style=3D"color: #2563eb; text-decoration: none;">h= | ||
ttp://test.com</a></p> | ||
<p><a href=3D"http://test.com/settings/notifications" style=3D"colo= | ||
r: #2563eb; text-decoration: none;">Click here to manage your notification = | ||
settings</a></p> | ||
<p><a href=3D"http://test.com/settings/notifications?disabled=3D89d= | ||
9745a-816e-4695-a17f-3d0a229e2b8d" style=3D"color: #2563eb; text-decoration= | ||
: none;">Stop receiving emails like this</a></p> | ||
</div> | ||
</div> | ||
</body> | ||
</html> | ||
|
||
--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4-- |
42 changes: 42 additions & 0 deletions
42
...cations/testdata/rendered-templates/webhook/TemplateWorkspaceResourceReplaced.json.golden
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"_version": "1.1", | ||
"msg_id": "00000000-0000-0000-0000-000000000000", | ||
"payload": { | ||
"_version": "1.2", | ||
"notification_name": "Prebuilt Workspace Resource Replaced", | ||
"notification_template_id": "00000000-0000-0000-0000-000000000000", | ||
"user_id": "00000000-0000-0000-0000-000000000000", | ||
"user_email": "bobby@coder.com", | ||
"user_name": "Bobby", | ||
"user_username": "bobby", | ||
"actions": [ | ||
{ | ||
"label": "View workspace build", | ||
"url": "http://test.com/@prebuilds-claimer/my-workspace/builds/2" | ||
}, | ||
{ | ||
"label": "View template version", | ||
"url": "http://test.com/templates/cern/docker/versions/angry_torvalds" | ||
} | ||
], | ||
"labels": { | ||
"claimant": "prebuilds-claimer", | ||
"org": "cern", | ||
"preset": "particle-accelerator", | ||
"template": "docker", | ||
"template_version": "angry_torvalds", | ||
"workspace": "my-workspace", | ||
"workspace_build_num": "2" | ||
}, | ||
"data": { | ||
"replacements": { | ||
"docker_container[0]": "env, hostname" | ||
} | ||
}, | ||
"targets": null | ||
}, | ||
"title": "There might be a problem with a recently claimed prebuilt workspace", | ||
"title_markdown": "There might be a problem with a recently claimed prebuilt workspace", | ||
"body": "Workspace my-workspace was claimed from a prebuilt workspace by prebuilds-claimer.\n\nDuring the claim, Terraform destroyed and recreated the following resources\nbecause one or more immutable attributes changed:\n\ndocker_container[0] was replaced due to changes to env, hostname\n\nWhen Terraform must change an immutable attribute, it replaces the entire resource.\nIf you’re using prebuilds to speed up provisioning, unexpected replacements will slow down\nworkspace startup—even when claiming a prebuilt environment.\n\nFor tips on preventing replacements and improving claim performance, see this guide (https://coder.com/docs/admin/templates/extending-templates/prebuilt-workspaces#preventing-resource-replacement).\n\nNOTE: t 1241 his prebuilt workspace used the particle-accelerator preset.", | ||
"body_markdown": "\nWorkspace **my-workspace** was claimed from a prebuilt workspace by **prebuilds-claimer**.\n\nDuring the claim, Terraform destroyed and recreated the following resources\nbecause one or more immutable attributes changed:\n\n- _docker_container[0]_ was replaced due to changes to _env, hostname_\n\n\nWhen Terraform must change an immutable attribute, it replaces the entire resource.\nIf you’re using prebuilds to speed up provisioning, unexpected replacements will slow down\nworkspace startup—even when claiming a prebuilt environment.\n\nFor tips on preventing replacements and improving claim performance, see [this guide](https://coder.com/docs/admin/templates/extending-templates/prebuilt-workspaces#preventing-resource-replacement).\n\nNOTE: this prebuilt workspace used the **particle-accelerator** preset.\n" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.