Skip to content

Commit e1978f2

Browse files
committed
use model struct for base health summary
1 parent 1bcad04 commit e1978f2

File tree

7 files changed

+38
-38
lines changed

7 files changed

+38
-38
lines changed

coderd/healthcheck/accessurl.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@ import (
99

1010
"golang.org/x/xerrors"
1111

12+
"github.com/coder/coder/v2/coderd/healthcheck/model"
1213
"github.com/coder/coder/v2/coderd/util/ptr"
1314
)
1415

1516
// @typescript-generate AccessURLReport
1617
type AccessURLReport struct {
17-
Healthy bool `json:"healthy"`
18-
Severity Severity `json:"severity" enums:"ok,warning,error"`
19-
Warnings []string `json:"warnings"`
18+
model.HealthSummary
2019

2120
AccessURL string `json:"access_url"`
2221
Reachable bool `json:"reachable"`

coderd/healthcheck/database.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"golang.org/x/xerrors"
99

1010
"github.com/coder/coder/v2/coderd/database"
11+
"github.com/coder/coder/v2/coderd/healthcheck/model"
1112
)
1213

1314
const (
@@ -16,9 +17,7 @@ const (
1617

1718
// @typescript-generate DatabaseReport
1819
type DatabaseReport struct {
19-
Healthy bool `json:"healthy"`
20-
Severity Severity `json:"severity" enums:"ok,warning,error"`
21-
Warnings []string `json:"warnings"`
20+
model.HealthSummary
2221

2322
Reachable bool `json:"reachable"`
2423
Latency string `json:"latency"`

coderd/healthcheck/derphealth/derp.go

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"tailscale.com/types/key"
2222
tslogger "tailscale.com/types/logger"
2323

24+
"github.com/coder/coder/v2/coderd/healthcheck/model"
2425
"github.com/coder/coder/v2/coderd/util/ptr"
2526
)
2627

@@ -29,20 +30,9 @@ const (
2930
oneNodeUnhealthy = "Region is operational, but performance might be degraded as one node is unhealthy."
3031
)
3132

32-
const (
33-
SeverityOK Severity = "ok"
34-
SeverityWarning Severity = "warning"
35-
SeverityError Severity = "error"
36-
)
37-
38-
// @typescript-generate Severity
39-
type Severity string
40-
4133
// @typescript-generate Report
4234
type Report struct {
43-
Healthy bool `json:"healthy"`
44-
Severity Severity `json:"severity" enums:"ok,warning,error"`
45-
Warnings []string `json:"warnings"`
35+
model.HealthSummary
4636

4737
Regions map[int]*RegionReport `json:"regions"`
4838

@@ -57,9 +47,7 @@ type Report struct {
5747
type RegionReport struct {
5848
mu sync.Mutex
5949

60-
Healthy bool `json:"healthy"`
61-
Severity Severity `json:"severity" enums:"ok,warning,error"`
62-
Warnings []string `json:"warnings"`
50+
model.HealthSummary
6351

6452
Region *tailcfg.DERPRegion `json:"region"`
6553
NodeReports []*NodeReport `json:"node_reports"`
@@ -71,9 +59,7 @@ type NodeReport struct {
7159
mu sync.Mutex
7260
clientCounter int
7361

74-
Healthy bool `json:"healthy"`
75-
Severity Severity `json:"severity" enums:"ok,warning,error"`
76-
Warnings []string `json:"warnings"`
62+
model.HealthSummary
7763

7864
Node *tailcfg.DERPNode `json:"node"`
7965

@@ -167,8 +153,10 @@ func (r *RegionReport) Run(ctx context.Context) {
167153
var (
168154
node = node
169155
nodeReport = NodeReport{
170-
Node: node,
171-
Healthy: true,
156+
Node: node,
157+
HealthSummary: model.HealthSummary{
158+
Healthy: true,
159+
},
172160
}
173161
)
174162

coderd/healthcheck/derphealth/doc.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package derphealth
2+
3+
// DERP healthcheck is kept in a separate package as it is used by `cli/netcheck.go`,
4+
// which is part of the slim binary. Slim binary can't have dependency on `database`,
5+
// which is used by the database healthcheck.

coderd/healthcheck/healthcheck.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/coder/coder/v2/buildinfo"
1010
"github.com/coder/coder/v2/coderd/healthcheck/derphealth"
11+
"github.com/coder/coder/v2/coderd/healthcheck/model"
1112
"github.com/coder/coder/v2/coderd/util/ptr"
1213
)
1314

@@ -18,14 +19,6 @@ const (
1819
SectionDatabase string = "Database"
1920
)
2021

21-
const (
22-
SeverityOK Severity = "ok"
23-
SeverityWarning Severity = "warning"
24-
SeverityError Severity = "error"
25-
)
26-
27-
type Severity string
28-
2922
type Checker interface {
3023
DERP(ctx context.Context, opts *derphealth.ReportOptions) derphealth.Report
3124
AccessURL(ctx context.Context, opts *AccessURLReportOptions) AccessURLReport
@@ -40,7 +33,7 @@ type Report struct {
4033
// Healthy is true if the report returns no errors.
4134
Healthy bool `json:"healthy"`
4235
// Severity indicates the status of Coder health.
43-
Severity Severity `json:"severity" enums:"ok,warning,error"`
36+
Severity model.Severity `json:"severity" enums:"ok,warning,error"`
4437
// FailingSections is a list of sections that have failed their healthcheck.
4538
FailingSections []string `json:"failing_sections"`
4639

coderd/healthcheck/model/base.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package model
2+
3+
const (
4+
SeverityOK Severity = "ok"
5+
SeverityWarning Severity = "warning"
6+
SeverityError Severity = "error"
7+
)
8+
9+
// @typescript-generate Severity
10+
type Severity string
11+
12+
type HealthSummary struct {
13+
Healthy bool `json:"healthy"`
14+
Severity Severity `json:"severity" enums:"ok,warning,error"`
15+
Warnings []string `json:"warnings"`
16+
}

coderd/healthcheck/websocket.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111

1212
"golang.org/x/xerrors"
1313
"nhooyr.io/websocket"
14+
15+
"github.com/coder/coder/v2/coderd/healthcheck/model"
1416
)
1517

1618
type WebsocketReportOptions struct {
@@ -21,9 +23,7 @@ type WebsocketReportOptions struct {
2123

2224
// @typescript-generate WebsocketReport
2325
type WebsocketReport struct {
24-
Healthy bool `json:"healthy"`
25-
Severity Severity `json:"severity" enums:"ok,warning,error"`
26-
Warnings []string `json:"warnings"`
26+
model.HealthSummary
2727

2828
Body string `json:"body"`
2929
Code int `json:"code"`

0 commit comments

Comments
 (0)