Skip to content

Commit 38c6470

Browse files
committed
feat(support): add messages from healthcheck to support bundle output
1 parent ca36623 commit 38c6470

File tree

3 files changed

+111
-2
lines changed

3 files changed

+111
-2
lines changed

cli/support.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func (r *RootCmd) supportBundle() *serpent.Command {
101101

102102
// Check if we're running inside a workspace
103103
if val, found := os.LookupEnv("CODER"); found && val == "true" {
104-
_, _ = fmt.Fprintln(inv.Stderr, "Running inside Coder workspace; this can affect results!")
104+
cliui.Warn(inv.Stderr, "Running inside Coder workspace; this can affect results!")
105105
cliLog.Debug(inv.Context(), "running inside coder workspace")
106106
}
107107

@@ -122,7 +122,7 @@ func (r *RootCmd) supportBundle() *serpent.Command {
122122

123123
if len(inv.Args) == 0 {
124124
cliLog.Warn(inv.Context(), "no workspace specified")
125-
_, _ = fmt.Fprintln(inv.Stderr, "Warning: no workspace specified. This will result in incomplete information.")
125+
cliui.Warn(inv.Stderr, "No workspace specified. This will result in incomplete information.")
126126
} else {
127127
ws, err := namedWorkspace(inv.Context(), client, inv.Args[0])
128128
if err != nil {
@@ -184,13 +184,22 @@ func (r *RootCmd) supportBundle() *serpent.Command {
184184
_ = os.Remove(outputPath) // best effort
185185
return xerrors.Errorf("create support bundle: %w", err)
186186
}
187+
msgs := support.Summarize(bun)
188+
if len(msgs) != 0 {
189+
cliui.Warn(inv.Stderr, "Potential issues detected:\n", msgs...)
190+
cliLog.Warn(inv.Context(), "auto-detected issues")
191+
for _, msg := range msgs {
192+
cliLog.Warn(inv.Context(), msg)
193+
}
194+
}
187195
bun.CLILogs = cliLogBuf.Bytes()
188196

189197
if err := writeBundle(bun, zwr); err != nil {
190198
_ = os.Remove(outputPath) // best effort
191199
return xerrors.Errorf("write support bundle to %s: %w", outputPath, err)
192200
}
193201
_, _ = fmt.Fprintln(inv.Stderr, "Wrote support bundle to "+outputPath)
202+
194203
return nil
195204
},
196205
}

support/support.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,3 +520,62 @@ func sanitizeEnv(kvs map[string]string) {
520520
}
521521
}
522522
}
523+
524+
func Summarize(b *Bundle) (msgs []string) {
525+
if b == nil {
526+
return []string{}
527+
}
528+
if b.Network.Netcheck == nil {
529+
msgs = append(msgs, "Netcheck missing from bundle!")
530+
} else {
531+
if b.Network.Netcheck.Error != nil {
532+
msgs = append(msgs, "Client netcheck: "+*b.Network.Netcheck.Error)
533+
}
534+
for _, warn := range b.Network.Netcheck.Warnings {
535+
msgs = append(msgs, "Client netcheck: "+warn.String())
536+
}
537+
}
538+
539+
if b.Deployment.HealthReport == nil {
540+
msgs = append(msgs, "Deployment health check missing from bundle!")
541+
} else {
542+
if b.Deployment.HealthReport.AccessURL.Error != nil {
543+
msgs = append(msgs, "Deployment health: "+*b.Deployment.HealthReport.AccessURL.Error)
544+
}
545+
for _, warn := range b.Deployment.HealthReport.AccessURL.Warnings {
546+
msgs = append(msgs, "Deployment health: "+warn.String())
547+
}
548+
if b.Deployment.HealthReport.DERP.Error != nil {
549+
msgs = append(msgs, "Deployment health: "+*b.Deployment.HealthReport.DERP.Error)
550+
}
551+
for _, warn := range b.Deployment.HealthReport.DERP.Warnings {
552+
msgs = append(msgs, "Deployment health: "+warn.String())
553+
}
554+
if b.Deployment.HealthReport.Database.Error != nil {
555+
msgs = append(msgs, "Deployment health: "+*b.Deployment.HealthReport.Database.Error)
556+
}
557+
for _, warn := range b.Deployment.HealthReport.Database.Warnings {
558+
msgs = append(msgs, "Deployment health: "+warn.String())
559+
}
560+
if b.Deployment.HealthReport.ProvisionerDaemons.Error != nil {
561+
msgs = append(msgs, "Deployment health: "+*b.Deployment.HealthReport.ProvisionerDaemons.Error)
562+
}
563+
for _, warn := range *&b.Deployment.HealthReport.ProvisionerDaemons.Warnings {
564+
msgs = append(msgs, "Deployment health: "+warn.String())
565+
}
566+
if b.Deployment.HealthReport.Websocket.Error != nil {
567+
msgs = append(msgs, "Deployment health: "+*b.Deployment.HealthReport.Websocket.Error)
568+
}
569+
for _, warn := range *&b.Deployment.HealthReport.Websocket.Warnings {
570+
msgs = append(msgs, "Deployment health: "+warn)
571+
}
572+
if b.Deployment.HealthReport.WorkspaceProxy.Error != nil {
573+
msgs = append(msgs, "Deployment health: "+*b.Deployment.HealthReport.WorkspaceProxy.Error)
574+
}
575+
for _, warn := range *&b.Deployment.HealthReport.WorkspaceProxy.Warnings {
576+
msgs = append(msgs, "Deployment health: "+warn.String())
577+
}
578+
}
579+
580+
return msgs
581+
}

support/support_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import (
2323
"github.com/coder/coder/v2/coderd/database"
2424
"github.com/coder/coder/v2/coderd/database/dbfake"
2525
"github.com/coder/coder/v2/coderd/database/dbtime"
26+
"github.com/coder/coder/v2/coderd/healthcheck/derphealth"
27+
"github.com/coder/coder/v2/coderd/healthcheck/health"
2628
"github.com/coder/coder/v2/coderd/util/ptr"
2729
"github.com/coder/coder/v2/codersdk"
2830
"github.com/coder/coder/v2/support"
@@ -245,3 +247,42 @@ func assertNotNilNotEmpty[T any](t *testing.T, v T, msg string) {
245247
assert.NotEmpty(t, v, msg+" but was empty")
246248
}
247249
}
250+
251+
func Test_Summarize(t *testing.T) {
252+
for _, tt := range []struct {
253+
name string
254+
in support.Bundle
255+
expected []string
256+
}{
257+
{
258+
name: "empty",
259+
in: support.Bundle{},
260+
expected: []string{"Netcheck missing from bundle!"},
261+
},
262+
{
263+
name: "network health report",
264+
in: support.Bundle{
265+
Network: support.Network{
266+
Netcheck: &derphealth.Report{
267+
Warnings: []health.Message{
268+
{Code: "TEST", Message: "test"},
269+
},
270+
},
271+
},
272+
},
273+
expected: []string{"TEST: test"},
274+
},
275+
} {
276+
tt := tt
277+
t.Run(tt.name, func(t *testing.T) {
278+
actual := support.Summarize(&tt.in)
279+
if len(tt.expected) == 0 {
280+
assert.Empty(t, actual)
281+
} else {
282+
for _, exp := range tt.expected {
283+
assert.Contains(t, actual, exp)
284+
}
285+
}
286+
})
287+
}
288+
}

0 commit comments

Comments
 (0)