Skip to content

Commit 6c59dc3

Browse files
committed
Reports
1 parent af2d0dc commit 6c59dc3

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

coderd/healthcheck/derphealth/derp.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ func (r *Report) Run(ctx context.Context, opts *ReportOptions) {
154154

155155
func (r *RegionReport) Run(ctx context.Context) {
156156
r.Healthy = true
157+
r.Severity = health.SeverityOK
157158
r.NodeReports = []*NodeReport{}
158159

159160
wg := &sync.WaitGroup{}
@@ -205,6 +206,13 @@ func (r *RegionReport) Run(ctx context.Context) {
205206
} else if healthyNodes < len(r.Region.Nodes) {
206207
r.Warnings = append(r.Warnings, oneNodeUnhealthy)
207208
}
209+
210+
// Review node reports and select the highest severing.
211+
for _, nodeReport := range r.NodeReports {
212+
if nodeReport.Severity.Value() > r.Severity.Value() {
213+
r.Severity = nodeReport.Severity
214+
}
215+
}
208216
}
209217

210218
func (r *NodeReport) derpURL() *url.URL {

coderd/healthcheck/health/model.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,13 @@ const (
88

99
// @typescript-generate Severity
1010
type Severity string
11+
12+
var severityRank = map[Severity]int{
13+
SeverityOK: 0,
14+
SeverityWarning: 1,
15+
SeverityError: 2,
16+
}
17+
18+
func (s Severity) Value() int {
19+
return severityRank[s]
20+
}

coderd/healthcheck/healthcheck.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,22 @@ func Run(ctx context.Context, opts *ReportOptions) *Report {
154154
}
155155

156156
report.Healthy = len(report.FailingSections) == 0
157+
158+
// Review healthcheck sub-reports.
159+
report.Severity = health.SeverityOK
160+
161+
if report.DERP.Severity.Value() > report.Severity.Value() {
162+
report.Severity = report.DERP.Severity
163+
}
164+
if report.AccessURL.Severity.Value() > report.Severity.Value() {
165+
report.Severity = report.AccessURL.Severity
166+
}
167+
if report.Websocket.Severity.Value() > report.Severity.Value() {
168+
report.Severity = report.Websocket.Severity
169+
}
170+
if report.Database.Severity.Value() > report.Severity.Value() {
171+
report.Severity = report.Database.Severity
172+
}
157173
return &report
158174
}
159175

0 commit comments

Comments
 (0)