Skip to content

feat(coderd/healthcheck): improve detection of STUN issues #12951

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 13 commits into from
Apr 15, 2024
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
feat(support): add messages from healthcheck to support bundle output
  • Loading branch information
johnstcn committed Apr 12, 2024
commit 38c6470fbb2746c16f0e5d166672be87a7f8b0b0
13 changes: 11 additions & 2 deletions cli/support.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (r *RootCmd) supportBundle() *serpent.Command {

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

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

if len(inv.Args) == 0 {
cliLog.Warn(inv.Context(), "no workspace specified")
_, _ = fmt.Fprintln(inv.Stderr, "Warning: no workspace specified. This will result in incomplete information.")
cliui.Warn(inv.Stderr, "No workspace specified. This will result in incomplete information.")
} else {
ws, err := namedWorkspace(inv.Context(), client, inv.Args[0])
if err != nil {
Expand Down Expand Up @@ -184,13 +184,22 @@ func (r *RootCmd) supportBundle() *serpent.Command {
_ = os.Remove(outputPath) // best effort
return xerrors.Errorf("create support bundle: %w", err)
}
msgs := support.Summarize(bun)
if len(msgs) != 0 {
cliui.Warn(inv.Stderr, "Potential issues detected:\n", msgs...)
cliLog.Warn(inv.Context(), "auto-detected issues")
for _, msg := range msgs {
cliLog.Warn(inv.Context(), msg)
}
}
bun.CLILogs = cliLogBuf.Bytes()

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

return nil
},
}
Expand Down
59 changes: 59 additions & 0 deletions support/support.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,3 +520,62 @@ func sanitizeEnv(kvs map[string]string) {
}
}
}

func Summarize(b *Bundle) (msgs []string) {
if b == nil {
return []string{}
}
if b.Network.Netcheck == nil {
msgs = append(msgs, "Netcheck missing from bundle!")
} else {
if b.Network.Netcheck.Error != nil {
msgs = append(msgs, "Client netcheck: "+*b.Network.Netcheck.Error)
}
for _, warn := range b.Network.Netcheck.Warnings {
msgs = append(msgs, "Client netcheck: "+warn.String())
}
}

if b.Deployment.HealthReport == nil {
msgs = append(msgs, "Deployment health check missing from bundle!")
} else {
if b.Deployment.HealthReport.AccessURL.Error != nil {
msgs = append(msgs, "Deployment health: "+*b.Deployment.HealthReport.AccessURL.Error)
}
for _, warn := range b.Deployment.HealthReport.AccessURL.Warnings {
msgs = append(msgs, "Deployment health: "+warn.String())
}
if b.Deployment.HealthReport.DERP.Error != nil {
msgs = append(msgs, "Deployment health: "+*b.Deployment.HealthReport.DERP.Error)
}
for _, warn := range b.Deployment.HealthReport.DERP.Warnings {
msgs = append(msgs, "Deployment health: "+warn.String())
}
if b.Deployment.HealthReport.Database.Error != nil {
msgs = append(msgs, "Deployment health: "+*b.Deployment.HealthReport.Database.Error)
}
for _, warn := range b.Deployment.HealthReport.Database.Warnings {
msgs = append(msgs, "Deployment health: "+warn.String())
}
if b.Deployment.HealthReport.ProvisionerDaemons.Error != nil {
msgs = append(msgs, "Deployment health: "+*b.Deployment.HealthReport.ProvisionerDaemons.Error)
}
for _, warn := range *&b.Deployment.HealthReport.ProvisionerDaemons.Warnings {
msgs = append(msgs, "Deployment health: "+warn.String())
}
if b.Deployment.HealthReport.Websocket.Error != nil {
msgs = append(msgs, "Deployment health: "+*b.Deployment.HealthReport.Websocket.Error)
}
for _, warn := range *&b.Deployment.HealthReport.Websocket.Warnings {
msgs = append(msgs, "Deployment health: "+warn)
}
if b.Deployment.HealthReport.WorkspaceProxy.Error != nil {
msgs = append(msgs, "Deployment health: "+*b.Deployment.HealthReport.WorkspaceProxy.Error)
}
for _, warn := range *&b.Deployment.HealthReport.WorkspaceProxy.Warnings {
msgs = append(msgs, "Deployment health: "+warn.String())
}
}

return msgs
}
41 changes: 41 additions & 0 deletions support/support_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"github.com/coder/coder/v2/coderd/database"
"github.com/coder/coder/v2/coderd/database/dbfake"
"github.com/coder/coder/v2/coderd/database/dbtime"
"github.com/coder/coder/v2/coderd/healthcheck/derphealth"
"github.com/coder/coder/v2/coderd/healthcheck/health"
"github.com/coder/coder/v2/coderd/util/ptr"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/coder/v2/support"
Expand Down Expand Up @@ -245,3 +247,42 @@ func assertNotNilNotEmpty[T any](t *testing.T, v T, msg string) {
assert.NotEmpty(t, v, msg+" but was empty")
}
}

func Test_Summarize(t *testing.T) {
for _, tt := range []struct {
name string
in support.Bundle
expected []string
}{
{
name: "empty",
in: support.Bundle{},
expected: []string{"Netcheck missing from bundle!"},
},
{
name: "network health report",
in: support.Bundle{
Network: support.Network{
Netcheck: &derphealth.Report{
Warnings: []health.Message{
{Code: "TEST", Message: "test"},
},
},
},
},
expected: []string{"TEST: test"},
},
} {
tt := tt
t.Run(tt.name, func(t *testing.T) {
actual := support.Summarize(&tt.in)
if len(tt.expected) == 0 {
assert.Empty(t, actual)
} else {
for _, exp := range tt.expected {
assert.Contains(t, actual, exp)
}
}
})
}
}