Skip to content

Commit c2b27c3

Browse files
committed
Merge remote-tracking branch 'origin/main' into quickstart-guide
2 parents 7e6c079 + 416d67b commit c2b27c3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+508
-163
lines changed

.github/actions/setup-go/action.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: |
44
inputs:
55
version:
66
description: "The Go version to use."
7-
default: "1.22.5"
7+
default: "1.22.6"
88
runs:
99
using: "composite"
1010
steps:

.github/workflows/mlc_config.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
{
1313
"pattern": "docs.github.com"
1414
},
15+
{
16+
"pattern": "github.com/<your_github_handle>"
17+
},
18+
{
19+
"pattern": "imgur.com"
20+
},
1521
{
1622
"pattern": "support.google.com"
1723
},

.github/workflows/security.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ jobs:
114114
echo "image=$(cat "$image_job")" >> $GITHUB_OUTPUT
115115
116116
- name: Run Trivy vulnerability scanner
117-
uses: aquasecurity/trivy-action@f781cce5aab226378ee181d764ab90ea0be3cdd8
117+
uses: aquasecurity/trivy-action@5681af892cd0f4997658e2bacc62bd0a894cf564
118118
with:
119119
image-ref: ${{ steps.build.outputs.image }}
120120
format: sarif

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,8 @@ gen: \
507507
examples/examples.gen.json \
508508
tailnet/tailnettest/coordinatormock.go \
509509
tailnet/tailnettest/coordinateemock.go \
510-
tailnet/tailnettest/multiagentmock.go
510+
tailnet/tailnettest/multiagentmock.go \
511+
coderd/database/pubsub/psmock/psmock.go
511512
.PHONY: gen
512513

513514
# Mark all generated files as fresh so make thinks they're up-to-date. This is
@@ -537,6 +538,7 @@ gen/mark-fresh:
537538
tailnet/tailnettest/coordinatormock.go \
538539
tailnet/tailnettest/coordinateemock.go \
539540
tailnet/tailnettest/multiagentmock.go \
541+
coderd/database/pubsub/psmock/psmock.go \
540542
"
541543

542544
for file in $$files; do

agent/agent.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,7 +1670,7 @@ func (a *agent) manageProcessPriority(ctx context.Context, debouncer *logDebounc
16701670
}
16711671

