Skip to content

Commit 7c70495

Browse files
committed
add to example
1 parent aaabc5a commit 7c70495

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

agent/apphealth.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,18 @@ func NewWorkspaceAppHealthReporter(logger slog.Logger, client *codersdk.Client)
103103
}
104104
}()
105105

106+
copyHealth := func(h1 map[string]codersdk.WorkspaceAppHealth) map[string]codersdk.WorkspaceAppHealth {
107+
h2 := make(map[string]codersdk.WorkspaceAppHealth, 0)
108+
mu.RLock()
109+
for k, v := range h1 {
110+
h2[k] = v
111+
}
112+
mu.RUnlock()
113+
114+
return h2
115+
}
116+
lastHealth := copyHealth(health)
106117
reportTicker := time.NewTicker(time.Second)
107-
lastHealth := make(map[string]codersdk.WorkspaceAppHealth, 0)
108118
for {
109119
select {
110120
case <-ctx.Done():
@@ -114,7 +124,7 @@ func NewWorkspaceAppHealthReporter(logger slog.Logger, client *codersdk.Client)
114124
changed := healthChanged(lastHealth, health)
115125
mu.RUnlock()
116126
if changed {
117-
lastHealth = health
127+
lastHealth = copyHealth(health)
118128
err := client.PostWorkspaceAgentAppHealth(ctx, codersdk.PostWorkspaceAppHealthsRequest{
119129
Healths: health,
120130
})

examples/templates/docker/main.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ resource "coder_app" "code-server" {
4747
name = "code-server"
4848
url = "http://localhost:13337/?folder=/home/coder"
4949
icon = "/icon/code.svg"
50+
healthcheck {
51+
url = "http://localhost:13337/healthz"
52+
interval = 5
53+
threshold = 6
54+
}
5055
}
5156

5257

0 commit comments

Comments
 (0)