Skip to content

Commit ae97adf

Browse files
committed
fix: generate typescript types for healthcheck
1 parent b104bb7 commit ae97adf

File tree

12 files changed

+208
-61
lines changed

12 files changed

+208
-61
lines changed

coderd/apidoc/docs.go

+3-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

+3-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/healthcheck/accessurl.go

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/coder/coder/coderd/util/ptr"
1313
)
1414

15+
// @typescript-generate AccessURLReport
1516
type AccessURLReport struct {
1617
AccessURL string `json:"access_url"`
1718
Healthy bool `json:"healthy"`

coderd/healthcheck/database.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ import (
1010
"github.com/coder/coder/coderd/database"
1111
)
1212

13+
// @typescript-generate DatabaseReport
1314
type DatabaseReport struct {
14-
Healthy bool `json:"healthy"`
15-
Reachable bool `json:"reachable"`
16-
Latency time.Duration `json:"latency"`
17-
Error *string `json:"error"`
15+
Healthy bool `json:"healthy"`
16+
Reachable bool `json:"reachable"`
17+
Latency string `json:"latency"`
18+
Error *string `json:"error"`
1819
}
1920

2021
type DatabaseReportOptions struct {
@@ -39,10 +40,11 @@ func (r *DatabaseReport) Run(ctx context.Context, opts *DatabaseReportOptions) {
3940
slices.Sort(pings)
4041

4142
// Take the median ping.
42-
r.Latency = pings[pingCount/2]
43+
latency := pings[pingCount/2]
44+
r.Latency = latency.String()
4345
// Somewhat arbitrary, but if the latency is over 15ms, we consider it
4446
// unhealthy.
45-
if r.Latency < 15*time.Millisecond {
47+
if latency < 15*time.Millisecond {
4648
r.Healthy = true
4749
}
4850
r.Reachable = true

coderd/healthcheck/derp.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/coder/coder/coderd/util/ptr"
2525
)
2626

27+
// @typescript-generate DERPReport
2728
type DERPReport struct {
2829
Healthy bool `json:"healthy"`
2930

@@ -36,6 +37,7 @@ type DERPReport struct {
3637
Error *string `json:"error"`
3738
}
3839

40+
// @typescript-generate DERPRegionReport
3941
type DERPRegionReport struct {
4042
mu sync.Mutex
4143
Healthy bool `json:"healthy"`
@@ -44,6 +46,8 @@ type DERPRegionReport struct {
4446
NodeReports []*DERPNodeReport `json:"node_reports"`
4547
Error *string `json:"error"`
4648
}
49+
50+
// @typescript-generate DERPNodeReport
4751
type DERPNodeReport struct {
4852
mu sync.Mutex
4953
clientCounter int
@@ -62,10 +66,11 @@ type DERPNodeReport struct {
6266
STUN DERPStunReport `json:"stun"`
6367
}
6468

69+
// @typescript-generate DERPStunReport
6570
type DERPStunReport struct {
6671
Enabled bool
6772
CanSTUN bool
68-
Error error
73+
Error *string
6974
}
7075

7176
type DERPReportOptions struct {
@@ -301,20 +306,20 @@ func (r *DERPNodeReport) doSTUNTest(ctx context.Context) {
301306

302307
addr, port, err := r.stunAddr(ctx)
303308
if err != nil {
304-
r.STUN.Error = xerrors.Errorf("get stun addr: %w", err)
309+
r.STUN.Error = convertError(xerrors.Errorf("get stun addr: %w", err))
305310
return
306311
}
307312

308313
// We only create a prober to call ProbeUDP manually.
309314
p, err := prober.DERP(prober.New(), "", time.Second, time.Second, time.Second)
310315
if err != nil {
311-
r.STUN.Error = xerrors.Errorf("create prober: %w", err)
316+
r.STUN.Error = convertError(xerrors.Errorf("create prober: %w", err))
312317
return
313318
}
314319

315320
err = p.ProbeUDP(addr, port)(ctx)
316321
if err != nil {
317-
r.STUN.Error = xerrors.Errorf("probe stun: %w", err)
322+
r.STUN.Error = convertError(xerrors.Errorf("probe stun: %w", err))
318323
return
319324
}
320325

coderd/healthcheck/derp_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func TestDERP(t *testing.T) {
7676

7777
assert.False(t, node.STUN.Enabled)
7878
assert.False(t, node.STUN.CanSTUN)
79-
assert.NoError(t, node.STUN.Error)
79+
assert.Nil(t, node.STUN.Error)
8080
}
8181
}
8282
})
@@ -120,7 +120,7 @@ func TestDERP(t *testing.T) {
120120

121121
assert.True(t, node.STUN.Enabled)
122122
assert.True(t, node.STUN.CanSTUN)
123-
assert.NoError(t, node.STUN.Error)
123+
assert.Nil(t, node.STUN.Error)
124124
}
125125
}
126126
})
@@ -185,7 +185,7 @@ func TestDERP(t *testing.T) {
185185

186186
assert.False(t, node.STUN.Enabled)
187187
assert.False(t, node.STUN.CanSTUN)
188-
assert.NoError(t, node.STUN.Error)
188+
assert.Nil(t, node.STUN.Error)
189189
}
190190
}
191191
})
@@ -227,7 +227,7 @@ func TestDERP(t *testing.T) {
227227

228228
assert.True(t, node.STUN.Enabled)
229229
assert.True(t, node.STUN.CanSTUN)
230-
assert.NoError(t, node.STUN.Error)
230+
assert.Nil(t, node.STUN.Error)
231231
}
232232
}
233233
})

coderd/healthcheck/healthcheck.go

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type Checker interface {
2929
Database(ctx context.Context, opts *DatabaseReportOptions) DatabaseReport
3030
}
3131

32+
// @typescript-generate Report
3233
type Report struct {
3334
// Time is the time the report was generated at.
3435
Time time.Time `json:"time"`

coderd/healthcheck/websocket.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package healthcheck
22

33
import (
44
"context"
5+
"fmt"
56
"io"
67
"net/http"
78
"net/url"
@@ -10,8 +11,6 @@ import (
1011

1112
"golang.org/x/xerrors"
1213
"nhooyr.io/websocket"
13-
14-
"github.com/coder/coder/coderd/httpapi"
1514
)
1615

1716
type WebsocketReportOptions struct {
@@ -20,6 +19,7 @@ type WebsocketReportOptions struct {
2019
HTTPClient *http.Client
2120
}
2221

22+
// @typescript-generate WebsocketReport
2323
type WebsocketReport struct {
2424
Healthy bool `json:"healthy"`
2525
Response WebsocketResponse `json:"response"`
@@ -115,7 +115,8 @@ func (s *WebsocketEchoServer) ServeHTTP(rw http.ResponseWriter, r *http.Request)
115115
ctx := r.Context()
116116
c, err := websocket.Accept(rw, r, &websocket.AcceptOptions{})
117117
if err != nil {
118-
httpapi.Write(ctx, rw, http.StatusBadRequest, "unable to accept: "+err.Error())
118+
rw.WriteHeader(http.StatusBadRequest)
119+
rw.Write([]byte(fmt.Sprint("unable to accept:", err)))
119120
return
120121
}
121122
defer c.Close(websocket.StatusGoingAway, "goodbye")

docs/api/debug.md

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/api/schemas.md

+8-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)