Skip to content

Commit a5e7b2e

Browse files
committed
remove health prefixes from healthsdk
1 parent 9f61acb commit a5e7b2e

File tree

7 files changed

+88
-88
lines changed

7 files changed

+88
-88
lines changed

coderd/database/types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ type AuditOAuthConvertState struct {
2525
}
2626

2727
type HealthSettings struct {
28-
ID uuid.UUID `db:"id" json:"id"`
29-
DismissedHealthchecks []healthsdk.HealthSection `db:"dismissed_healthchecks" json:"dismissed_healthchecks"`
28+
ID uuid.UUID `db:"id" json:"id"`
29+
DismissedHealthchecks []healthsdk.Section `db:"dismissed_healthchecks" json:"dismissed_healthchecks"`
3030
}
3131

3232
type Actions []rbac.Action

coderd/debug.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,19 +106,19 @@ func (api *API) debugDeploymentHealth(rw http.ResponseWriter, r *http.Request) {
106106
}
107107
}
108108

109-
func formatHealthcheck(ctx context.Context, rw http.ResponseWriter, r *http.Request, hc healthsdk.HealthcheckReport, dismissed ...healthsdk.HealthSection) {
109+
func formatHealthcheck(ctx context.Context, rw http.ResponseWriter, r *http.Request, hc healthsdk.HealthcheckReport, dismissed ...healthsdk.Section) {
110110
// Mark any sections previously marked as dismissed.
111111
for _, d := range dismissed {
112112
switch d {
113-
case healthsdk.HealthSectionAccessURL:
113+
case healthsdk.SectionAccessURL:
114114
hc.AccessURL.Dismissed = true
115-
case healthsdk.HealthSectionDERP:
115+
case healthsdk.SectionDERP:
116116
hc.DERP.Dismissed = true
117-
case healthsdk.HealthSectionDatabase:
117+
case healthsdk.SectionDatabase:
118118
hc.Database.Dismissed = true
119-
case healthsdk.HealthSectionWebsocket:
119+
case healthsdk.SectionWebsocket:
120120
hc.Websocket.Dismissed = true
121-
case healthsdk.HealthSectionWorkspaceProxy:
121+
case healthsdk.SectionWorkspaceProxy:
122122
hc.WorkspaceProxy.Dismissed = true
123123
}
124124
}
@@ -164,7 +164,7 @@ func (api *API) deploymentHealthSettings(rw http.ResponseWriter, r *http.Request
164164
return
165165
}
166166

167-
var settings healthsdk.HealthSettings
167+
var settings healthsdk.Settings
168168
err = json.Unmarshal([]byte(settingsJSON), &settings)
169169
if err != nil {
170170
httpapi.Write(r.Context(), rw, http.StatusInternalServerError, codersdk.Response{
@@ -175,7 +175,7 @@ func (api *API) deploymentHealthSettings(rw http.ResponseWriter, r *http.Request
175175
}
176176

177177
if len(settings.DismissedHealthchecks) == 0 {
178-
settings.DismissedHealthchecks = []healthsdk.HealthSection{}
178+
settings.DismissedHealthchecks = []healthsdk.Section{}
179179
}
180180

181181
httpapi.Write(r.Context(), rw, http.StatusOK, settings)
@@ -200,7 +200,7 @@ func (api *API) putDeploymentHealthSettings(rw http.ResponseWriter, r *http.Requ
200200
return
201201
}
202202

203-
var settings healthsdk.HealthSettings
203+
var settings healthsdk.Settings
204204
if !httpapi.Read(ctx, rw, r, &settings) {
205205
return
206206
}
@@ -264,9 +264,9 @@ func (api *API) putDeploymentHealthSettings(rw http.ResponseWriter, r *http.Requ
264264
httpapi.Write(r.Context(), rw, http.StatusOK, settings)
265265
}
266266

267-
func validateHealthSettings(settings healthsdk.HealthSettings) error {
267+
func validateHealthSettings(settings healthsdk.Settings) error {
268268
for _, dismissed := range settings.DismissedHealthchecks {
269-
ok := slices.Contains(healthsdk.HealthSections, dismissed)
269+
ok := slices.Contains(healthsdk.Sections, dismissed)
270270
if !ok {
271271
return xerrors.Errorf("unknown healthcheck section: %s", dismissed)
272272
}
@@ -306,11 +306,11 @@ func _debugDERPTraffic(http.ResponseWriter, *http.Request) {} //nolint:unused
306306
// @x-apidocgen {"skip": true}
307307
func _debugExpVar(http.ResponseWriter, *http.Request) {} //nolint:unused
308308

309-
func loadDismissedHealthchecks(ctx context.Context, db database.Store, logger slog.Logger) []healthsdk.HealthSection {
310-
dismissedHealthchecks := []healthsdk.HealthSection{}
309+
func loadDismissedHealthchecks(ctx context.Context, db database.Store, logger slog.Logger) []healthsdk.Section {
310+
dismissedHealthchecks := []healthsdk.Section{}
311311
settingsJSON, err := db.GetHealthSettings(ctx)
312312
if err == nil {
313-
var settings healthsdk.HealthSettings
313+
var settings healthsdk.Settings
314314
err = json.Unmarshal([]byte(settingsJSON), &settings)
315315
if len(settings.DismissedHealthchecks) > 0 {
316316
dismissedHealthchecks = settings.DismissedHealthchecks

coderd/debug_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,11 @@ func TestHealthSettings(t *testing.T) {
251251
_ = coderdtest.CreateFirstUser(t, adminClient)
252252

253253
// when
254-
settings, err := healthsdk.NewHealthClient(adminClient).HealthSettings(ctx)
254+
settings, err := healthsdk.NewClient(adminClient).Settings(ctx)
255255
require.NoError(t, err)
256256

257257
// then
258-
require.Equal(t, healthsdk.HealthSettings{DismissedHealthchecks: []healthsdk.HealthSection{}}, settings)
258+
require.Equal(t, healthsdk.Settings{DismissedHealthchecks: []healthsdk.Section{}}, settings)
259259
})
260260

261261
t.Run("DismissSection", func(t *testing.T) {
@@ -268,16 +268,16 @@ func TestHealthSettings(t *testing.T) {
268268
adminClient := coderdtest.New(t, nil)
269269
_ = coderdtest.CreateFirstUser(t, adminClient)
270270

271-
expected := healthsdk.HealthSettings{
272-
DismissedHealthchecks: []healthsdk.HealthSection{healthsdk.HealthSectionDERP, healthsdk.HealthSectionWebsocket},
271+
expected := healthsdk.Settings{
272+
DismissedHealthchecks: []healthsdk.Section{healthsdk.SectionDERP, healthsdk.SectionWebsocket},
273273
}
274274

275275
// when: dismiss "derp" and "websocket"
276-
err := healthsdk.NewHealthClient(adminClient).PutHealthSettings(ctx, expected)
276+
err := healthsdk.NewClient(adminClient).PutSettings(ctx, expected)
277277
require.NoError(t, err)
278278

279279
// then
280-
settings, err := healthsdk.NewHealthClient(adminClient).HealthSettings(ctx)
280+
settings, err := healthsdk.NewClient(adminClient).Settings(ctx)
281281
require.NoError(t, err)
282282
require.Equal(t, expected, settings)
283283

@@ -303,23 +303,23 @@ func TestHealthSettings(t *testing.T) {
303303
adminClient := coderdtest.New(t, nil)
304304
_ = coderdtest.CreateFirstUser(t, adminClient)
305305

306-
initial := healthsdk.HealthSettings{
307-
DismissedHealthchecks: []healthsdk.HealthSection{healthsdk.HealthSectionDERP, healthsdk.HealthSectionWebsocket},
306+
initial := healthsdk.Settings{
307+
DismissedHealthchecks: []healthsdk.Section{healthsdk.SectionDERP, healthsdk.SectionWebsocket},
308308
}
309309

310-
err := healthsdk.NewHealthClient(adminClient).PutHealthSettings(ctx, initial)
310+
err := healthsdk.NewClient(adminClient).PutSettings(ctx, initial)
311311
require.NoError(t, err)
312312

313-
expected := healthsdk.HealthSettings{
314-
DismissedHealthchecks: []healthsdk.HealthSection{healthsdk.HealthSectionDERP},
313+
expected := healthsdk.Settings{
314+
DismissedHealthchecks: []healthsdk.Section{healthsdk.SectionDERP},
315315
}
316316

317317
// when: undismiss "websocket"
318-
err = healthsdk.NewHealthClient(adminClient).PutHealthSettings(ctx, expected)
318+
err = healthsdk.NewClient(adminClient).PutSettings(ctx, expected)
319319
require.NoError(t, err)
320320

321321
// then
322-
settings, err := healthsdk.NewHealthClient(adminClient).HealthSettings(ctx)
322+
settings, err := healthsdk.NewClient(adminClient).Settings(ctx)
323323
require.NoError(t, err)
324324
require.Equal(t, expected, settings)
325325

@@ -345,15 +345,15 @@ func TestHealthSettings(t *testing.T) {
345345
adminClient := coderdtest.New(t, nil)
346346
_ = coderdtest.CreateFirstUser(t, adminClient)
347347

348-
expected := healthsdk.HealthSettings{
349-
DismissedHealthchecks: []healthsdk.HealthSection{healthsdk.HealthSectionDERP, healthsdk.HealthSectionWebsocket},
348+
expected := healthsdk.Settings{
349+
DismissedHealthchecks: []healthsdk.Section{healthsdk.SectionDERP, healthsdk.SectionWebsocket},
350350
}
351351

352-
err := healthsdk.NewHealthClient(adminClient).PutHealthSettings(ctx, expected)
352+
err := healthsdk.NewClient(adminClient).PutSettings(ctx, expected)
353353
require.NoError(t, err)
354354

355355
// when
356-
err = healthsdk.NewHealthClient(adminClient).PutHealthSettings(ctx, expected)
356+
err = healthsdk.NewClient(adminClient).PutSettings(ctx, expected)
357357

358358
// then
359359
require.Error(t, err)

coderd/healthcheck/healthcheck.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,24 +156,24 @@ func Run(ctx context.Context, opts *ReportOptions) *healthsdk.HealthcheckReport
156156
wg.Wait()
157157

158158
report.Time = time.Now()
159-
report.FailingSections = []healthsdk.HealthSection{}
159+
report.FailingSections = []healthsdk.Section{}
160160
if report.DERP.Severity.Value() > health.SeverityWarning.Value() {
161-
report.FailingSections = append(report.FailingSections, healthsdk.HealthSectionDERP)
161+
report.FailingSections = append(report.FailingSections, healthsdk.SectionDERP)
162162
}
163163
if report.AccessURL.Severity.Value() > health.SeverityOK.Value() {
164-
report.FailingSections = append(report.FailingSections, healthsdk.HealthSectionAccessURL)
164+
report.FailingSections = append(report.FailingSections, healthsdk.SectionAccessURL)
165165
}
166166
if report.Websocket.Severity.Value() > health.SeverityWarning.Value() {
167-
report.FailingSections = append(report.FailingSections, healthsdk.HealthSectionWebsocket)
167+
report.FailingSections = append(report.FailingSections, healthsdk.SectionWebsocket)
168168
}
169169
if report.Database.Severity.Value() > health.SeverityWarning.Value() {
170-
report.FailingSections = append(report.FailingSections, healthsdk.HealthSectionDatabase)
170+
report.FailingSections = append(report.FailingSections, healthsdk.SectionDatabase)
171171
}
172172
if report.WorkspaceProxy.Severity.Value() > health.SeverityWarning.Value() {
173-
report.FailingSections = append(report.FailingSections, healthsdk.HealthSectionWorkspaceProxy)
173+
report.FailingSections = append(report.FailingSections, healthsdk.SectionWorkspaceProxy)
174174
}
175175
if report.ProvisionerDaemons.Severity.Value() > health.SeverityWarning.Value() {
176-
report.FailingSections = append(report.FailingSections, healthsdk.HealthSectionProvisionerDaemons)
176+
report.FailingSections = append(report.FailingSections, healthsdk.SectionProvisionerDaemons)
177177
}
178178

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

coderd/healthcheck/healthcheck_test.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func TestHealthcheck(t *testing.T) {
5353
checker *testChecker
5454
healthy bool
5555
severity health.Severity
56-
failingSections []healthsdk.HealthSection
56+
failingSections []healthsdk.Section
5757
}{{
5858
name: "OK",
5959
checker: &testChecker{
@@ -83,7 +83,7 @@ func TestHealthcheck(t *testing.T) {
8383
},
8484
healthy: true,
8585
severity: health.SeverityOK,
86-
failingSections: []healthsdk.HealthSection{},
86+
failingSections: []healthsdk.Section{},
8787
}, {
8888
name: "DERPFail",
8989
checker: &testChecker{
@@ -113,7 +113,7 @@ func TestHealthcheck(t *testing.T) {
113113
},
114114
healthy: false,
115115
severity: health.SeverityError,
116-
failingSections: []healthsdk.HealthSection{healthsdk.HealthSectionDERP},
116+
failingSections: []healthsdk.Section{healthsdk.SectionDERP},
117117
}, {
118118
name: "DERPWarning",
119119
checker: &testChecker{
@@ -144,7 +144,7 @@ func TestHealthcheck(t *testing.T) {
144144
},
145145
healthy: true,
146146
severity: health.SeverityWarning,
147-
failingSections: []healthsdk.HealthSection{},
147+
failingSections: []healthsdk.Section{},
148148
}, {
149149
name: "AccessURLFail",
150150
checker: &testChecker{
@@ -174,7 +174,7 @@ func TestHealthcheck(t *testing.T) {
174174
},
175175
healthy: false,
176176
severity: health.SeverityWarning,
177-
failingSections: []healthsdk.HealthSection{healthsdk.HealthSectionAccessURL},
177+
failingSections: []healthsdk.Section{healthsdk.SectionAccessURL},
178178
}, {
179179
name: "WebsocketFail",
180180
checker: &testChecker{
@@ -204,7 +204,7 @@ func TestHealthcheck(t *testing.T) {
204204
},
205205
healthy: false,
206206
severity: health.SeverityError,
207-
failingSections: []healthsdk.HealthSection{healthsdk.HealthSectionWebsocket},
207+
failingSections: []healthsdk.Section{healthsdk.SectionWebsocket},
208208
}, {
209209
name: "DatabaseFail",
210210
checker: &testChecker{
@@ -234,7 +234,7 @@ func TestHealthcheck(t *testing.T) {
234234
},
235235
healthy: false,
236236
severity: health.SeverityError,
237-
failingSections: []healthsdk.HealthSection{healthsdk.HealthSectionDatabase},
237+
failingSections: []healthsdk.Section{healthsdk.SectionDatabase},
238238
}, {
239239
name: "ProxyFail",
240240
checker: &testChecker{
@@ -264,7 +264,7 @@ func TestHealthcheck(t *testing.T) {
264264
},
265265
severity: health.SeverityError,
266266
healthy: false,
267-
failingSections: []healthsdk.HealthSection{healthsdk.HealthSectionWorkspaceProxy},
267+
failingSections: []healthsdk.Section{healthsdk.SectionWorkspaceProxy},
268268
}, {
269269
name: "ProxyWarn",
270270
checker: &testChecker{
@@ -295,7 +295,7 @@ func TestHealthcheck(t *testing.T) {
295295
},
296296
severity: health.SeverityWarning,
297297
healthy: true,
298-
failingSections: []healthsdk.HealthSection{},
298+
failingSections: []healthsdk.Section{},
299299
}, {
300300
name: "ProvisionerDaemonsFail",
301301
checker: &testChecker{
@@ -325,7 +325,7 @@ func TestHealthcheck(t *testing.T) {
325325
},
326326
severity: health.SeverityError,
327327
healthy: false,
328-
failingSections: []healthsdk.HealthSection{healthsdk.HealthSectionProvisionerDaemons},
328+
failingSections: []healthsdk.Section{healthsdk.SectionProvisionerDaemons},
329329
}, {
330330
name: "ProvisionerDaemonsWarn",
331331
checker: &testChecker{
@@ -356,7 +356,7 @@ func TestHealthcheck(t *testing.T) {
356356
},
357357
severity: health.SeverityWarning,
358358
healthy: true,
359-
failingSections: []healthsdk.HealthSection{},
359+
failingSections: []healthsdk.Section{},
360360
}, {
361361
name: "AllFail",
362362
healthy: false,
@@ -386,13 +386,13 @@ func TestHealthcheck(t *testing.T) {
386386
},
387387
},
388388
severity: health.SeverityError,
389-
failingSections: []healthsdk.HealthSection{
390-
healthsdk.HealthSectionDERP,
391-
healthsdk.HealthSectionAccessURL,
392-
healthsdk.HealthSectionWebsocket,
393-
healthsdk.HealthSectionDatabase,
394-
healthsdk.HealthSectionWorkspaceProxy,
395-
healthsdk.HealthSectionProvisionerDaemons,
389+
failingSections: []healthsdk.Section{
390+
healthsdk.SectionDERP,
391+
healthsdk.SectionAccessURL,
392+
healthsdk.SectionWebsocket,
393+
healthsdk.SectionDatabase,
394+
healthsdk.SectionWorkspaceProxy,
395+
healthsdk.SectionProvisionerDaemons,
396396
},
397397
}} {
398398
c := c

0 commit comments

Comments
 (0)