Skip to content

feat: include health severity in reports #10817

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
use model struct for base health summary
  • Loading branch information
mtojek committed Nov 21, 2023
commit e1978f22c240d6e0785730be806d82b0084400a5
5 changes: 2 additions & 3 deletions coderd/healthcheck/accessurl.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ import (

"golang.org/x/xerrors"

"github.com/coder/coder/v2/coderd/healthcheck/model"
"github.com/coder/coder/v2/coderd/util/ptr"
)

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

AccessURL string `json:"access_url"`
Reachable bool `json:"reachable"`
Expand Down
5 changes: 2 additions & 3 deletions coderd/healthcheck/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"golang.org/x/xerrors"

"github.com/coder/coder/v2/coderd/database"
"github.com/coder/coder/v2/coderd/healthcheck/model"
)

const (
Expand All @@ -16,9 +17,7 @@ const (

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

Reachable bool `json:"reachable"`
Latency string `json:"latency"`
Expand Down
28 changes: 8 additions & 20 deletions coderd/healthcheck/derphealth/derp.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"tailscale.com/types/key"
tslogger "tailscale.com/types/logger"

"github.com/coder/coder/v2/coderd/healthcheck/model"
"github.com/coder/coder/v2/coderd/util/ptr"
)

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

const (
SeverityOK Severity = "ok"
SeverityWarning Severity = "warning"
SeverityError Severity = "error"
)

// @typescript-generate Severity
type Severity string

// @typescript-generate Report
type Report struct {
Healthy bool `json:"healthy"`
Severity Severity `json:"severity" enums:"ok,warning,error"`
Warnings []string `json:"warnings"`
model.HealthSummary

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

Expand All @@ -57,9 +47,7 @@ type Report struct {
type RegionReport struct {
mu sync.Mutex

Healthy bool `json:"healthy"`
Severity Severity `json:"severity" enums:"ok,warning,error"`
Warnings []string `json:"warnings"`
model.HealthSummary

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

Healthy bool `json:"healthy"`
Severity Severity `json:"severity" enums:"ok,warning,error"`
Warnings []string `json:"warnings"`
model.HealthSummary

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

Expand Down Expand Up @@ -167,8 +153,10 @@ func (r *RegionReport) Run(ctx context.Context) {
var (
node = node
nodeReport = NodeReport{
Node: node,
Healthy: true,
Node: node,
HealthSummary: model.HealthSummary{
Healthy: true,
},
}
)

Expand Down
5 changes: 5 additions & 0 deletions coderd/healthcheck/derphealth/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package derphealth

// DERP healthcheck is kept in a separate package as it is used by `cli/netcheck.go`,
// which is part of the slim binary. Slim binary can't have dependency on `database`,
// which is used by the database healthcheck.
11 changes: 2 additions & 9 deletions coderd/healthcheck/healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/coder/coder/v2/buildinfo"
"github.com/coder/coder/v2/coderd/healthcheck/derphealth"
"github.com/coder/coder/v2/coderd/healthcheck/model"
"github.com/coder/coder/v2/coderd/util/ptr"
)

Expand All @@ -18,14 +19,6 @@ const (
SectionDatabase string = "Database"
)

const (
SeverityOK Severity = "ok"
SeverityWarning Severity = "warning"
SeverityError Severity = "error"
)

type Severity string

type Checker interface {
DERP(ctx context.Context, opts *derphealth.ReportOptions) derphealth.Report
AccessURL(ctx context.Context, opts *AccessURLReportOptions) AccessURLReport
Expand All @@ -40,7 +33,7 @@ type Report struct {
// Healthy is true if the report returns no errors.
Healthy bool `json:"healthy"`
// Severity indicates the status of Coder health.
Severity Severity `json:"severity" enums:"ok,warning,error"`
Severity model.Severity `json:"severity" enums:"ok,warning,error"`
// FailingSections is a list of sections that have failed their healthcheck.
FailingSections []string `json:"failing_sections"`

Expand Down
16 changes: 16 additions & 0 deletions coderd/healthcheck/model/base.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package model

const (
SeverityOK Severity = "ok"
SeverityWarning Severity = "warning"
SeverityError Severity = "error"
)

// @typescript-generate Severity
type Severity string

type HealthSummary struct {
Healthy bool `json:"healthy"`
Severity Severity `json:"severity" enums:"ok,warning,error"`
Warnings []string `json:"warnings"`
}
6 changes: 3 additions & 3 deletions coderd/healthcheck/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (

"golang.org/x/xerrors"
"nhooyr.io/websocket"

"github.com/coder/coder/v2/coderd/healthcheck/model"
)

type WebsocketReportOptions struct {
Expand All @@ -21,9 +23,7 @@ type WebsocketReportOptions struct {

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

Body string `json:"body"`
Code int `json:"code"`
Expand Down