feat(cli): support bundle: dump healthcheck summary (#12963)

* refactor(codersdk): extract common fields from HealthReport and friends
* feat(codersdk/healthsdk): add Summarize() method
* feat(cli): support bundle: dump healthcheck summary
This commit is contained in:
Cian Johnston
2024-04-16 13:31:56 +01:00
committed by GitHub
parent 06e042acfa
commit 407e61ecd4
13 changed files with 590 additions and 242 deletions

25
coderd/apidoc/docs.go generated
View File

@ -13834,7 +13834,16 @@ const docTemplate = `{
}
},
"severity": {
"$ref": "#/definitions/health.Severity"
"enum": [
"ok",
"warning",
"error"
],
"allOf": [
{
"$ref": "#/definitions/health.Severity"
}
]
},
"warnings": {
"type": "array",
@ -13917,7 +13926,7 @@ const docTemplate = `{
"warnings": {
"type": "array",
"items": {
"type": "string"
"$ref": "#/definitions/health.Message"
}
}
}
@ -13932,10 +13941,20 @@ const docTemplate = `{
"type": "string"
},
"healthy": {
"description": "Healthy is deprecated and left for backward compatibility purposes, use ` + "`" + `Severity` + "`" + ` instead.",
"type": "boolean"
},
"severity": {
"$ref": "#/definitions/health.Severity"
"enum": [
"ok",
"warning",
"error"
],
"allOf": [
{
"$ref": "#/definitions/health.Severity"
}
]
},
"warnings": {
"type": "array",

View File

@ -12574,7 +12574,12 @@
}
},
"severity": {
"$ref": "#/definitions/health.Severity"
"enum": ["ok", "warning", "error"],
"allOf": [
{
"$ref": "#/definitions/health.Severity"
}
]
},
"warnings": {
"type": "array",
@ -12653,7 +12658,7 @@
"warnings": {
"type": "array",
"items": {
"type": "string"
"$ref": "#/definitions/health.Message"
}
}
}
@ -12668,10 +12673,16 @@
"type": "string"
},
"healthy": {
"description": "Healthy is deprecated and left for backward compatibility purposes, use `Severity` instead.",
"type": "boolean"
},
"severity": {
"$ref": "#/definitions/health.Severity"
"enum": ["ok", "warning", "error"],
"allOf": [
{
"$ref": "#/definitions/health.Severity"
}
]
},
"warnings": {
"type": "array",

View File

@ -156,8 +156,8 @@ func (r *RegionReport) Run(ctx context.Context) {
node = node
nodeReport = NodeReport{
DERPNodeReport: healthsdk.DERPNodeReport{
Node: node,
Healthy: true,
Node: node,
},
}
)

View File

@ -58,27 +58,39 @@ func TestHealthcheck(t *testing.T) {
name: "OK",
checker: &testChecker{
DERPReport: healthsdk.DERPHealthReport{
Healthy: true,
Severity: health.SeverityOK,
Healthy: true,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
AccessURLReport: healthsdk.AccessURLReport{
Healthy: true,
Severity: health.SeverityOK,
Healthy: true,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
WebsocketReport: healthsdk.WebsocketReport{
Healthy: true,
Severity: health.SeverityOK,
Healthy: true,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
DatabaseReport: healthsdk.DatabaseReport{
Healthy: true,
Severity: health.SeverityOK,
Healthy: true,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
WorkspaceProxyReport: healthsdk.WorkspaceProxyReport{
Healthy: true,
Severity: health.SeverityOK,
Healthy: true,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
ProvisionerDaemonsReport: healthsdk.ProvisionerDaemonsReport{
Severity: health.SeverityOK,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
},
healthy: true,
@ -88,27 +100,39 @@ func TestHealthcheck(t *testing.T) {
name: "DERPFail",
checker: &testChecker{
DERPReport: healthsdk.DERPHealthReport{
Healthy: false,
Severity: health.SeverityError,
Healthy: false,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityError,
},
},
AccessURLReport: healthsdk.AccessURLReport{
Healthy: true,
Severity: health.SeverityOK,
Healthy: true,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
WebsocketReport: healthsdk.WebsocketReport{
Healthy: true,
Severity: health.SeverityOK,
Healthy: true,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
DatabaseReport: healthsdk.DatabaseReport{
Healthy: true,
Severity: health.SeverityOK,
Healthy: true,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
WorkspaceProxyReport: healthsdk.WorkspaceProxyReport{
Healthy: true,
Severity: health.SeverityOK,
Healthy: true,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
ProvisionerDaemonsReport: healthsdk.ProvisionerDaemonsReport{
Severity: health.SeverityOK,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
},
healthy: false,
@ -118,28 +142,40 @@ func TestHealthcheck(t *testing.T) {
name: "DERPWarning",
checker: &testChecker{
DERPReport: healthsdk.DERPHealthReport{
Healthy: true,
Warnings: []health.Message{{Message: "foobar", Code: "EFOOBAR"}},
Severity: health.SeverityWarning,
Healthy: true,
BaseReport: healthsdk.BaseReport{
Warnings: []health.Message{{Message: "foobar", Code: "EFOOBAR"}},
Severity: health.SeverityWarning,
},
},
AccessURLReport: healthsdk.AccessURLReport{
Healthy: true,
Severity: health.SeverityOK,
Healthy: true,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
WebsocketReport: healthsdk.WebsocketReport{
Healthy: true,
Severity: health.SeverityOK,
Healthy: true,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
DatabaseReport: healthsdk.DatabaseReport{
Healthy: true,
Severity: health.SeverityOK,
Healthy: true,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
WorkspaceProxyReport: healthsdk.WorkspaceProxyReport{
Healthy: true,
Severity: health.SeverityOK,
Healthy: true,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
ProvisionerDaemonsReport: healthsdk.ProvisionerDaemonsReport{
Severity: health.SeverityOK,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
},
healthy: true,
@ -149,27 +185,39 @@ func TestHealthcheck(t *testing.T) {
name: "AccessURLFail",
checker: &testChecker{
DERPReport: healthsdk.DERPHealthReport{
Healthy: true,
Severity: health.SeverityOK,
Healthy: true,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
AccessURLReport: healthsdk.AccessURLReport{
Healthy: false,
Severity: health.SeverityWarning,
Healthy: false,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityWarning,
},
},
WebsocketReport: healthsdk.WebsocketReport{
Healthy: true,
Severity: health.SeverityOK,
Healthy: true,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
DatabaseReport: healthsdk.DatabaseReport{
Healthy: true,
Severity: health.SeverityOK,
Healthy: true,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
WorkspaceProxyReport: healthsdk.WorkspaceProxyReport{
Healthy: true,
Severity: health.SeverityOK,
Healthy: true,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
ProvisionerDaemonsReport: healthsdk.ProvisionerDaemonsReport{
Severity: health.SeverityOK,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
},
healthy: false,
@ -179,27 +227,39 @@ func TestHealthcheck(t *testing.T) {
name: "WebsocketFail",
checker: &testChecker{
DERPReport: healthsdk.DERPHealthReport{
Healthy: true,
Severity: health.SeverityOK,
Healthy: true,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
AccessURLReport: healthsdk.AccessURLReport{
Healthy: true,
Severity: health.SeverityOK,
Healthy: true,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
WebsocketReport: healthsdk.WebsocketReport{
Healthy: false,
Severity: health.SeverityError,
Healthy: false,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityError,
},
},
DatabaseReport: healthsdk.DatabaseReport{
Healthy: true,
Severity: health.SeverityOK,
Healthy: true,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
WorkspaceProxyReport: healthsdk.WorkspaceProxyReport{
Healthy: true,
Severity: health.SeverityOK,
Healthy: true,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
ProvisionerDaemonsReport: healthsdk.ProvisionerDaemonsReport{
Severity: health.SeverityOK,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
},
healthy: false,
@ -209,27 +269,39 @@ func TestHealthcheck(t *testing.T) {
name: "DatabaseFail",
checker: &testChecker{
DERPReport: healthsdk.DERPHealthReport{
Healthy: true,
Severity: health.SeverityOK,
Healthy: true,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
AccessURLReport: healthsdk.AccessURLReport{
Healthy: true,
Severity: health.SeverityOK,
Healthy: true,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
WebsocketReport: healthsdk.WebsocketReport{
Healthy: true,
Severity: health.SeverityOK,
Healthy: true,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
DatabaseReport: healthsdk.DatabaseReport{
Healthy: false,
Severity: health.SeverityError,
Healthy: false,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityError,
},
},
WorkspaceProxyReport: healthsdk.WorkspaceProxyReport{
Healthy: true,
Severity: health.SeverityOK,
Healthy: true,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
ProvisionerDaemonsReport: healthsdk.ProvisionerDaemonsReport{
Severity: health.SeverityOK,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
},
healthy: false,
@ -239,27 +311,39 @@ func TestHealthcheck(t *testing.T) {
name: "ProxyFail",
checker: &testChecker{
DERPReport: healthsdk.DERPHealthReport{
Healthy: true,
Severity: health.SeverityOK,
Healthy: true,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
AccessURLReport: healthsdk.AccessURLReport{
Healthy: true,
Severity: health.SeverityOK,
Healthy: true,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
WebsocketReport: healthsdk.WebsocketReport{
Healthy: true,
Severity: health.SeverityOK,
Healthy: true,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
DatabaseReport: healthsdk.DatabaseReport{
Healthy: true,
Severity: health.SeverityOK,
Healthy: true,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
WorkspaceProxyReport: healthsdk.WorkspaceProxyReport{
Healthy: false,
Severity: health.SeverityError,
Healthy: false,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityError,
},
},
ProvisionerDaemonsReport: healthsdk.ProvisionerDaemonsReport{
Severity: health.SeverityOK,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
},
severity: health.SeverityError,
@ -269,28 +353,40 @@ func TestHealthcheck(t *testing.T) {
name: "ProxyWarn",
checker: &testChecker{
DERPReport: healthsdk.DERPHealthReport{
Healthy: true,
Severity: health.SeverityOK,
Healthy: true,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
AccessURLReport: healthsdk.AccessURLReport{
Healthy: true,
Severity: health.SeverityOK,
Healthy: true,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
WebsocketReport: healthsdk.WebsocketReport{
Healthy: true,
Severity: health.SeverityOK,
Healthy: true,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
DatabaseReport: healthsdk.DatabaseReport{
Healthy: true,
Severity: health.SeverityOK,
Healthy: true,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
WorkspaceProxyReport: healthsdk.WorkspaceProxyReport{
Healthy: true,
Warnings: []health.Message{{Message: "foobar", Code: "EFOOBAR"}},
Severity: health.SeverityWarning,
Healthy: true,
BaseReport: healthsdk.BaseReport{
Warnings: []health.Message{{Message: "foobar", Code: "EFOOBAR"}},
Severity: health.SeverityWarning,
},
},
ProvisionerDaemonsReport: healthsdk.ProvisionerDaemonsReport{
Severity: health.SeverityOK,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
},
severity: health.SeverityWarning,
@ -300,27 +396,39 @@ func TestHealthcheck(t *testing.T) {
name: "ProvisionerDaemonsFail",
checker: &testChecker{
DERPReport: healthsdk.DERPHealthReport{
Healthy: true,
Severity: health.SeverityOK,
Healthy: true,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
AccessURLReport: healthsdk.AccessURLReport{
Healthy: true,
Severity: health.SeverityOK,
Healthy: true,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
WebsocketReport: healthsdk.WebsocketReport{
Healthy: true,
Severity: health.SeverityOK,
Healthy: true,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
DatabaseReport: healthsdk.DatabaseReport{
Healthy: true,
Severity: health.SeverityOK,
Healthy: true,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
WorkspaceProxyReport: healthsdk.WorkspaceProxyReport{
Healthy: true,
Severity: health.SeverityOK,
Healthy: true,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
ProvisionerDaemonsReport: healthsdk.ProvisionerDaemonsReport{
Severity: health.SeverityError,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityError,
},
},
},
severity: health.SeverityError,
@ -330,28 +438,40 @@ func TestHealthcheck(t *testing.T) {
name: "ProvisionerDaemonsWarn",
checker: &testChecker{
DERPReport: healthsdk.DERPHealthReport{
Healthy: true,
Severity: health.SeverityOK,
Healthy: true,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
AccessURLReport: healthsdk.AccessURLReport{
Healthy: true,
Severity: health.SeverityOK,
Healthy: true,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
WebsocketReport: healthsdk.WebsocketReport{
Healthy: true,
Severity: health.SeverityOK,
Healthy: true,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
DatabaseReport: healthsdk.DatabaseReport{
Healthy: true,
Severity: health.SeverityOK,
Healthy: true,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
WorkspaceProxyReport: healthsdk.WorkspaceProxyReport{
Healthy: true,
Severity: health.SeverityOK,
Healthy: true,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityOK,
},
},
ProvisionerDaemonsReport: healthsdk.ProvisionerDaemonsReport{
Severity: health.SeverityWarning,
Warnings: []health.Message{{Message: "foobar", Code: "EFOOBAR"}},
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityWarning,
Warnings: []health.Message{{Message: "foobar", Code: "EFOOBAR"}},
},
},
},
severity: health.SeverityWarning,
@ -362,27 +482,39 @@ func TestHealthcheck(t *testing.T) {
healthy: false,
checker: &testChecker{
DERPReport: healthsdk.DERPHealthReport{
Healthy: false,
Severity: health.SeverityError,
Healthy: false,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityError,
},
},
AccessURLReport: healthsdk.AccessURLReport{
Healthy: false,
Severity: health.SeverityError,
Healthy: false,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityError,
},
},
WebsocketReport: healthsdk.WebsocketReport{
Healthy: false,
Severity: health.SeverityError,
Healthy: false,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityError,
},
},
DatabaseReport: healthsdk.DatabaseReport{
Healthy: false,
Severity: health.SeverityError,
Healthy: false,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityError,
},
},
WorkspaceProxyReport: healthsdk.WorkspaceProxyReport{
Healthy: false,
Severity: health.SeverityError,
Healthy: false,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityError,
},
},
ProvisionerDaemonsReport: healthsdk.ProvisionerDaemonsReport{
Severity: health.SeverityError,
BaseReport: healthsdk.BaseReport{
Severity: health.SeverityError,
},
},
},
severity: health.SeverityError,

View File

@ -31,7 +31,7 @@ func (r *WebsocketReport) Run(ctx context.Context, opts *WebsocketReportOptions)
defer cancel()
r.Severity = health.SeverityOK
r.Warnings = []string{}
r.Warnings = []health.Message{}
r.Dismissed = opts.Dismissed
u, err := opts.AccessURL.Parse("/api/v2/debug/ws")