Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6e0b5d4

Browse files
committed
feat: expose DERP server debug metrics
1 parent53c5543 commit6e0b5d4

File tree

5 files changed

+222
-1
lines changed

5 files changed

+222
-1
lines changed

‎coderd/apidoc/docs.go

Lines changed: 82 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/apidoc/swagger.json

Lines changed: 74 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/coderd.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"crypto/tls"
66
"crypto/x509"
77
"database/sql"
8+
"expvar"
89
"flag"
910
"fmt"
1011
"io"
@@ -85,6 +86,8 @@ func init() {
8586
globalHTTPSwaggerHandler=httpSwagger.Handler(httpSwagger.URL("/swagger/doc.json"))
8687
}
8788

89+
varexpDERPOnce= sync.Once{}
90+
8891
// Options are requires parameters for Coder to start.
8992
typeOptionsstruct {
9093
AccessURL*url.URL
@@ -561,6 +564,16 @@ func New(options *Options) *API {
561564

562565
derpHandler:=derphttp.Handler(api.DERPServer)
563566
derpHandler,api.derpCloseFunc=tailnet.WithWebsocketSupport(api.DERPServer,derpHandler)
567+
// Register DERP on expvar HTTP handler, which we serve below in the router, c.f. expvar.Handler()
568+
// These are the metrics the DERP server exposes.
569+
// TODO: export via prometheus
570+
expDERPOnce.Do(func() {
571+
// We need to do this via a global Once because expvar registry is global and panics if we
572+
// register multiple times. In production there is only one Coderd and one DERP server per
573+
// process, but in testing, we create multiple of both, so the Once protects us from
574+
// panicking.
575+
expvar.Publish("derp",api.DERPServer.ExpVar())
576+
})
564577
cors:=httpmw.Cors(options.DeploymentValues.Dangerous.AllowAllCors.Value())
565578
prometheusMW:=httpmw.Prometheus(options.PrometheusRegistry)
566579

@@ -1038,6 +1051,10 @@ func New(options *Options) *API {
10381051
r.Use(httpmw.ExtractUserParam(options.Database))
10391052
r.Get("/debug-link",api.userDebugOIDC)
10401053
})
1054+
r.Route("/derp",func(r chi.Router) {
1055+
r.Get("/traffic",options.DERPServer.ServeDebugTraffic)
1056+
})
1057+
r.Method("GET","/expvar",expvar.Handler())// contains DERP metrics as well as cmdline and memstats
10411058
})
10421059
})
10431060

‎coderd/debug.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ func validateHealthSettings(settings codersdk.HealthSettings) error {
276276
}
277277

278278
// For some reason the swagger docs need to be attached to a function.
279-
//
279+
280280
// @Summary Debug Info Websocket Test
281281
// @ID debug-info-websocket-test
282282
// @Security CoderSessionToken
@@ -287,6 +287,26 @@ func validateHealthSettings(settings codersdk.HealthSettings) error {
287287
// @x-apidocgen {"skip": true}
288288
func_debugws(http.ResponseWriter,*http.Request) {}//nolint:unused
289289

290+
// @Summary Debug DERP traffic
291+
// @ID debug-derp-traffic
292+
// @Security CoderSessionToken
293+
// @Produce json
294+
// @Success 200 {array} derp.BytesSentRecv
295+
// @Tags Debug
296+
// @Router /debug/derp/traffic [get]
297+
// @x-apidocgen {"skip": true}
298+
func_debugDERPTraffic(http.ResponseWriter,*http.Request) {}//nolint:unused
299+
300+
// @Summary Debug expvar
301+
// @ID debug-expvar
302+
// @Security CoderSessionToken
303+
// @Produce json
304+
// @Tags Debug
305+
// @Success 200 {object} map[string]any
306+
// @Router /debug/expvar [get]
307+
// @x-apidocgen {"skip": true}
308+
func_debugExpVar(http.ResponseWriter,*http.Request) {}//nolint:unused
309+
290310
funcloadDismissedHealthchecks(ctx context.Context,db database.Store,logger slog.Logger) []codersdk.HealthSection {
291311
dismissedHealthchecks:= []codersdk.HealthSection{}
292312
settingsJSON,err:=db.GetHealthSettings(ctx)

‎docs/api/schemas.md

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp