Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd0b25cb

Browse files
committed
fix: Use app slugs instead of the display name to report health
All applications without display names were reporting broken health.
1 parent50ad4a8 commitd0b25cb

File tree

5 files changed

+40
-47
lines changed

5 files changed

+40
-47
lines changed

‎agent/apphealth.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88

99
"golang.org/x/xerrors"
1010

11+
"github.com/google/uuid"
12+
1113
"cdr.dev/slog"
1214
"github.com/coder/coder/codersdk"
1315
"github.com/coder/retry"
@@ -31,9 +33,9 @@ func NewWorkspaceAppHealthReporter(logger slog.Logger, apps []codersdk.Workspace
3133
}
3234

3335
hasHealthchecksEnabled:=false
34-
health:=make(map[string]codersdk.WorkspaceAppHealth,0)
36+
health:=make(map[uuid.UUID]codersdk.WorkspaceAppHealth,0)
3537
for_,app:=rangeapps {
36-
health[app.DisplayName]=app.Health
38+
health[app.ID]=app.Health
3739
if!hasHealthchecksEnabled&&app.Health!=codersdk.WorkspaceAppHealthDisabled {
3840
hasHealthchecksEnabled=true
3941
}
@@ -46,7 +48,7 @@ func NewWorkspaceAppHealthReporter(logger slog.Logger, apps []codersdk.Workspace
4648

4749
// run a ticker for each app health check.
4850
varmu sync.RWMutex
49-
failures:=make(map[string]int,0)
51+
failures:=make(map[uuid.UUID]int,0)
5052
for_,nextApp:=rangeapps {
5153
if!shouldStartTicker(nextApp) {
5254
continue
@@ -85,21 +87,21 @@ func NewWorkspaceAppHealthReporter(logger slog.Logger, apps []codersdk.Workspace
8587
}()
8688
iferr!=nil {
8789
mu.Lock()
88-
iffailures[app.DisplayName]<int(app.Healthcheck.Threshold) {
90+
iffailures[app.ID]<int(app.Healthcheck.Threshold) {
8991
// increment the failure count and keep status the same.
9092
// we will change it when we hit the threshold.
91-
failures[app.DisplayName]++
93+
failures[app.ID]++
9294
}else {
9395
// set to unhealthy if we hit the failure threshold.
9496
// we stop incrementing at the threshold to prevent the failure value from increasing forever.
95-
health[app.DisplayName]=codersdk.WorkspaceAppHealthUnhealthy
97+
health[app.ID]=codersdk.WorkspaceAppHealthUnhealthy
9698
}
9799
mu.Unlock()
98100
}else {
99101
mu.Lock()
100102
// we only need one successful health check to be considered healthy.
101-
health[app.DisplayName]=codersdk.WorkspaceAppHealthHealthy
102-
failures[app.DisplayName]=0
103+
health[app.ID]=codersdk.WorkspaceAppHealthHealthy
104+
failures[app.ID]=0
103105
mu.Unlock()
104106
}
105107

@@ -155,7 +157,7 @@ func shouldStartTicker(app codersdk.WorkspaceApp) bool {
155157
returnapp.Healthcheck.URL!=""&&app.Healthcheck.Interval>0&&app.Healthcheck.Threshold>0
156158
}
157159

158-
funchealthChanged(oldmap[string]codersdk.WorkspaceAppHealth,newmap[string]codersdk.WorkspaceAppHealth)bool {
160+
funchealthChanged(oldmap[uuid.UUID]codersdk.WorkspaceAppHealth,newmap[uuid.UUID]codersdk.WorkspaceAppHealth)bool {
159161
forname,newValue:=rangenew {
160162
oldValue,found:=old[name]
161163
if!found {
@@ -169,8 +171,8 @@ func healthChanged(old map[string]codersdk.WorkspaceAppHealth, new map[string]co
169171
returnfalse
170172
}
171173

172-
funccopyHealth(h1map[string]codersdk.WorkspaceAppHealth)map[string]codersdk.WorkspaceAppHealth {
173-
h2:=make(map[string]codersdk.WorkspaceAppHealth,0)
174+
funccopyHealth(h1map[uuid.UUID]codersdk.WorkspaceAppHealth)map[uuid.UUID]codersdk.WorkspaceAppHealth {
175+
h2:=make(map[uuid.UUID]codersdk.WorkspaceAppHealth,0)
174176
fork,v:=rangeh1 {
175177
h2[k]=v
176178
}

‎agent/apphealth_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ func TestAppHealth(t *testing.T) {
2727
defercancel()
2828
apps:= []codersdk.WorkspaceApp{
2929
{
30-
DisplayName:"app1",
30+
Slug:"app1",
3131
Healthcheck: codersdk.Healthcheck{},
3232
Health:codersdk.WorkspaceAppHealthDisabled,
3333
},
3434
{
35-
DisplayName:"app2",
35+
Slug:"app2",
3636
Healthcheck: codersdk.Healthcheck{
3737
// URL: We don't set the URL for this test because the setup will
3838
// create a httptest server for us and set it for us.
@@ -69,7 +69,7 @@ func TestAppHealth(t *testing.T) {
6969
defercancel()
7070
apps:= []codersdk.WorkspaceApp{
7171
{
72-
DisplayName:"app2",
72+
Slug:"app2",
7373
Healthcheck: codersdk.Healthcheck{
7474
// URL: We don't set the URL for this test because the setup will
7575
// create a httptest server for us and set it for us.
@@ -102,7 +102,7 @@ func TestAppHealth(t *testing.T) {
102102
defercancel()
103103
apps:= []codersdk.WorkspaceApp{
104104
{
105-
DisplayName:"app2",
105+
Slug:"app2",
106106
Healthcheck: codersdk.Healthcheck{
107107
// URL: We don't set the URL for this test because the setup will
108108
// create a httptest server for us and set it for us.
@@ -137,7 +137,7 @@ func TestAppHealth(t *testing.T) {
137137
defercancel()
138138
apps:= []codersdk.WorkspaceApp{
139139
{
140-
DisplayName:"app2",
140+
Slug:"app2",
141141
Healthcheck: codersdk.Healthcheck{
142142
// URL: We don't set the URL for this test because the setup will
143143
// create a httptest server for us and set it for us.
@@ -185,9 +185,9 @@ func setupAppReporter(ctx context.Context, t *testing.T, apps []codersdk.Workspa
185185
}
186186
postWorkspaceAgentAppHealth:=func(_ context.Context,req codersdk.PostWorkspaceAppHealthsRequest)error {
187187
mu.Lock()
188-
forname,health:=rangereq.Healths {
188+
forid,health:=rangereq.Healths {
189189
fori,app:=rangeapps {
190-
ifapp.DisplayName!=name {
190+
ifapp.ID!=id {
191191
continue
192192
}
193193
app.Health=health

‎coderd/workspaceagents.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -913,10 +913,10 @@ func (api *API) postWorkspaceAppHealth(rw http.ResponseWriter, r *http.Request)
913913
}
914914

915915
varnewApps []database.WorkspaceApp
916-
forname,newHealth:=rangereq.Healths {
916+
forid,newHealth:=rangereq.Healths {
917917
old:=func()*database.WorkspaceApp {
918918
for_,app:=rangeapps {
919-
ifapp.DisplayName==name {
919+
ifapp.ID==id {
920920
return&app
921921
}
922922
}
@@ -926,15 +926,15 @@ func (api *API) postWorkspaceAppHealth(rw http.ResponseWriter, r *http.Request)
926926
ifold==nil {
927927
httpapi.Write(r.Context(),rw,http.StatusNotFound, codersdk.Response{
928928
Message:"Error setting workspace app health",
929-
Detail:xerrors.Errorf("workspace app name %s not found",name).Error(),
929+
Detail:xerrors.Errorf("workspace app name %s not found",id).Error(),
930930
})
931931
return
932932
}
933933

934934
ifold.HealthcheckUrl=="" {
935935
httpapi.Write(r.Context(),rw,http.StatusNotFound, codersdk.Response{
936936
Message:"Error setting workspace app health",
937-
Detail:xerrors.Errorf("health checking is disabled for workspace app %s",name).Error(),
937+
Detail:xerrors.Errorf("health checking is disabled for workspace app %s",id).Error(),
938938
})
939939
return
940940
}

‎coderd/workspaceagents_test.go

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -555,9 +555,8 @@ func TestWorkspaceAgentListeningPorts(t *testing.T) {
555555
// should not exist in the response.
556556
_,appLPort:=generateUnfilteredPort(t)
557557
app:=&proto.App{
558-
Slug:"test-app",
559-
DisplayName:"test-app",
560-
Url:fmt.Sprintf("http://localhost:%d",appLPort),
558+
Slug:"test-app",
559+
Url:fmt.Sprintf("http://localhost:%d",appLPort),
561560
}
562561

563562
// Generate a filtered port that should not exist in the response.
@@ -624,11 +623,10 @@ func TestWorkspaceAgentAppHealth(t *testing.T) {
624623
authToken:=uuid.NewString()
625624
apps:= []*proto.App{
626625
{
627-
Slug:"code-server",
628-
DisplayName:"code-server",
629-
Command:"some-command",
630-
Url:"http://localhost:3000",
631-
Icon:"/code.svg",
626+
Slug:"code-server",
627+
Command:"some-command",
628+
Url:"http://localhost:3000",
629+
Icon:"/code.svg",
632630
},
633631
{
634632
Slug:"code-server-2",
@@ -683,31 +681,24 @@ func TestWorkspaceAgentAppHealth(t *testing.T) {
683681
// empty
684682
err=agentClient.PostWorkspaceAgentAppHealth(ctx, codersdk.PostWorkspaceAppHealthsRequest{})
685683
require.Error(t,err)
686-
// invalid name
687-
err=agentClient.PostWorkspaceAgentAppHealth(ctx, codersdk.PostWorkspaceAppHealthsRequest{
688-
Healths:map[string]codersdk.WorkspaceAppHealth{
689-
"bad-name":codersdk.WorkspaceAppHealthDisabled,
690-
},
691-
})
692-
require.Error(t,err)
693-
// healcheck disabled
684+
// healthcheck disabled
694685
err=agentClient.PostWorkspaceAgentAppHealth(ctx, codersdk.PostWorkspaceAppHealthsRequest{
695-
Healths:map[string]codersdk.WorkspaceAppHealth{
696-
"code-server":codersdk.WorkspaceAppHealthInitializing,
686+
Healths:map[uuid.UUID]codersdk.WorkspaceAppHealth{
687+
metadata.Apps[0].ID:codersdk.WorkspaceAppHealthInitializing,
697688
},
698689
})
699690
require.Error(t,err)
700691
// invalid value
701692
err=agentClient.PostWorkspaceAgentAppHealth(ctx, codersdk.PostWorkspaceAppHealthsRequest{
702-
Healths:map[string]codersdk.WorkspaceAppHealth{
703-
"code-server-2":codersdk.WorkspaceAppHealth("bad-value"),
693+
Healths:map[uuid.UUID]codersdk.WorkspaceAppHealth{
694+
metadata.Apps[1].ID:codersdk.WorkspaceAppHealth("bad-value"),
704695
},
705696
})
706697
require.Error(t,err)
707698
// update to healthy
708699
err=agentClient.PostWorkspaceAgentAppHealth(ctx, codersdk.PostWorkspaceAppHealthsRequest{
709-
Healths:map[string]codersdk.WorkspaceAppHealth{
710-
"code-server-2":codersdk.WorkspaceAppHealthHealthy,
700+
Healths:map[uuid.UUID]codersdk.WorkspaceAppHealth{
701+
metadata.Apps[1].ID:codersdk.WorkspaceAppHealthHealthy,
711702
},
712703
})
713704
require.NoError(t,err)
@@ -716,8 +707,8 @@ func TestWorkspaceAgentAppHealth(t *testing.T) {
716707
require.EqualValues(t,codersdk.WorkspaceAppHealthHealthy,metadata.Apps[1].Health)
717708
// update to unhealthy
718709
err=agentClient.PostWorkspaceAgentAppHealth(ctx, codersdk.PostWorkspaceAppHealthsRequest{
719-
Healths:map[string]codersdk.WorkspaceAppHealth{
720-
"code-server-2":codersdk.WorkspaceAppHealthUnhealthy,
710+
Healths:map[uuid.UUID]codersdk.WorkspaceAppHealth{
711+
metadata.Apps[1].ID:codersdk.WorkspaceAppHealthUnhealthy,
721712
},
722713
})
723714
require.NoError(t,err)

‎codersdk/workspaceapps.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,5 @@ type Healthcheck struct {
5454
// @typescript-ignore PostWorkspaceAppHealthsRequest
5555
typePostWorkspaceAppHealthsRequeststruct {
5656
// Healths is a map of the workspace app name and the health of the app.
57-
Healthsmap[string]WorkspaceAppHealth
57+
Healthsmap[uuid.UUID]WorkspaceAppHealth
5858
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp