Skip to content

chore(codersdk): move all tailscale imports out of codersdk #12735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Prev Previous commit
Next Next commit
Revert "remove health prefixes from healthsdk"
This reverts commit a5e7b2e.
  • Loading branch information
coadler committed Mar 25, 2024
commit 57a645ca66e1a5204938a3f4fa9e483a460c6c03
4 changes: 2 additions & 2 deletions coderd/database/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ type AuditOAuthConvertState struct {
}

type HealthSettings struct {
ID uuid.UUID `db:"id" json:"id"`
DismissedHealthchecks []healthsdk.Section `db:"dismissed_healthchecks" json:"dismissed_healthchecks"`
ID uuid.UUID `db:"id" json:"id"`
DismissedHealthchecks []healthsdk.HealthSection `db:"dismissed_healthchecks" json:"dismissed_healthchecks"`
}

type Actions []rbac.Action
Expand Down
28 changes: 14 additions & 14 deletions coderd/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,19 @@ func (api *API) debugDeploymentHealth(rw http.ResponseWriter, r *http.Request) {
}
}

func formatHealthcheck(ctx context.Context, rw http.ResponseWriter, r *http.Request, hc healthsdk.HealthcheckReport, dismissed ...healthsdk.Section) {
func formatHealthcheck(ctx context.Context, rw http.ResponseWriter, r *http.Request, hc healthsdk.HealthcheckReport, dismissed ...healthsdk.HealthSection) {
// Mark any sections previously marked as dismissed.
for _, d := range dismissed {
switch d {
case healthsdk.SectionAccessURL:
case healthsdk.HealthSectionAccessURL:
hc.AccessURL.Dismissed = true
case healthsdk.SectionDERP:
case healthsdk.HealthSectionDERP:
hc.DERP.Dismissed = true
case healthsdk.SectionDatabase:
case healthsdk.HealthSectionDatabase:
hc.Database.Dismissed = true
case healthsdk.SectionWebsocket:
case healthsdk.HealthSectionWebsocket:
hc.Websocket.Dismissed = true
case healthsdk.SectionWorkspaceProxy:
case healthsdk.HealthSectionWorkspaceProxy:
hc.WorkspaceProxy.Dismissed = true
}
}
Expand Down Expand Up @@ -164,7 +164,7 @@ func (api *API) deploymentHealthSettings(rw http.ResponseWriter, r *http.Request
return
}

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

if len(settings.DismissedHealthchecks) == 0 {
settings.DismissedHealthchecks = []healthsdk.Section{}
settings.DismissedHealthchecks = []healthsdk.HealthSection{}
}

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

var settings healthsdk.Settings
var settings healthsdk.HealthSettings
if !httpapi.Read(ctx, rw, r, &settings) {
return
}
Expand Down Expand Up @@ -264,9 +264,9 @@ func (api *API) putDeploymentHealthSettings(rw http.ResponseWriter, r *http.Requ
httpapi.Write(r.Context(), rw, http.StatusOK, settings)
}

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

func loadDismissedHealthchecks(ctx context.Context, db database.Store, logger slog.Logger) []healthsdk.Section {
dismissedHealthchecks := []healthsdk.Section{}
func loadDismissedHealthchecks(ctx context.Context, db database.Store, logger slog.Logger) []healthsdk.HealthSection {
dismissedHealthchecks := []healthsdk.HealthSection{}
settingsJSON, err := db.GetHealthSettings(ctx)
if err == nil {
var settings healthsdk.Settings
var settings healthsdk.HealthSettings
err = json.Unmarshal([]byte(settingsJSON), &settings)
if len(settings.DismissedHealthchecks) > 0 {
dismissedHealthchecks = settings.DismissedHealthchecks
Expand Down
34 changes: 17 additions & 17 deletions coderd/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,11 @@ func TestHealthSettings(t *testing.T) {
_ = coderdtest.CreateFirstUser(t, adminClient)

// when
settings, err := healthsdk.NewClient(adminClient).Settings(ctx)
settings, err := healthsdk.NewHealthClient(adminClient).HealthSettings(ctx)
require.NoError(t, err)

// then
require.Equal(t, healthsdk.Settings{DismissedHealthchecks: []healthsdk.Section{}}, settings)
require.Equal(t, healthsdk.HealthSettings{DismissedHealthchecks: []healthsdk.HealthSection{}}, settings)
})

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

expected := healthsdk.Settings{
DismissedHealthchecks: []healthsdk.Section{healthsdk.SectionDERP, healthsdk.SectionWebsocket},
expected := healthsdk.HealthSettings{
DismissedHealthchecks: []healthsdk.HealthSection{healthsdk.HealthSectionDERP, healthsdk.HealthSectionWebsocket},
}

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

// then
settings, err := healthsdk.NewClient(adminClient).Settings(ctx)
settings, err := healthsdk.NewHealthClient(adminClient).HealthSettings(ctx)
require.NoError(t, err)
require.Equal(t, expected, settings)

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

initial := healthsdk.Settings{
DismissedHealthchecks: []healthsdk.Section{healthsdk.SectionDERP, healthsdk.SectionWebsocket},
initial := healthsdk.HealthSettings{
DismissedHealthchecks: []healthsdk.HealthSection{healthsdk.HealthSectionDERP, healthsdk.HealthSectionWebsocket},
}

err := healthsdk.NewClient(adminClient).PutSettings(ctx, initial)
err := healthsdk.NewHealthClient(adminClient).PutHealthSettings(ctx, initial)
require.NoError(t, err)

expected := healthsdk.Settings{
DismissedHealthchecks: []healthsdk.Section{healthsdk.SectionDERP},
expected := healthsdk.HealthSettings{
DismissedHealthchecks: []healthsdk.HealthSection{healthsdk.HealthSectionDERP},
}

// when: undismiss "websocket"
err = healthsdk.NewClient(adminClient).PutSettings(ctx, expected)
err = healthsdk.NewHealthClient(adminClient).PutHealthSettings(ctx, expected)
require.NoError(t, err)

// then
settings, err := healthsdk.NewClient(adminClient).Settings(ctx)
settings, err := healthsdk.NewHealthClient(adminClient).HealthSettings(ctx)
require.NoError(t, err)
require.Equal(t, expected, settings)

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

expected := healthsdk.Settings{
DismissedHealthchecks: []healthsdk.Section{healthsdk.SectionDERP, healthsdk.SectionWebsocket},
expected := healthsdk.HealthSettings{
DismissedHealthchecks: []healthsdk.HealthSection{healthsdk.HealthSectionDERP, healthsdk.HealthSectionWebsocket},
}

err := healthsdk.NewClient(adminClient).PutSettings(ctx, expected)
err := healthsdk.NewHealthClient(adminClient).PutHealthSettings(ctx, expected)
require.NoError(t, err)

// when
err = healthsdk.NewClient(adminClient).PutSettings(ctx, expected)
err = healthsdk.NewHealthClient(adminClient).PutHealthSettings(ctx, expected)

// then
require.Error(t, err)
Expand Down
14 changes: 7 additions & 7 deletions coderd/healthcheck/healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,24 +156,24 @@ func Run(ctx context.Context, opts *ReportOptions) *healthsdk.HealthcheckReport
wg.Wait()

report.Time = time.Now()
report.FailingSections = []healthsdk.Section{}
report.FailingSections = []healthsdk.HealthSection{}
if report.DERP.Severity.Value() > health.SeverityWarning.Value() {
report.FailingSections = append(report.FailingSections, healthsdk.SectionDERP)
report.FailingSections = append(report.FailingSections, healthsdk.HealthSectionDERP)
}
if report.AccessURL.Severity.Value() > health.SeverityOK.Value() {
report.FailingSections = append(report.FailingSections, healthsdk.SectionAccessURL)
report.FailingSections = append(report.FailingSections, healthsdk.HealthSectionAccessURL)
}
if report.Websocket.Severity.Value() > health.SeverityWarning.Value() {
report.FailingSections = append(report.FailingSections, healthsdk.SectionWebsocket)
report.FailingSections = append(report.FailingSections, healthsdk.HealthSectionWebsocket)
}
if report.Database.Severity.Value() > health.SeverityWarning.Value() {
report.FailingSections = append(report.FailingSections, healthsdk.SectionDatabase)
report.FailingSections = append(report.FailingSections, healthsdk.HealthSectionDatabase)
}
if report.WorkspaceProxy.Severity.Value() > health.SeverityWarning.Value() {
report.FailingSections = append(report.FailingSections, healthsdk.SectionWorkspaceProxy)
report.FailingSections = append(report.FailingSections, healthsdk.HealthSectionWorkspaceProxy)
}
if report.ProvisionerDaemons.Severity.Value() > health.SeverityWarning.Value() {
report.FailingSections = append(report.FailingSections, healthsdk.SectionProvisionerDaemons)
report.FailingSections = append(report.FailingSections, healthsdk.HealthSectionProvisionerDaemons)
}

report.Healthy = len(report.FailingSections) == 0
Expand Down
36 changes: 18 additions & 18 deletions coderd/healthcheck/healthcheck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestHealthcheck(t *testing.T) {
checker *testChecker
healthy bool
severity health.Severity
failingSections []healthsdk.Section
failingSections []healthsdk.HealthSection
}{{
name: "OK",
checker: &testChecker{
Expand Down Expand Up @@ -83,7 +83,7 @@ func TestHealthcheck(t *testing.T) {
},
healthy: true,
severity: health.SeverityOK,
failingSections: []healthsdk.Section{},
failingSections: []healthsdk.HealthSection{},
}, {
name: "DERPFail",
checker: &testChecker{
Expand Down Expand Up @@ -113,7 +113,7 @@ func TestHealthcheck(t *testing.T) {
},
healthy: false,
severity: health.SeverityError,
failingSections: []healthsdk.Section{healthsdk.SectionDERP},
failingSections: []healthsdk.HealthSection{healthsdk.HealthSectionDERP},
}, {
name: "DERPWarning",
checker: &testChecker{
Expand Down Expand Up @@ -144,7 +144,7 @@ func TestHealthcheck(t *testing.T) {
},
healthy: true,
severity: health.SeverityWarning,
failingSections: []healthsdk.Section{},
failingSections: []healthsdk.HealthSection{},
}, {
name: "AccessURLFail",
checker: &testChecker{
Expand Down Expand Up @@ -174,7 +174,7 @@ func TestHealthcheck(t *testing.T) {
},
healthy: false,
severity: health.SeverityWarning,
failingSections: []healthsdk.Section{healthsdk.SectionAccessURL},
failingSections: []healthsdk.HealthSection{healthsdk.HealthSectionAccessURL},
}, {
name: "WebsocketFail",
checker: &testChecker{
Expand Down Expand Up @@ -204,7 +204,7 @@ func TestHealthcheck(t *testing.T) {
},
healthy: false,
severity: health.SeverityError,
failingSections: []healthsdk.Section{healthsdk.SectionWebsocket},
failingSections: []healthsdk.HealthSection{healthsdk.HealthSectionWebsocket},
}, {
name: "DatabaseFail",
checker: &testChecker{
Expand Down Expand Up @@ -234,7 +234,7 @@ func TestHealthcheck(t *testing.T) {
},
healthy: false,
severity: health.SeverityError,
failingSections: []healthsdk.Section{healthsdk.SectionDatabase},
failingSections: []healthsdk.HealthSection{healthsdk.HealthSectionDatabase},
}, {
name: "ProxyFail",
checker: &testChecker{
Expand Down Expand Up @@ -264,7 +264,7 @@ func TestHealthcheck(t *testing.T) {
},
severity: health.SeverityError,
healthy: false,
failingSections: []healthsdk.Section{healthsdk.SectionWorkspaceProxy},
failingSections: []healthsdk.HealthSection{healthsdk.HealthSectionWorkspaceProxy},
}, {
name: "ProxyWarn",
checker: &testChecker{
Expand Down Expand Up @@ -295,7 +295,7 @@ func TestHealthcheck(t *testing.T) {
},
severity: health.SeverityWarning,
healthy: true,
failingSections: []healthsdk.Section{},
failingSections: []healthsdk.HealthSection{},
}, {
name: "ProvisionerDaemonsFail",
checker: &testChecker{
Expand Down Expand Up @@ -325,7 +325,7 @@ func TestHealthcheck(t *testing.T) {
},
severity: health.SeverityError,
healthy: false,
failingSections: []healthsdk.Section{healthsdk.SectionProvisionerDaemons},
failingSections: []healthsdk.HealthSection{healthsdk.HealthSectionProvisionerDaemons},
}, {
name: "ProvisionerDaemonsWarn",
checker: &testChecker{
Expand Down Expand Up @@ -356,7 +356,7 @@ func TestHealthcheck(t *testing.T) {
},
severity: health.SeverityWarning,
healthy: true,
failingSections: []healthsdk.Section{},
failingSections: []healthsdk.HealthSection{},
}, {
name: "AllFail",
healthy: false,
Expand Down Expand Up @@ -386,13 +386,13 @@ func TestHealthcheck(t *testing.T) {
},
},
severity: health.SeverityError,
failingSections: []healthsdk.Section{
healthsdk.SectionDERP,
healthsdk.SectionAccessURL,
healthsdk.SectionWebsocket,
healthsdk.SectionDatabase,
healthsdk.SectionWorkspaceProxy,
healthsdk.SectionProvisionerDaemons,
failingSections: []healthsdk.HealthSection{
healthsdk.HealthSectionDERP,
healthsdk.HealthSectionAccessURL,
healthsdk.HealthSectionWebsocket,
healthsdk.HealthSectionDatabase,
healthsdk.HealthSectionWorkspaceProxy,
healthsdk.HealthSectionProvisionerDaemons,
},
}} {
c := c
Expand Down
Loading