Skip to content

Commit 11597b6

Browse files
committed
wire it up
1 parent 3005ac8 commit 11597b6

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

coderd/coderd.go

+22-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,13 @@ type Options struct {
135135
AccessControlStore *atomic.Pointer[dbauthz.AccessControlStore]
136136
// AppSecurityKey is the crypto key used to sign and encrypt tokens related to
137137
// workspace applications. It consists of both a signing and encryption key.
138-
AppSecurityKey workspaceapps.SecurityKey
138+
AppSecurityKey workspaceapps.SecurityKey
139+
140+
// The following two functions are dependencies of HealthcheckFunc but are only implemented
141+
// in enterprise. Stubbing them out here.
142+
FetchWorkspaceProxiesFunc *atomic.Pointer[func(context.Context) (codersdk.RegionsResponse[codersdk.WorkspaceProxy], error)]
143+
UpdateProxyHealthFunc *atomic.Pointer[func(context.Context) error]
144+
139145
HealthcheckFunc func(ctx context.Context, apiKey string) *healthcheck.Report
140146
HealthcheckTimeout time.Duration
141147
HealthcheckRefresh time.Duration
@@ -396,6 +402,15 @@ func New(options *Options) *API {
396402
*options.UpdateCheckOptions,
397403
)
398404
}
405+
406+
if options.FetchWorkspaceProxiesFunc == nil {
407+
options.FetchWorkspaceProxiesFunc = &atomic.Pointer[func(context.Context) (codersdk.RegionsResponse[codersdk.WorkspaceProxy], error)]{}
408+
}
409+
410+
if options.UpdateProxyHealthFunc == nil {
411+
options.UpdateProxyHealthFunc = &atomic.Pointer[func(context.Context) error]{}
412+
}
413+
399414
if options.HealthcheckFunc == nil {
400415
options.HealthcheckFunc = func(ctx context.Context, apiKey string) *healthcheck.Report {
401416
return healthcheck.Run(ctx, &healthcheck.ReportOptions{
@@ -413,9 +428,15 @@ func New(options *Options) *API {
413428
DerpHealth: derphealth.ReportOptions{
414429
DERPMap: api.DERPMap(),
415430
},
431+
WorkspaceProxy: healthcheck.WorkspaceProxyReportOptions{
432+
CurrentVersion: buildinfo.Version(),
433+
FetchWorkspaceProxies: *options.FetchWorkspaceProxiesFunc.Load(),
434+
UpdateProxyHealth: *options.UpdateProxyHealthFunc.Load(),
435+
},
416436
})
417437
}
418438
}
439+
419440
if options.HealthcheckTimeout == 0 {
420441
options.HealthcheckTimeout = 30 * time.Second
421442
}

coderd/healthcheck/workspaceproxy.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ import (
1010
)
1111

1212
type WorkspaceProxyReportOptions struct {
13+
// CurrentVersion is the current server version.
14+
// We pass this in to make it easier to test.
15+
CurrentVersion string
16+
// FetchWorkspaceProxies is a function that returns the available workspace proxies.
17+
FetchWorkspaceProxies func(context.Context) (codersdk.RegionsResponse[codersdk.WorkspaceProxy], error)
1318
// UpdateProxyHealth is a function called when healthcheck is run.
1419
// This would normally be ProxyHealth.ForceUpdate().
1520
// We do this because if someone mashes the healthcheck refresh button
1621
// they would expect up-to-date data.
1722
UpdateProxyHealth func(context.Context) error
18-
// FetchWorkspaceProxies is a function that returns the available workspace proxies.
19-
FetchWorkspaceProxies func(context.Context) (codersdk.RegionsResponse[codersdk.WorkspaceProxy], error)
20-
// CurrentVersion is the current server version.
21-
// We pass this in to make it easier to test.
22-
CurrentVersion string
2323
}
2424

2525
// @typescript-generate Report

enterprise/coderd/coderd.go

+5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"github.com/coder/coder/v2/coderd/httpmw"
3030
"github.com/coder/coder/v2/coderd/rbac"
3131
agplschedule "github.com/coder/coder/v2/coderd/schedule"
32+
"github.com/coder/coder/v2/coderd/util/ptr"
3233
"github.com/coder/coder/v2/codersdk"
3334
"github.com/coder/coder/v2/enterprise/coderd/dbauthz"
3435
"github.com/coder/coder/v2/enterprise/coderd/license"
@@ -374,6 +375,10 @@ func New(ctx context.Context, options *Options) (_ *API, err error) {
374375
// Use proxy health to return the healthy workspace proxy hostnames.
375376
f := api.ProxyHealth.ProxyHosts
376377
api.AGPL.WorkspaceProxyHostsFn.Store(&f)
378+
379+
// Wire this up to healthcheck.
380+
api.AGPL.FetchWorkspaceProxiesFunc.Store(ptr.Ref(api.fetchWorkspaceProxies))
381+
api.AGPL.UpdateProxyHealthFunc.Store(ptr.Ref(api.ProxyHealth.ForceUpdate))
377382
}
378383

379384
err = api.PrometheusRegistry.Register(&api.licenseMetricsCollector)

0 commit comments

Comments
 (0)