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
Prev Previous commit
Next Next commit
move health into healthsdk
it imports tailscale
  • Loading branch information
coadler committed Mar 24, 2024
commit 6a8d8713d5e3c0712f1a88c08be3e65d9743f39d
4 changes: 2 additions & 2 deletions cli/netcheck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/coder/coder/v2/cli/clitest"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/coder/v2/codersdk/healthsdk"
"github.com/coder/coder/v2/pty/ptytest"
)

Expand All @@ -27,7 +27,7 @@ func TestNetcheck(t *testing.T) {

b := out.Bytes()
t.Log(string(b))
var report codersdk.DERPHealthReport
var report healthsdk.DERPHealthReport
require.NoError(t, json.Unmarshal(b, &report))

assert.True(t, report.Healthy)
Expand Down
3 changes: 2 additions & 1 deletion cli/support_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/coder/coder/v2/coderd/database/dbtime"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/coder/v2/codersdk/agentsdk"
"github.com/coder/coder/v2/codersdk/healthsdk"
"github.com/coder/coder/v2/codersdk/workspacesdk"
"github.com/coder/coder/v2/provisionersdk/proto"
"github.com/coder/coder/v2/tailnet"
Expand Down Expand Up @@ -156,7 +157,7 @@ func assertBundleContents(t *testing.T, path string, badValues ...string) {
decodeJSONFromZip(t, f, &v)
require.NotEmpty(t, f, v, "experiments should not be empty")
case "deployment/health.json":
var v codersdk.HealthcheckReport
var v healthsdk.HealthcheckReport
decodeJSONFromZip(t, f, &v)
require.NotEmpty(t, v, "health report should not be empty")
case "network/coordinator_debug.html":
Expand Down
12 changes: 6 additions & 6 deletions coderd/coderd.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import (
"tailscale.com/util/singleflight"

"cdr.dev/slog"

agentproto "github.com/coder/coder/v2/agent/proto"
"github.com/coder/coder/v2/buildinfo"
_ "github.com/coder/coder/v2/coderd/apidoc" // Used for swagger docs.
Expand Down Expand Up @@ -70,6 +69,7 @@ import (
"github.com/coder/coder/v2/coderd/workspaceusage"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/coder/v2/codersdk/drpc"
"github.com/coder/coder/v2/codersdk/healthsdk"
"github.com/coder/coder/v2/provisionerd/proto"
"github.com/coder/coder/v2/provisionersdk"
"github.com/coder/coder/v2/site"
Expand Down Expand Up @@ -147,7 +147,7 @@ type Options struct {
// workspace applications. It consists of both a signing and encryption key.
AppSecurityKey workspaceapps.SecurityKey

HealthcheckFunc func(ctx context.Context, apiKey string) *codersdk.HealthcheckReport
HealthcheckFunc func(ctx context.Context, apiKey string) *healthsdk.HealthcheckReport
HealthcheckTimeout time.Duration
HealthcheckRefresh time.Duration
WorkspaceProxiesFetchUpdater *atomic.Pointer[healthcheck.WorkspaceProxiesFetchUpdater]
Expand Down Expand Up @@ -417,7 +417,7 @@ func New(options *Options) *API {
UserQuietHoursScheduleStore: options.UserQuietHoursScheduleStore,
AccessControlStore: options.AccessControlStore,
Experiments: experiments,
healthCheckGroup: &singleflight.Group[string, *codersdk.HealthcheckReport]{},
healthCheckGroup: &singleflight.Group[string, *healthsdk.HealthcheckReport]{},
Acquirer: provisionerdserver.NewAcquirer(
ctx,
options.Logger.Named("acquirer"),
Expand Down Expand Up @@ -456,7 +456,7 @@ func New(options *Options) *API {
}

if options.HealthcheckFunc == nil {
options.HealthcheckFunc = func(ctx context.Context, apiKey string) *codersdk.HealthcheckReport {
options.HealthcheckFunc = func(ctx context.Context, apiKey string) *healthsdk.HealthcheckReport {
// NOTE: dismissed healthchecks are marked in formatHealthcheck.
// Not here, as this result gets cached.
return healthcheck.Run(ctx, &healthcheck.ReportOptions{
Expand Down Expand Up @@ -1201,8 +1201,8 @@ type API struct {
// This is used to gate features that are not yet ready for production.
Experiments codersdk.Experiments

healthCheckGroup *singleflight.Group[string, *codersdk.HealthcheckReport]
healthCheckCache atomic.Pointer[codersdk.HealthcheckReport]
healthCheckGroup *singleflight.Group[string, *healthsdk.HealthcheckReport]
healthCheckCache atomic.Pointer[healthsdk.HealthcheckReport]

statsBatcher *batchstats.Batcher

Expand Down
3 changes: 2 additions & 1 deletion coderd/coderdtest/coderdtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import (
"github.com/coder/coder/v2/codersdk"
"github.com/coder/coder/v2/codersdk/agentsdk"
"github.com/coder/coder/v2/codersdk/drpc"
"github.com/coder/coder/v2/codersdk/healthsdk"
"github.com/coder/coder/v2/cryptorand"
"github.com/coder/coder/v2/provisioner/echo"
"github.com/coder/coder/v2/provisionerd"
Expand Down Expand Up @@ -113,7 +114,7 @@ type Options struct {
TemplateScheduleStore schedule.TemplateScheduleStore
Coordinator tailnet.Coordinator

HealthcheckFunc func(ctx context.Context, apiKey string) *codersdk.HealthcheckReport
HealthcheckFunc func(ctx context.Context, apiKey string) *healthsdk.HealthcheckReport
HealthcheckTimeout time.Duration
HealthcheckRefresh time.Duration

Expand Down
6 changes: 3 additions & 3 deletions coderd/database/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"golang.org/x/xerrors"

"github.com/coder/coder/v2/coderd/rbac"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/coder/v2/codersdk/healthsdk"
)

// AuditOAuthConvertState is never stored in the database. It is stored in a cookie
Expand All @@ -25,8 +25,8 @@ type AuditOAuthConvertState struct {
}

type HealthSettings struct {
ID uuid.UUID `db:"id" json:"id"`
DismissedHealthchecks []codersdk.HealthSection `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
36 changes: 18 additions & 18 deletions coderd/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import (
"golang.org/x/xerrors"

"cdr.dev/slog"

"github.com/coder/coder/v2/coderd/audit"
"github.com/coder/coder/v2/coderd/database"
"github.com/coder/coder/v2/coderd/httpapi"
"github.com/coder/coder/v2/coderd/httpmw"
"github.com/coder/coder/v2/coderd/rbac"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/coder/v2/codersdk/healthsdk"
)

// @Summary Debug Info Wireguard Coordinator
Expand Down Expand Up @@ -50,7 +50,7 @@ func (api *API) debugTailnet(rw http.ResponseWriter, r *http.Request) {
// @Security CoderSessionToken
// @Produce json
// @Tags Debug
// @Success 200 {object} codersdk.HealthcheckReport
// @Success 200 {object} healthsdk.HealthcheckReport
// @Router /debug/health [get]
// @Param force query boolean false "Force a healthcheck to run"
func (api *API) debugDeploymentHealth(rw http.ResponseWriter, r *http.Request) {
Expand All @@ -76,7 +76,7 @@ func (api *API) debugDeploymentHealth(rw http.ResponseWriter, r *http.Request) {
}
}

resChan := api.healthCheckGroup.DoChan("", func() (*codersdk.HealthcheckReport, error) {
resChan := api.healthCheckGroup.DoChan("", func() (*healthsdk.HealthcheckReport, error) {
// Create a new context not tied to the request.
ctx, cancel := context.WithTimeout(context.Background(), api.Options.HealthcheckTimeout)
defer cancel()
Expand Down 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 codersdk.HealthcheckReport, dismissed ...codersdk.HealthSection) {
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 codersdk.HealthSectionAccessURL:
case healthsdk.HealthSectionAccessURL:
hc.AccessURL.Dismissed = true
case codersdk.HealthSectionDERP:
case healthsdk.HealthSectionDERP:
hc.DERP.Dismissed = true
case codersdk.HealthSectionDatabase:
case healthsdk.HealthSectionDatabase:
hc.Database.Dismissed = true
case codersdk.HealthSectionWebsocket:
case healthsdk.HealthSectionWebsocket:
hc.Websocket.Dismissed = true
case codersdk.HealthSectionWorkspaceProxy:
case healthsdk.HealthSectionWorkspaceProxy:
hc.WorkspaceProxy.Dismissed = true
}
}
Expand Down Expand Up @@ -152,7 +152,7 @@ func formatHealthcheck(ctx context.Context, rw http.ResponseWriter, r *http.Requ
// @Security CoderSessionToken
// @Produce json
// @Tags Debug
// @Success 200 {object} codersdk.HealthSettings
// @Success 200 {object} healthsdk.HealthSettings
// @Router /debug/health/settings [get]
func (api *API) deploymentHealthSettings(rw http.ResponseWriter, r *http.Request) {
settingsJSON, err := api.Database.GetHealthSettings(r.Context())
Expand All @@ -164,7 +164,7 @@ func (api *API) deploymentHealthSettings(rw http.ResponseWriter, r *http.Request
return
}

var settings codersdk.HealthSettings
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 = []codersdk.HealthSection{}
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 codersdk.HealthSettings
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 codersdk.HealthSettings) error {
func validateHealthSettings(settings healthsdk.HealthSettings) error {
for _, dismissed := range settings.DismissedHealthchecks {
ok := slices.Contains(codersdk.HealthSections, 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) []codersdk.HealthSection {
dismissedHealthchecks := []codersdk.HealthSection{}
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 codersdk.HealthSettings
var settings healthsdk.HealthSettings
err = json.Unmarshal([]byte(settingsJSON), &settings)
if len(settings.DismissedHealthchecks) > 0 {
dismissedHealthchecks = settings.DismissedHealthchecks
Expand Down
Loading