|
5 | 5 | "crypto/tls"
|
6 | 6 | "crypto/x509"
|
7 | 7 | "database/sql"
|
| 8 | + "expvar" |
8 | 9 | "flag"
|
9 | 10 | "fmt"
|
10 | 11 | "io"
|
@@ -85,6 +86,8 @@ func init() {
|
85 | 86 | globalHTTPSwaggerHandler = httpSwagger.Handler(httpSwagger.URL("/swagger/doc.json"))
|
86 | 87 | }
|
87 | 88 |
|
| 89 | +var expDERPOnce = sync.Once{} |
| 90 | + |
88 | 91 | // Options are requires parameters for Coder to start.
|
89 | 92 | type Options struct {
|
90 | 93 | AccessURL *url.URL
|
@@ -561,6 +564,16 @@ func New(options *Options) *API {
|
561 | 564 |
|
562 | 565 | derpHandler := derphttp.Handler(api.DERPServer)
|
563 | 566 | 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 | + }) |
564 | 577 | cors := httpmw.Cors(options.DeploymentValues.Dangerous.AllowAllCors.Value())
|
565 | 578 | prometheusMW := httpmw.Prometheus(options.PrometheusRegistry)
|
566 | 579 |
|
@@ -1038,6 +1051,10 @@ func New(options *Options) *API {
|
1038 | 1051 | r.Use(httpmw.ExtractUserParam(options.Database))
|
1039 | 1052 | r.Get("/debug-link", api.userDebugOIDC)
|
1040 | 1053 | })
|
| 1054 | + r.Route("/derp", func(r chi.Router) { |
| 1055 | + r.Get("/traffic", options.DERPServer.ServeDebugTraffic) |
| 1056 | + }) |
| 1057 | + r.Mount("/expvar", expvar.Handler()) // contains DERP metrics as well as cmdline and memstats |
1041 | 1058 | })
|
1042 | 1059 | })
|
1043 | 1060 |
|
|
0 commit comments