Skip to content

Commit feaa989

Browse files
authored
fix(site/src/api/typesGenerated): generate HealthSection enums (#11049)
Relates to #8971 - Introduces a codersdk.HealthSection enum type - Refactors existing references using strings to use new HealthSection type
1 parent f66e802 commit feaa989

File tree

13 files changed

+149
-73
lines changed

13 files changed

+149
-73
lines changed

coderd/apidoc/docs.go

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

coderd/apidoc/swagger.json

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

coderd/coderd.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -413,25 +413,25 @@ func New(options *Options) *API {
413413
Database: healthcheck.DatabaseReportOptions{
414414
DB: options.Database,
415415
Threshold: options.DeploymentValues.Healthcheck.ThresholdDatabase.Value(),
416-
Dismissed: slices.Contains(dismissedHealthchecks, healthcheck.SectionDatabase),
416+
Dismissed: slices.Contains(dismissedHealthchecks, codersdk.HealthSectionDatabase),
417417
},
418418
Websocket: healthcheck.WebsocketReportOptions{
419419
AccessURL: options.AccessURL,
420420
APIKey: apiKey,
421-
Dismissed: slices.Contains(dismissedHealthchecks, healthcheck.SectionWebsocket),
421+
Dismissed: slices.Contains(dismissedHealthchecks, codersdk.HealthSectionWebsocket),
422422
},
423423
AccessURL: healthcheck.AccessURLReportOptions{
424424
AccessURL: options.AccessURL,
425-
Dismissed: slices.Contains(dismissedHealthchecks, healthcheck.SectionAccessURL),
425+
Dismissed: slices.Contains(dismissedHealthchecks, codersdk.HealthSectionAccessURL),
426426
},
427427
DerpHealth: derphealth.ReportOptions{
428428
DERPMap: api.DERPMap(),
429-
Dismissed: slices.Contains(dismissedHealthchecks, healthcheck.SectionDERP),
429+
Dismissed: slices.Contains(dismissedHealthchecks, codersdk.HealthSectionDERP),
430430
},
431431
WorkspaceProxy: healthcheck.WorkspaceProxyReportOptions{
432432
CurrentVersion: buildinfo.Version(),
433433
WorkspaceProxiesFetchUpdater: *(options.WorkspaceProxiesFetchUpdater).Load(),
434-
Dismissed: slices.Contains(dismissedHealthchecks, healthcheck.SectionWorkspaceProxy),
434+
Dismissed: slices.Contains(dismissedHealthchecks, codersdk.HealthSectionWorkspaceProxy),
435435
},
436436
})
437437
}

coderd/database/types.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"golang.org/x/xerrors"
1010

1111
"github.com/coder/coder/v2/coderd/rbac"
12+
"github.com/coder/coder/v2/codersdk"
1213
)
1314

1415
// AuditOAuthConvertState is never stored in the database. It is stored in a cookie
@@ -24,8 +25,8 @@ type AuditOAuthConvertState struct {
2425
}
2526

2627
type HealthSettings struct {
27-
ID uuid.UUID `db:"id" json:"id"`
28-
DismissedHealthchecks []string `db:"dismissed_healthchecks" json:"dismissed_healthchecks"`
28+
ID uuid.UUID `db:"id" json:"id"`
29+
DismissedHealthchecks []codersdk.HealthSection `db:"dismissed_healthchecks" json:"dismissed_healthchecks"`
2930
}
3031

3132
type Actions []rbac.Action

coderd/debug.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func (api *API) deploymentHealthSettings(rw http.ResponseWriter, r *http.Request
147147
}
148148

149149
if len(settings.DismissedHealthchecks) == 0 {
150-
settings.DismissedHealthchecks = []string{}
150+
settings.DismissedHealthchecks = []codersdk.HealthSection{}
151151
}
152152

