Skip to content

Commit e86a518

Browse files
committed
Healthz and buildinfo endpoints
1 parent 1e163d9 commit e86a518

File tree

3 files changed

+40
-16
lines changed

3 files changed

+40
-16
lines changed

coderd/coderd.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ import (
3636
"tailscale.com/util/singleflight"
3737

3838
"cdr.dev/slog"
39-
"github.com/coder/coder/buildinfo"
4039

41-
// Used to serve the Swagger endpoint
40+
"github.com/coder/coder/buildinfo"
4241
_ "github.com/coder/coder/coderd/apidoc"
4342
"github.com/coder/coder/coderd/audit"
4443
"github.com/coder/coder/coderd/awsidentity"
@@ -334,18 +333,18 @@ func New(options *Options) *API {
334333
api.workspaceAppServer = &workspaceapps.Server{
335334
Logger: options.Logger.Named("workspaceapps"),
336335

337-
DashboardURL: api.AccessURL,
338-
AccessURL: api.AccessURL,
339-
Hostname: api.AppHostname,
340-
HostnameRegex: api.AppHostnameRegex,
341-
RealIPConfig: options.RealIPConfig,
336+
DashboardURL: api.AccessURL,
337+
AccessURL: api.AccessURL,
338+
Hostname: api.AppHostname,
339+
HostnameRegex: api.AppHostnameRegex,
340+
RealIPConfig: options.RealIPConfig,
342341

343342
SignedTokenProvider: api.WorkspaceAppsProvider,
344343
WorkspaceConnCache: api.workspaceAgentCache,
345344
AppSecurityKey: options.AppSecurityKey,
346345

347-
DisablePathApps: options.DeploymentValues.DisablePathApps.Value(),
348-
SecureAuthCookie: options.DeploymentValues.SecureAuthCookie.Value(),
346+
DisablePathApps: options.DeploymentValues.DisablePathApps.Value(),
347+
SecureAuthCookie: options.DeploymentValues.SecureAuthCookie.Value(),
349348
}
350349

351350
apiKeyMiddleware := httpmw.ExtractAPIKeyMW(httpmw.ExtractAPIKeyConfig{

codersdk/deployment.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,6 +1538,15 @@ type BuildInfoResponse struct {
15381538
ExternalURL string `json:"external_url"`
15391539
// Version returns the semantic version of the build.
15401540
Version string `json:"version"`
1541+
1542+
WorkspaceProxy *WorkspaceProxyBuildInfo `json:"workspace_proxy,omitempty"`
1543+
}
1544+
1545+
type WorkspaceProxyBuildInfo struct {
1546+
// TODO: @emyrk what should we include here?
1547+
IsWorkspaceProxy bool `json:"is_workspace_proxy"`
1548+
// DashboardURL is the URL of the coderd this proxy is connected to.
1549+
DashboardURL string `json:"dashboard_url"`
15411550
}
15421551

15431552
// CanonicalVersion trims build information from the version.

enterprise/wsproxy/proxy.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"strings"
1010
"time"
1111

12+
"github.com/coder/coder/coderd/httpapi"
13+
1214
"github.com/go-chi/chi/v5"
1315
"github.com/google/uuid"
1416
"github.com/prometheus/client_golang/prometheus"
@@ -57,6 +59,7 @@ type Options struct {
5759

5860
APIRateLimit int
5961
SecureAuthCookie bool
62+
DisablePathApps bool
6063

6164
ProxySessionToken string
6265
}
@@ -156,9 +159,8 @@ func New(opts *Options) (*Server, error) {
156159
WorkspaceConnCache: wsconncache.New(s.DialWorkspaceAgent, 0),
157160
AppSecurityKey: opts.AppSecurityKey,
158161

159-
// TODO: We need to pass some deployment values to here
160-
DisablePathApps: false,
161-
SecureAuthCookie: false,
162+
DisablePathApps: opts.DisablePathApps,
163+
SecureAuthCookie: opts.SecureAuthCookie,
162164
}
163165

164166
// Routes
@@ -173,11 +175,10 @@ func New(opts *Options) (*Server, error) {
173175
httpmw.ExtractRealIP(s.Options.RealIPConfig),
174176
httpmw.Logger(s.Logger),
175177
httpmw.Prometheus(s.PrometheusRegistry),
176-
ExtractSessionTokenMW(),
177178

178179
// SubdomainAppMW is a middleware that handles all requests to the
179180
// subdomain based workspace apps.
180-
s.AppServer.SubdomainAppMW(apiRateLimiter),
181+
s.AppServer.SubdomainAppMW(apiRateLimiter, ExtractSessionTokenMW()),
181182
// Build-Version is helpful for debugging.
182183
func(next http.Handler) http.Handler {
183184
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -202,11 +203,15 @@ func New(opts *Options) (*Server, error) {
202203

203204
// Attach workspace apps routes.
204205
r.Group(func(r chi.Router) {
205-
r.Use(apiRateLimiter)
206+
r.Use(
207+
apiRateLimiter,
208+
ExtractSessionTokenMW(),
209+
)
206210
s.AppServer.Attach(r)
207211
})
208212

209-
// TODO: @emyrk Buildinfo and healthz routes.
213+
r.Get("/buildinfo", s.buildInfo)
214+
r.Get("/healthz", func(w http.ResponseWriter, r *http.Request) { _, _ = w.Write([]byte("OK")) })
210215

211216
return s, nil
212217
}
@@ -220,6 +225,17 @@ func (s *Server) DialWorkspaceAgent(id uuid.UUID) (*codersdk.WorkspaceAgentConn,
220225
return s.SDKClient.DialWorkspaceAgent(s.ctx, id, nil)
221226
}
222227

228+
func (s *Server) buildInfo(rw http.ResponseWriter, r *http.Request) {
229+
httpapi.Write(r.Context(), rw, http.StatusOK, codersdk.BuildInfoResponse{
230+
ExternalURL: buildinfo.ExternalURL(),
231+
Version: buildinfo.Version(),
232+
WorkspaceProxy: &codersdk.WorkspaceProxyBuildInfo{
233+
IsWorkspaceProxy: true,
234+
DashboardURL: s.PrimaryAccessURL.String(),
235+
},
236+
})
237+
}
238+
223239
type optErrors []error
224240

225241
func (e optErrors) Error() string {

0 commit comments

Comments
 (0)