Skip to content

Commit 419f8e7

Browse files
committed
Add more healthcheck fields to db schema
1 parent b034b06 commit 419f8e7

File tree

9 files changed

+88
-33
lines changed

9 files changed

+88
-33
lines changed

coderd/database/databasefake/databasefake.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2032,6 +2032,22 @@ func (q *fakeQuerier) InsertWorkspaceApp(_ context.Context, arg database.InsertW
20322032
return workspaceApp, nil
20332033
}
20342034

2035+
func (q *fakeQuerier) UpdateWorkspaceAppHealthByID(_ context.Context, arg database.UpdateWorkspaceAppHealthByIDParams) error {
2036+
q.mutex.Lock()
2037+
defer q.mutex.Unlock()
2038+
2039+
for index, app := range q.workspaceApps {
2040+
if app.ID != arg.ID {
2041+
continue
2042+
}
2043+
app.UpdatedAt = arg.UpdatedAt
2044+
app.Health = arg.Health
2045+
q.workspaceApps[index] = app
2046+
return nil
2047+
}
2048+
return sql.ErrNoRows
2049+
}
2050+
20352051
func (q *fakeQuerier) UpdateAPIKeyByID(_ context.Context, arg database.UpdateAPIKeyByIDParams) error {
20362052
q.mutex.Lock()
20372053
defer q.mutex.Unlock()

coderd/database/dump.sql

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
ALTER TABLE ONLY workspace_apps
2-
DROP COLUMN IF EXISTS health;
2+
DROP COLUMN IF EXISTS updated_at,
3+
DROP COLUMN IF EXISTS healthcheck_enabled,
4+
DROP COLUMN IF EXISTS healthcheck_period,
5+
DROP COLUMN IF EXISTS unhealthy_threshold,
6+
DROP COLUMN IF EXISTS health;
37

48
DROP TYPE workspace_app_health;
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
CREATE TYPE workspace_app_health AS ENUM ('intializing', 'healthy', 'unhealthy');
1+
CREATE TYPE workspace_app_health AS ENUM ('disabled', 'intializing', 'healthy', 'unhealthy');
22

33
ALTER TABLE ONLY workspace_apps
4-
ADD COLUMN IF NOT EXISTS health workspace_app_health NOT NULL DEFAULT 'intializing',
5-
ADD COLUMN IF NOT EXISTS updated_at timestamptz NOT NULL DEFAULT '-infinity';
4+
ADD COLUMN IF NOT EXISTS updated_at timestamptz NOT NULL DEFAULT '-infinity',
5+
ADD COLUMN IF NOT EXISTS healthcheck_enabled boolean NOT NULL DEFAULT FALSE,
6+
ADD COLUMN IF NOT EXISTS healthcheck_period int NOT NULL DEFAULT 0,
7+
ADD COLUMN IF NOT EXISTS unhealthy_threshold int NOT NULL DEFAULT 0,
8+
ADD COLUMN IF NOT EXISTS health workspace_app_health NOT NULL DEFAULT 'disabled';

coderd/database/models.go

Lines changed: 14 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries.sql.go

Lines changed: 25 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/workspaceapps.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,12 +289,20 @@ func (api *API) postWorkspaceAppHealths(rw http.ResponseWriter, r *http.Request)
289289
return
290290
}
291291

292+
if !found.HealthcheckEnabled {
293+
httpapi.Write(rw, http.StatusNotFound, codersdk.Response{
294+
Message: "Error setting workspace app health",
295+
Detail: xerrors.Errorf("health checking is disabled for workspace app %s", name).Error(),
296+
})
297+
return
298+
}
299+
292300
switch health {
293-
case codersdk.WorkspaceAppInitializing:
301+
case codersdk.WorkspaceAppHealthInitializing:
294302
found.Health = database.WorkspaceAppHealthIntializing
295-
case codersdk.WorkspaceAppHealthy:
303+
case codersdk.WorkspaceAppHealthHealthy:
296304
found.Health = database.WorkspaceAppHealthHealthy
297-
case codersdk.WorkspaceAppUnhealthy:
305+
case codersdk.WorkspaceAppHealthUnhealthy:
298306
found.Health = database.WorkspaceAppHealthUnhealthy
299307
default:
300308
httpapi.Write(rw, http.StatusBadRequest, codersdk.Response{

codersdk/workspaceapps.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import (
77
type WorkspaceAppHealth string
88

99
const (
10-
WorkspaceAppInitializing WorkspaceAppHealth = "initializing"
11-
WorkspaceAppHealthy WorkspaceAppHealth = "healthy"
12-
WorkspaceAppUnhealthy WorkspaceAppHealth = "unhealthy"
10+
WorkspaceAppHealthDisabled WorkspaceAppHealth = "disabled"
11+
WorkspaceAppHealthInitializing WorkspaceAppHealth = "initializing"
12+
WorkspaceAppHealthHealthy WorkspaceAppHealth = "healthy"
13+
WorkspaceAppHealthUnhealthy WorkspaceAppHealth = "unhealthy"
1314
)
1415

1516
type WorkspaceApp struct {

site/src/api/typesGenerated.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ export type UserStatus = "active" | "suspended"
745745
export type WorkspaceAgentStatus = "connected" | "connecting" | "disconnected"
746746

747747
// From codersdk/workspaceapps.go
748-
export type WorkspaceAppHealth = "healthy" | "initializing" | "unhealthy"
748+
export type WorkspaceAppHealth = "disabled" | "healthy" | "initializing" | "unhealthy"
749749

750750
// From codersdk/workspacebuilds.go
751751
export type WorkspaceTransition = "delete" | "start" | "stop"

0 commit comments

Comments
 (0)