153153
httpapi.Write(r.Context(), rw, http.StatusOK, settings)
@@ -218,6 +218,7 @@ func (api *API) putDeploymentHealthSettings(rw http.ResponseWriter, r *http.Requ
218218
Action: database.AuditActionWrite,
219219
})
220220
defer commitAudit()
221+
221222
aReq.New = database.HealthSettings{
222223
ID: uuid.New(),
223224
DismissedHealthchecks: settings.DismissedHealthchecks,
@@ -237,7 +238,7 @@ func (api *API) putDeploymentHealthSettings(rw http.ResponseWriter, r *http.Requ
237238

238239
func validateHealthSettings(settings codersdk.HealthSettings) error {
239240
for _, dismissed := range settings.DismissedHealthchecks {
240-
ok := slices.Contains(healthcheck.Sections, dismissed)
241+
ok := slices.Contains(codersdk.HealthSections, dismissed)
241242
if !ok {
242243
return xerrors.Errorf("unknown healthcheck section: %s", dismissed)
243244
}
@@ -257,8 +258,8 @@ func validateHealthSettings(settings codersdk.HealthSettings) error {
257258
// @x-apidocgen {"skip": true}
258259
func _debugws(http.ResponseWriter, *http.Request) {} //nolint:unused
259260

260-
func loadDismissedHealthchecks(ctx context.Context, db database.Store, logger slog.Logger) []string {
261-
dismissedHealthchecks := []string{}
261+
func loadDismissedHealthchecks(ctx context.Context, db database.Store, logger slog.Logger) []codersdk.HealthSection {
262+
dismissedHealthchecks := []codersdk.HealthSection{}
262263
settingsJSON, err := db.GetHealthSettings(ctx)
263264
if err == nil {
264265
var settings codersdk.HealthSettings

coderd/debug_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ func TestHealthSettings(t *testing.T) {
251251
require.NoError(t, err)
252252

253253
// then
254-
require.Equal(t, codersdk.HealthSettings{DismissedHealthchecks: []string{}}, settings)
254+
require.Equal(t, codersdk.HealthSettings{DismissedHealthchecks: []codersdk.HealthSection{}}, settings)
255255
})
256256

257257
t.Run("DismissSection", func(t *testing.T) {
@@ -265,7 +265,7 @@ func TestHealthSettings(t *testing.T) {
265265
_ = coderdtest.CreateFirstUser(t, adminClient)
266266

267267
expected := codersdk.HealthSettings{
268-
DismissedHealthchecks: []string{healthcheck.SectionDERP, healthcheck.SectionWebsocket},
268+
DismissedHealthchecks: []codersdk.HealthSection{codersdk.HealthSectionDERP, codersdk.HealthSectionWebsocket},
269269
}
270270

271271
// when: dismiss "derp" and "websocket"
@@ -289,14 +289,14 @@ func TestHealthSettings(t *testing.T) {
289289
_ = coderdtest.CreateFirstUser(t, adminClient)
290290

291291
initial := codersdk.HealthSettings{
292-
DismissedHealthchecks: []string{healthcheck.SectionDERP, healthcheck.SectionWebsocket},
292+
DismissedHealthchecks: []codersdk.HealthSection{codersdk.HealthSectionDERP, codersdk.HealthSectionWebsocket},
293293
}
294294

295295
err := adminClient.PutHealthSettings(ctx, initial)
296296
require.NoError(t, err)
297297

298298
expected := codersdk.HealthSettings{
299-
DismissedHealthchecks: []string{healthcheck.SectionDERP},
299+
DismissedHealthchecks: []codersdk.HealthSection{codersdk.HealthSectionDERP},
300300
}
301301

302302
// when: undismiss "websocket"
@@ -320,7 +320,7 @@ func TestHealthSettings(t *testing.T) {
320320
_ = coderdtest.CreateFirstUser(t, adminClient)
321321

322322
expected := codersdk.HealthSettings{
323-
DismissedHealthchecks: []string{healthcheck.SectionDERP, healthcheck.SectionWebsocket},
323+
DismissedHealthchecks: []codersdk.HealthSection{codersdk.HealthSectionDERP, codersdk.HealthSectionWebsocket},
324324
}
325325

326326
err := adminClient.PutHealthSettings(ctx, expected)

coderd/healthcheck/healthcheck.go

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,9 @@ import (
99
"github.com/coder/coder/v2/coderd/healthcheck/derphealth"
1010
"github.com/coder/coder/v2/coderd/healthcheck/health"
1111
"github.com/coder/coder/v2/coderd/util/ptr"
12+
"github.com/coder/coder/v2/codersdk"
1213
)
1314

14-
const (
15-
SectionDERP string = "DERP"
16-
SectionAccessURL string = "AccessURL"
17-
SectionWebsocket string = "Websocket"
18-
SectionDatabase string = "Database"
19-
SectionWorkspaceProxy string = "WorkspaceProxy"
20-
)
21-
22-
var Sections = []string{SectionAccessURL, SectionDatabase, SectionDERP, SectionWebsocket, SectionWorkspaceProxy}
23-
2415
type Checker interface {
2516
DERP(ctx context.Context, opts *derphealth.ReportOptions) derphealth.Report
2617
AccessURL(ctx context.Context, opts *AccessURLReportOptions) AccessURLReport
@@ -39,7 +30,7 @@ type Report struct {
3930
// Severity indicates the status of Coder health.
4031
Severity health.Severity `json:"severity" enums:"ok,warning,error"`
4132
// FailingSections is a list of sections that have failed their healthcheck.
42-
FailingSections []string `json:"failing_sections"`
33+
FailingSections []codersdk.HealthSection `json:"failing_sections"`
4334

4435
DERP derphealth.Report `json:"derp"`
4536
AccessURL AccessURLReport `json:"access_url"`
@@ -162,21 +153,21 @@ func Run(ctx context.Context, opts *ReportOptions) *Report {
162153
wg.Wait()
163154

164155
report.Time = time.Now()
165-
report.FailingSections = []string{}
156+
report.FailingSections = []codersdk.HealthSection{}
166157
if !report.DERP.Healthy {
167-
report.FailingSections = append(report.FailingSections, SectionDERP)
158+
report.FailingSections = append(report.FailingSections, codersdk.HealthSectionDERP)
168159
}
169160
if !report.AccessURL.Healthy {
170-
report.FailingSections = append(report.FailingSections, SectionAccessURL)
161+
report.FailingSections = append(report.FailingSections, codersdk.HealthSectionAccessURL)
171162
}
172163
if !report.Websocket.Healthy {
173-
report.FailingSections = append(report.FailingSections, SectionWebsocket)
164+
report.FailingSections = append(report.FailingSections, codersdk.HealthSectionWebsocket)
174165
}
175166
if !report.Database.Healthy {
176-
report.FailingSections = append(report.FailingSections, SectionDatabase)
167+
report.FailingSections = append(report.FailingSections, codersdk.HealthSectionDatabase)
177168
}
178169
if !report.WorkspaceProxy.Healthy {
179-
report.FailingSections = append(report.FailingSections, SectionWorkspaceProxy)
170+
report.FailingSections = append(report.FailingSections, codersdk.HealthSectionWorkspaceProxy)
180171
}
181172

182173
report.Healthy = len(report.FailingSections) == 0

coderd/healthcheck/healthcheck_test.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/coder/coder/v2/coderd/healthcheck"
1010
"github.com/coder/coder/v2/coderd/healthcheck/derphealth"
1111
"github.com/coder/coder/v2/coderd/healthcheck/health"
12+
"github.com/coder/coder/v2/codersdk"
1213
)
1314

1415
type testChecker struct {
@@ -47,7 +48,7 @@ func TestHealthcheck(t *testing.T) {
4748
checker *testChecker
4849
healthy bool
4950
severity health.Severity
50-
failingSections []string
51+
failingSections []codersdk.HealthSection
5152
}{{
5253
name: "OK",
5354
checker: &testChecker{
@@ -74,7 +75,7 @@ func TestHealthcheck(t *testing.T) {
7475
},
7576
healthy: true,
7677
severity: health.SeverityOK,
77-
failingSections: []string{},
78+
failingSections: []codersdk.HealthSection{},
7879
}, {
7980
name: "DERPFail",
8081
checker: &testChecker{
@@ -101,7 +102,7 @@ func TestHealthcheck(t *testing.T) {
101102
},
102103
healthy: false,
103104
severity: health.SeverityError,
104-
failingSections: []string{healthcheck.SectionDERP},
105+
failingSections: []codersdk.HealthSection{codersdk.HealthSectionDERP},
105106
}, {
106107
name: "DERPWarning",
107108
checker: &testChecker{
@@ -129,7 +130,7 @@ func TestHealthcheck(t *testing.T) {
129130
},
130131
healthy: true,
131132
severity: health.SeverityWarning,
132-
failingSections: []string{},
133+
failingSections: []codersdk.HealthSection{},
133134
}, {
134135
name: "AccessURLFail",
135136
checker: &testChecker{
@@ -156,7 +157,7 @@ func TestHealthcheck(t *testing.T) {
156157
},
157158
healthy: false,
158159
severity: health.SeverityWarning,
159-
failingSections: []string{healthcheck.SectionAccessURL},
160+
failingSections: []codersdk.HealthSection{codersdk.HealthSectionAccessURL},
160161
}, {
161162
name: "WebsocketFail",
162163
checker: &testChecker{
@@ -183,7 +184,7 @@ func TestHealthcheck(t *testing.T) {
183184
},
184185
healthy: false,
185186
severity: health.SeverityError,
186-
failingSections: []string{healthcheck.SectionWebsocket},
187+
failingSections: []codersdk.HealthSection{codersdk.HealthSectionWebsocket},
187188
}, {
188189
name: "DatabaseFail",
189190
checker: &testChecker{
@@ -210,7 +211,7 @@ func TestHealthcheck(t *testing.T) {
210211
},
211212
healthy: false,
212213
severity: health.SeverityError,
213-
failingSections: []string{healthcheck.SectionDatabase},
214+
failingSections: []codersdk.HealthSection{codersdk.HealthSectionDatabase},
214215
}, {
215216
name: "ProxyFail",
216217
checker: &testChecker{
@@ -237,7 +238,7 @@ func TestHealthcheck(t *testing.T) {
237238
},
238239
severity: health.SeverityError,
239240
healthy: false,
240-
failingSections: []string{healthcheck.SectionWorkspaceProxy},
241+
failingSections: []codersdk.HealthSection{codersdk.HealthSectionWorkspaceProxy},
241242
}, {
242243
name: "ProxyWarn",
243244
checker: &testChecker{
@@ -265,7 +266,7 @@ func TestHealthcheck(t *testing.T) {
265266
},
266267
severity: health.SeverityWarning,
267268
healthy: true,
268-
failingSections: []string{},
269+
failingSections: []codersdk.HealthSection{},
269270
}, {
270271
name: "AllFail",
271272
healthy: false,
@@ -292,12 +293,12 @@ func TestHealthcheck(t *testing.T) {
292293
},
293294
},
294295
severity: health.SeverityError,
295-
failingSections: []string{
296-
healthcheck.SectionDERP,
297-
healthcheck.SectionAccessURL,
298-
healthcheck.SectionWebsocket,
299-
healthcheck.SectionDatabase,
300-
healthcheck.SectionWorkspaceProxy,
296+
failingSections: []codersdk.HealthSection{
297+
codersdk.HealthSectionDERP,
298+
codersdk.HealthSectionAccessURL,
299+
codersdk.HealthSectionWebsocket,
300+
codersdk.HealthSectionDatabase,
301+
codersdk.HealthSectionWorkspaceProxy,
301302
},
302303
}} {
303304
c := c

0 commit comments

Comments
 (0)