Skip to content

Commit 6f4c14d

Browse files
committed
feat: show health warnings
1 parent 177affb commit 6f4c14d

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

coderd/healthcheck/derphealth/derp.go

+14-4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
// @typescript-generate Report
2828
type Report struct {
2929
Healthy bool `json:"healthy"`
30+
Warning bool `json:"warning"`
3031

3132
Regions map[int]*RegionReport `json:"regions"`
3233

@@ -41,6 +42,7 @@ type Report struct {
4142
type RegionReport struct {
4243
mu sync.Mutex
4344
Healthy bool `json:"healthy"`
45+
Warning bool `json:"warning"`
4446

4547
Region *tailcfg.DERPRegion `json:"region"`
4648
NodeReports []*NodeReport `json:"node_reports"`
@@ -53,6 +55,7 @@ type NodeReport struct {
5355
clientCounter int
5456

5557
Healthy bool `json:"healthy"`
58+
Warning bool `json:"warning"`
5659
Node *tailcfg.DERPNode `json:"node"`
5760

5861
ServerInfo derp.ServerInfoMessage `json:"node_info"`
@@ -108,6 +111,9 @@ func (r *Report) Run(ctx context.Context, opts *ReportOptions) {
108111
if !regionReport.Healthy {
109112
r.Healthy = false
110113
}
114+
if regionReport.Warning {
115+
r.Warning = true
116+
}
111117
mu.Unlock()
112118
}()
113119
}
@@ -159,6 +165,9 @@ func (r *RegionReport) Run(ctx context.Context) {
159165
if !nodeReport.Healthy {
160166
r.Healthy = false
161167
}
168+
if nodeReport.Warning {
169+
r.Warning = true
170+
}
162171
r.mu.Unlock()
163172
}()
164173
}
@@ -208,14 +217,15 @@ func (r *NodeReport) Run(ctx context.Context) {
208217

209218
// We can't exchange messages with the node,
210219
if (!r.CanExchangeMessages && !r.Node.STUNOnly) ||
211-
// A node may use websockets because `Upgrade: DERP` may be blocked on
212-
// the load balancer. This is unhealthy because websockets are slower
213-
// than the regular DERP protocol.
214-
r.UsesWebsocket ||
215220
// The node was marked as STUN compatible but the STUN test failed.
216221
r.STUN.Error != nil {
217222
r.Healthy = false
218223
}
224+
225+
// A node may use websockets because `Upgrade: DERP` may be blocked on
226+
// the load balancer. This is unhealthy because websockets are slower
227+
// than the regular DERP protocol.
228+
r.Warning = r.UsesWebsocket
219229
}
220230

221231
func (r *NodeReport) doExchangeMessage(ctx context.Context) {

coderd/healthcheck/healthcheck.go

+5
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ type Report struct {
3636
Time time.Time `json:"time"`
3737
// Healthy is true if the report returns no errors.
3838
Healthy bool `json:"healthy"`
39+
// Warning is true when Coder is operational but its performance might be impacted.
40+
Warning bool `json:"warning"`
3941
// FailingSections is a list of sections that have failed their healthcheck.
4042
FailingSections []string `json:"failing_sections"`
4143

@@ -156,6 +158,9 @@ func Run(ctx context.Context, opts *ReportOptions) *Report {
156158
if !report.DERP.Healthy {
157159
report.FailingSections = append(report.FailingSections, SectionDERP)
158160
}
161+
if report.DERP.Warning {
162+
report.Warning = true
163+
}
159164
if !report.AccessURL.Healthy {
160165
report.FailingSections = append(report.FailingSections, SectionAccessURL)
161166
}

coderd/healthcheck/healthcheck_test.go

+23
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ func TestHealthcheck(t *testing.T) {
4040
name string
4141
checker *testChecker
4242
healthy bool
43+
warning bool
4344
failingSections []string
4445
}{{
4546
name: "OK",
@@ -77,6 +78,26 @@ func TestHealthcheck(t *testing.T) {
7778
},
7879
healthy: false,
7980
failingSections: []string{healthcheck.SectionDERP},
81+
}, {
82+
name: "DERPWarning",
83+
checker: &testChecker{
84+
DERPReport: derphealth.Report{
85+
Healthy: true,
86+
Warning: true,
87+
},
88+
AccessURLReport: healthcheck.AccessURLReport{
89+
Healthy: true,
90+
},
91+
WebsocketReport: healthcheck.WebsocketReport{
92+
Healthy: true,
93+
},
94+
DatabaseReport: healthcheck.DatabaseReport{
95+
Healthy: true,
96+
},
97+
},
98+
healthy: true,
99+
warning: true,
100+
failingSections: nil,
80101
}, {
81102
name: "AccessURLFail",
82103
checker: &testChecker{
@@ -151,8 +172,10 @@ func TestHealthcheck(t *testing.T) {
151172
})
152173

153174
assert.Equal(t, c.healthy, report.Healthy)
175+
assert.Equal(t, c.warning, report.Warning)
154176
assert.Equal(t, c.failingSections, report.FailingSections)
155177
assert.Equal(t, c.checker.DERPReport.Healthy, report.DERP.Healthy)
178+
assert.Equal(t, c.checker.DERPReport.Warning, report.DERP.Warning)
156179
assert.Equal(t, c.checker.AccessURLReport.Healthy, report.AccessURL.Healthy)
157180
assert.Equal(t, c.checker.WebsocketReport.Healthy, report.Websocket.Healthy)
158181
assert.NotZero(t, report.Time)

0 commit comments

Comments
 (0)