Skip to content

Commit da0749d

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 parent 50ad4a8 commit da0749d

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

agent/apphealth.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func NewWorkspaceAppHealthReporter(logger slog.Logger, apps []codersdk.Workspace
3333
hasHealthchecksEnabled := false
3434
health := make(map[string]codersdk.WorkspaceAppHealth, 0)
3535
for _, app := range apps {
36-
health[app.DisplayName] = app.Health
36+
health[app.Slug] = app.Health
3737
if !hasHealthchecksEnabled && app.Health != codersdk.WorkspaceAppHealthDisabled {
3838
hasHealthchecksEnabled = true
3939
}
@@ -85,21 +85,21 @@ func NewWorkspaceAppHealthReporter(logger slog.Logger, apps []codersdk.Workspace
8585
}()
8686
if err != nil {
8787
mu.Lock()
88-
if failures[app.DisplayName] < int(app.Healthcheck.Threshold) {
88+
if failures[app.Slug] < int(app.Healthcheck.Threshold) {
8989
// increment the failure count and keep status the same.
9090
// we will change it when we hit the threshold.
91-
failures[app.DisplayName]++
91+
failures[app.Slug]++
9292
} else {
9393
// set to unhealthy if we hit the failure threshold.
9494
// we stop incrementing at the threshold to prevent the failure value from increasing forever.
95-
health[app.DisplayName] = codersdk.WorkspaceAppHealthUnhealthy
95+
health[app.Slug] = codersdk.WorkspaceAppHealthUnhealthy
9696
}
9797
mu.Unlock()
9898
} else {
9999
mu.Lock()
100100
// we only need one successful health check to be considered healthy.
101-
health[app.DisplayName] = codersdk.WorkspaceAppHealthHealthy
102-
failures[app.DisplayName] = 0
101+
health[app.Slug] = codersdk.WorkspaceAppHealthHealthy
102+
failures[app.Slug] = 0
103103
mu.Unlock()
104104
}
105105

agent/apphealth_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ func TestAppHealth(t *testing.T) {
2727
defer cancel()
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
defer cancel()
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
defer cancel()
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
defer cancel()
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.
@@ -187,7 +187,7 @@ func setupAppReporter(ctx context.Context, t *testing.T, apps []codersdk.Workspa
187187
mu.Lock()
188188
for name, health := range req.Healths {
189189
for i, app := range apps {
190-
if app.DisplayName != name {
190+
if app.Slug != name {
191191
continue
192192
}
193193
app.Health = health

coderd/workspaceagents.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ func (api *API) postWorkspaceAppHealth(rw http.ResponseWriter, r *http.Request)
916916
for name, newHealth := range req.Healths {
917917
old := func() *database.WorkspaceApp {
918918
for _, app := range apps {
919-
if app.DisplayName == name {
919+
if app.Slug == name {
920920
return &app
921921
}
922922
}

0 commit comments

Comments
 (0)