16721672
score, niceErr := proc.Niceness(a.syscaller)
1673-
if !isBenignProcessErr(niceErr) {
1673+
if niceErr != nil && !isBenignProcessErr(niceErr) {
16741674
debouncer.Warn(ctx, "unable to get proc niceness",
16751675
slog.F("cmd", proc.Cmd()),
16761676
slog.F("pid", proc.PID),
@@ -1689,7 +1689,7 @@ func (a *agent) manageProcessPriority(ctx context.Context, debouncer *logDebounc
16891689

16901690
if niceErr == nil {
16911691
err := proc.SetNiceness(a.syscaller, niceness)
1692-
if !isBenignProcessErr(err) {
1692+
if err != nil && !isBenignProcessErr(err) {
16931693
debouncer.Warn(ctx, "unable to set proc niceness",
16941694
slog.F("cmd", proc.Cmd()),
16951695
slog.F("pid", proc.PID),
@@ -1703,7 +1703,7 @@ func (a *agent) manageProcessPriority(ctx context.Context, debouncer *logDebounc
17031703
if oomScore != unsetOOMScore && oomScore != proc.OOMScoreAdj && !isCustomOOMScore(agentScore, proc) {
17041704
oomScoreStr := strconv.Itoa(oomScore)
17051705
err := afero.WriteFile(a.filesystem, fmt.Sprintf("/proc/%d/oom_score_adj", proc.PID), []byte(oomScoreStr), 0o644)
1706-
if !isBenignProcessErr(err) {
1706+
if err != nil && !isBenignProcessErr(err) {
17071707
debouncer.Warn(ctx, "unable to set oom_score_adj",
17081708
slog.F("cmd", proc.Cmd()),
17091709
slog.F("pid", proc.PID),

cli/testdata/coder_templates_init_--help.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ USAGE:
66
Get started with a templated template.
77

88
OPTIONS:
9-
--id aws-devcontainer|aws-linux|aws-windows|azure-linux|do-linux|docker|gcp-devcontainer|gcp-linux|gcp-vm-container|gcp-windows|kubernetes|nomad-docker|scratch
9+
--id aws-devcontainer|aws-linux|aws-windows|azure-linux|devcontainer-docker|devcontainer-kubernetes|do-linux|docker|gcp-devcontainer|gcp-linux|gcp-vm-container|gcp-windows|kubernetes|nomad-docker|scratch
1010
Specify a given example template by ID.
1111

1212
———
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
UPDATE notification_templates
2+
SET
3+
body_template = E'Hi {{.UserName}},\n\n' ||
4+
E'A manual build of the workspace **{{.Labels.name}}** using the template **{{.Labels.template_name}}** failed (version: **{{.Labels.template_version_name}}**).\n\n' ||
5+
-- Mention template display name:
6+
E'The template''s display name was **{{.Labels.template_display_name}}**. ' ||
7+
E'The workspace build was initiated by **{{.Labels.initiator}}**.'
8+
WHERE
9+
id = '2faeee0f-26cb-4e96-821c-85ccb9f71513';
10+
11+
UPDATE notification_templates
12+
SET
13+
body_template = E'Hi {{.UserName}},\n\n' || -- Add a comma
14+
E'The template **{{.Labels.name}}** was deleted by **{{ .Labels.initiator }}**.\n\n' ||
15+
-- Mention template display name:
16+
E'The template''s display name was **{{.Labels.display_name}}**.'
17+
WHERE
18+
id = '29a09665-2a4c-403f-9648-54301670e7be';
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
UPDATE notification_templates
2+
SET
3+
body_template = E'Hi {{.UserName}},\n\n' ||
4+
-- Revert to a single label for the template name:
5+
E'A manual build of the workspace **{{.Labels.name}}** using the template **{{.Labels.template_name}}** failed (version: **{{.Labels.template_version_name}}**).\n\n' ||
6+
E'The workspace build was initiated by **{{.Labels.initiator}}**.'
7+
WHERE
8+
id = '2faeee0f-26cb-4e96-821c-85ccb9f71513';
9+
10+
UPDATE notification_templates
11+
SET
12+
body_template = E'Hi {{.UserName}},\n\n' ||
13+
-- Revert to a single label for the template name:
14+
E'The template **{{.Labels.name}}** was deleted by **{{ .Labels.initiator }}**.\n\n'
15+
WHERE
16+
id = '29a09665-2a4c-403f-9648-54301670e7be';

coderd/insights_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ func TestUserLatencyInsights(t *testing.T) {
225225
t.Parallel()
226226

227227
db, ps := dbtestutil.NewDB(t)
228-
logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: false}).Leveled(slog.LevelDebug)
228+
logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}).Leveled(slog.LevelDebug)
229229
client := coderdtest.New(t, &coderdtest.Options{
230230
Database: db,
231231
Pubsub: ps,

coderd/notifications/metrics_test.go

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package notifications_test
33
import (
44
"context"
55
"strconv"
6+
"sync"
67
"testing"
78
"time"
89

@@ -317,10 +318,12 @@ func TestInflightDispatchesMetric(t *testing.T) {
317318
})
318319

319320
handler := &fakeHandler{}
320-
// Delayer will delay all dispatches by 2x fetch intervals to ensure we catch the requests inflight.
321-
delayer := newDelayingHandler(cfg.FetchInterval.Value()*2, handler)
321+
const msgCount = 2
322+
323+
// Barrier handler will wait until all notification messages are in-flight.
324+
barrier := newBarrierHandler(msgCount, handler)
322325
mgr.WithHandlers(map[database.NotificationMethod]notifications.Handler{
323-
method: delayer,
326+
method: barrier,
324327
})
325328

326329
enq, err := notifications.NewStoreEnqueuer(cfg, api.Database, defaultHelpers(), api.Logger.Named("enqueuer"), quartz.NewReal())
@@ -329,7 +332,6 @@ func TestInflightDispatchesMetric(t *testing.T) {
329332
user := createSampleUser(t, api.Database)
330333

331334
// WHEN: notifications are enqueued which will succeed (and be delayed during dispatch)
332-
const msgCount = 2
333335
for i := 0; i < msgCount; i++ {
334336
_, err = enq.Enqueue(ctx, user.ID, template, map[string]string{"type": "success", "i": strconv.Itoa(i)}, "test")
335337
require.NoError(t, err)
@@ -343,6 +345,10 @@ func TestInflightDispatchesMetric(t *testing.T) {
343345
return promtest.ToFloat64(metrics.InflightDispatches.WithLabelValues(string(method), template.String())) == msgCount
344346
}, testutil.WaitShort, testutil.IntervalFast)
345347

348+
for i := 0; i < msgCount; i++ {
349+
barrier.wg.Done()
350+
}
351+
346352
// Wait until the handler has dispatched the given notifications.
347353
require.Eventually(t, func() bool {
348354
handler.mu.RLock()
@@ -493,27 +499,30 @@ func (u *updateSignallingInterceptor) BulkMarkNotificationMessagesFailed(ctx con
493499
return u.Store.BulkMarkNotificationMessagesFailed(ctx, arg)
494500
}
495501

496-
type delayingHandler struct {
502+
type barrierHandler struct {
497503
h notifications.Handler
498504

499-
delay time.Duration
505+
wg *sync.WaitGroup
500506
}
501507

502-
func newDelayingHandler(delay time.Duration, handler notifications.Handler) *delayingHandler {
503-
return &delayingHandler{
504-
delay: delay,
505-
h: handler,
508+
func newBarrierHandler(total int, handler notifications.Handler) *barrierHandler {
509+
var wg sync.WaitGroup
510+
wg.Add(total)
511+
512+
return &barrierHandler{
513+
h: handler,
514+
wg: &wg,
506515
}
507516
}
508517

509-
func (d *delayingHandler) Dispatcher(payload types.MessagePayload, title, body string) (dispatch.DeliveryFunc, error) {
510-
deliverFn, err := d.h.Dispatcher(payload, title, body)
518+
func (bh *barrierHandler) Dispatcher(payload types.MessagePayload, title, body string) (dispatch.DeliveryFunc, error) {
519+
deliverFn, err := bh.h.Dispatcher(payload, title, body)
511520
if err != nil {
512521
return nil, err
513522
}
514523

515524
return func(ctx context.Context, msgID uuid.UUID) (retryable bool, err error) {
516-
time.Sleep(d.delay)
525+
bh.wg.Wait()
517526

518527
return deliverFn(ctx, msgID)
519528
}, nil

coderd/notifications/notifications_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -870,9 +870,8 @@ func TestNotificationTemplates_Golden(t *testing.T) {
870870
UserEmail: "bobby@coder.com",
871871
UserUsername: "bobby",
872872
Labels: map[string]string{
873-
"name": "bobby-template",
874-
"display_name": "Bobby's Template",
875-
"initiator": "rob",
873+
"name": "Bobby's Template",
874+
"initiator": "rob",
876875
},
877876
},
878877
},
@@ -886,7 +885,6 @@ func TestNotificationTemplates_Golden(t *testing.T) {
886885
Labels: map[string]string{
887886
"name": "bobby-workspace",
888887
"template_name": "bobby-template",
889-
"template_display_name": "William's Template",
890888
"template_version_name": "bobby-template-version",
891889
"initiator": "joe",
892890
"workspace_owner_username": "mrbobby",

coderd/notifications/testdata/rendered-templates/smtp/TemplateTemplateDeleted.html.golden

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
From: system@coder.com
22
To: bobby@coder.com
3-
Subject: Template "bobby-template" deleted
3+
Subject: Template "Bobby's Template" deleted
44
Message-Id: 02ee4935-73be-4fa1-a290-ff9999026b13@blush-whale-48
55
Date: Fri, 11 Oct 2024 09:03:06 +0000
66
Content-Type: multipart/alternative; boundary=bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4
@@ -12,9 +12,7 @@ Content-Type: text/plain; charset=UTF-8
1212

1313
Hi Bobby,
1414

15-
The template bobby-template was deleted by rob.
16-
17-
The template's display name was Bobby's Template.
15+
The template Bobby's Template was deleted by rob.
1816

1917

2018
View templates: http://test.com/templates
@@ -29,7 +27,7 @@ Content-Type: text/html; charset=UTF-8
2927
<meta charset=3D"UTF-8" />
3028
<meta name=3D"viewport" content=3D"width=3Ddevice-width, initial-scale=
3129
=3D1.0" />
32-
<title>Template "bobby-template" deleted</title>
30+
<title>Template "Bobby's Template" deleted</title>
3331
</head>
3432
<body style=3D"margin: 0; padding: 0; font-family: -apple-system, system-=
3533
ui, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarel=
@@ -44,16 +42,13 @@ er Logo" style=3D"height: 40px;" />
4442
</div>
4543
<h1 style=3D"text-align: center; font-size: 24px; font-weight: 400; m=
4644
argin: 8px 0 32px; line-height: 1.5;">
47-
Template "bobby-template" deleted
45+
Template "Bobby's Template" deleted
4846
</h1>
4947
<div style=3D"line-height: 1.5;">
5048
<p>Hi Bobby,</p>
5149

52-
<p>The template <strong>bobby-template</strong> was deleted by <strong>rob<=
53-
/strong>.</p>
54-
55-
<p>The template&rsquo;s display name was <strong>Bobby&rsquo;s Template</st=
56-
rong>.</p>
50+
<p>The template <strong>Bobby&rsquo;s Template</strong> was deleted by <str=
51+
ong>rob</strong>.</p>
5752
</div>
5853
<div style=3D"text-align: center; margin-top: 32px;">
5954
=20

coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceManualBuildFailed.html.golden

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ Hi Bobby,
1515
A manual build of the workspace bobby-workspace using the template bobby-te=
1616
mplate failed (version: bobby-template-version).
1717

18-
The template's display name was William's Template. The workspace build was=
19-
initiated by joe.
18+
The workspace build was initiated by joe.
2019

2120

2221
View build: http://test.com/@mrbobby/bobby-workspace/builds/3
@@ -55,8 +54,7 @@ argin: 8px 0 32px; line-height: 1.5;">
5554
he template <strong>bobby-template</strong> failed (version: <strong>bobby-=
5655
template-version</strong>).</p>
5756

58-
<p>The template&rsquo;s display name was <strong>William&rsquo;s Template</=
59-
strong>. The workspace build was initiated by <strong>joe</strong>.</p>
57+
<p>The workspace build was initiated by <strong>joe</strong>.</p>
6058
</div>
6159
<div style=3D"text-align: center; margin-top: 32px;">
6260
=20

coderd/notifications/testdata/rendered-templates/webhook/TemplateTemplateDeleted.json.golden

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@
1616
}
1717
],
1818
"labels": {
19-
"display_name": "Bobby's Template",
2019
"initiator": "rob",
21-
"name": "bobby-template"
20+
"name": "Bobby's Template"
2221
},
2322
"data": null
2423
},
25-
"title": "Template \"bobby-template\" deleted",
26-
"title_markdown": "Template \"bobby-template\" deleted",
27-
"body": "Hi Bobby,\n\nThe template bobby-template was deleted by rob.\n\nThe template's display name was Bobby's Template.",
28-
"body_markdown": "Hi Bobby,\n\nThe template **bobby-template** was deleted by **rob**.\n\nThe template's display name was **Bobby's Template**."
24+
"title": "Template \"Bobby's Template\" deleted",
25+
"title_markdown": "Template \"Bobby's Template\" deleted",
26+
"body": "Hi Bobby,\n\nThe template Bobby's Template was deleted by rob.",
27+
"body_markdown": "Hi Bobby,\n\nThe template **Bobby's Template** was deleted by **rob**.\n\n"
2928
}

coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceManualBuildFailed.json.golden

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"labels": {
1919
"initiator": "joe",
2020
"name": "bobby-workspace",
21-
"template_display_name": "William's Template",
2221
"template_name": "bobby-template",
2322
"template_version_name": "bobby-template-version",
2423
"workspace_build_number": "3",
@@ -28,6 +27,6 @@
2827
},
2928
"title": "Workspace \"bobby-workspace\" manual build failed",
3029
"title_markdown": "Workspace \"bobby-workspace\" manual build failed",
31-
"body": "Hi Bobby,\n\nA manual build of the workspace bobby-workspace using the template bobby-template failed (version: bobby-template-version).\n\nThe template's display name was William's Template. The workspace build was initiated by joe.",
32-
"body_markdown": "Hi Bobby,\n\nA manual build of the workspace **bobby-workspace** using the template **bobby-template** failed (version: **bobby-template-version**).\n\nThe template's display name was **William's Template**. The workspace build was initiated by **joe**."
30+
"body": "Hi Bobby,\n\nA manual build of the workspace bobby-workspace using the template bobby-template failed (version: bobby-template-version).\n\nThe workspace build was initiated by joe.",
31+
"body_markdown": "Hi Bobby,\n\nA manual build of the workspace **bobby-workspace** using the template **bobby-template** failed (version: **bobby-template-version**).\n\nThe workspace build was initiated by **joe**."
3332
}

coderd/provisionerdserver/provisionerdserver.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,16 +1124,20 @@ func (s *server) notifyWorkspaceManualBuildFailed(ctx context.Context, workspace
11241124
}
11251125

11261126
for _, templateAdmin := range templateAdmins {
1127+
templateNameLabel := template.DisplayName
1128+
if templateNameLabel == "" {
1129+
templateNameLabel = template.Name
1130+
}
1131+
labels := map[string]string{
1132+
"name": workspace.Name,
1133+
"template_name": templateNameLabel,
1134+
"template_version_name": templateVersion.Name,
1135+
"initiator": build.InitiatorByUsername,
1136+
"workspace_owner_username": workspaceOwner.Username,
1137+
"workspace_build_number": strconv.Itoa(int(build.BuildNumber)),
1138+
}
11271139
if _, err := s.NotificationsEnqueuer.Enqueue(ctx, templateAdmin.ID, notifications.TemplateWorkspaceManualBuildFailed,
1128-
map[string]string{
1129-
"name": workspace.Name,
1130-
"template_name": template.Name,
1131-
"template_display_name": template.DisplayName,
1132-
"template_version_name": templateVersion.Name,
1133-
"initiator": build.InitiatorByUsername,
1134-
"workspace_owner_username": workspaceOwner.Username,
1135-
"workspace_build_number": strconv.Itoa(int(build.BuildNumber)),
1136-
}, "provisionerdserver",
1140+
labels, "provisionerdserver",
11371141
// Associate this notification with all the related entities.
11381142
workspace.ID, workspace.OwnerID, workspace.TemplateID, workspace.OrganizationID,
11391143
); err != nil {

coderd/provisionerdserver/provisionerdserver_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1859,8 +1859,7 @@ func TestNotifications(t *testing.T) {
18591859
assert.Contains(t, notifEnq.Sent[0].Targets, workspace.OrganizationID)
18601860
assert.Contains(t, notifEnq.Sent[0].Targets, user.ID)
18611861
assert.Equal(t, workspace.Name, notifEnq.Sent[0].Labels["name"])
1862-
assert.Equal(t, template.Name, notifEnq.Sent[0].Labels["template_name"])
1863-
assert.Equal(t, template.DisplayName, notifEnq.Sent[0].Labels["template_display_name"])
1862+
assert.Equal(t, template.DisplayName, notifEnq.Sent[0].Labels["template_name"])
18641863
assert.Equal(t, version.Name, notifEnq.Sent[0].Labels["template_version_name"])
18651864
assert.Equal(t, user.Username, notifEnq.Sent[0].Labels["initiator"])
18661865
assert.Equal(t, user.Username, notifEnq.Sent[0].Labels["workspace_owner_username"])

coderd/templates.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,15 @@ func (api *API) notifyTemplateDeleted(ctx context.Context, template database.Tem
135135
return
136136
}
137137

138+
templateNameLabel := template.DisplayName
139+
if templateNameLabel == "" {
140+
templateNameLabel = template.Name
141+
}
142+
138143
if _, err := api.NotificationsEnqueuer.Enqueue(ctx, receiverID, notifications.TemplateTemplateDeleted,
139144
map[string]string{
140-
"name": template.Name,
141-
"display_name": template.DisplayName,
142-
"initiator": initiator.Username,
145+
"name": templateNameLabel,
146+
"initiator": initiator.Username,
143147
}, "api-templates-delete",
144148
// Associate this notification with all the related entities.
145149
template.ID, template.OrganizationID,

0 commit comments

Comments
 (0)