Skip to content

feat(cli): add aws check to ping p2p diagnostics #14450

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
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
fix test
  • Loading branch information
ethanndickson committed Aug 29, 2024
commit 2e08d191fdf198615438ce61ad2b1d78d86d40e5
19 changes: 4 additions & 15 deletions cli/cliui/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ import (
"strconv"
"strings"
"time"
"unicode"

"github.com/google/uuid"
"golang.org/x/xerrors"
"tailscale.com/tailcfg"

"github.com/coder/coder/v2/coderd/healthcheck/health"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/coder/v2/codersdk/healthsdk"
"github.com/coder/coder/v2/codersdk/workspacesdk"
Expand Down Expand Up @@ -394,13 +392,13 @@ func (d ConnDiags) splitDiagnostics() (general, client, agent []string) {

if d.AgentNetcheck != nil {
for _, msg := range d.AgentNetcheck.Interfaces.Warnings {
agent = append(agent, formatHealthMessage(msg))
agent = append(agent, msg.Message)
}
}

if d.LocalInterfaces != nil {
for _, msg := range d.LocalInterfaces.Warnings {
client = append(client, formatHealthMessage(msg))
client = append(client, msg.Message)
}
}

Expand Down Expand Up @@ -441,21 +439,12 @@ func (d ConnDiags) splitDiagnostics() (general, client, agent []string) {
}
}

if true {
if d.ClientIPIsAWS {
client = append(client, "Client IP address is within an AWS range (AWS uses hard NAT)")
}

if true {
if d.AgentIPIsAWS {
agent = append(agent, "Agent IP address is within an AWS range (AWS uses hard NAT)")
}
return general, client, agent
}

func formatHealthMessage(msg health.Message) string {
if msg.Code != health.CodeInterfaceSmallMTU {
return msg.Message
}
r := []rune(strings.Replace(msg.Message, ", which may cause problems with direct connections", "", -1))
out := string(append([]rune{unicode.ToUpper(r[0])}, r[1:]...))
return fmt.Sprintf("%s, which may degrade the quality of direct connections", out)
}
4 changes: 2 additions & 2 deletions cli/cliui/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ func TestConnDiagnostics(t *testing.T) {
Interfaces: healthsdk.InterfacesReport{
BaseReport: healthsdk.BaseReport{
Warnings: []health.Message{
health.Messagef(health.CodeInterfaceSmallMTU, "network interface eth0 has MTU 1280, (less than 1378), which may cause problems with direct connections"),
health.Messagef(health.CodeInterfaceSmallMTU, "Network interface eth0 has MTU 1280, (less than 1378), which may degrade the quality of direct connections"),
},
},
},
Expand All @@ -838,7 +838,7 @@ func TestConnDiagnostics(t *testing.T) {
LocalInterfaces: &healthsdk.InterfacesReport{
BaseReport: healthsdk.BaseReport{
Warnings: []health.Message{
health.Messagef(health.CodeInterfaceSmallMTU, "network interface eth1 has MTU 1310, (less than 1378), which may cause problems with direct connections"),
health.Messagef(health.CodeInterfaceSmallMTU, "Network interface eth1 has MTU 1310, (less than 1378), which may degrade the quality of direct connections"),
},
},
},
Expand Down
12 changes: 6 additions & 6 deletions cli/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ func (r *RootCmd) ping() *serpent.Command {
break
}
}
ctx, cancel = context.WithTimeout(inv.Context(), 30*time.Second)
defer cancel()
diagCtx, diagCancel := context.WithTimeout(inv.Context(), 30*time.Second)
defer diagCancel()
diags := conn.GetPeerDiagnostics()
cliui.PeerDiagnostics(inv.Stdout, diags)

Expand All @@ -161,16 +161,16 @@ func (r *RootCmd) ping() *serpent.Command {
Verbose: r.verbose,
}

awsRanges, err := cliutil.FetchAWSIPRanges(ctx, cliutil.AWSIPRangesURL)
awsRanges, err := cliutil.FetchAWSIPRanges(diagCtx, cliutil.AWSIPRangesURL)
if err != nil {
opts.Logger.Debug(inv.Context(), "failed to retrieve AWS IP ranges", slog.Error(err))
}

connDiags.ClientIPIsAWS = isAWSIP(awsRanges, ni)

connInfo, err := client.AgentConnectionInfoGeneric(ctx)
connInfo, err := client.AgentConnectionInfoGeneric(diagCtx)
if err != nil || connInfo.DERPMap == nil {
return xerrors.Errorf("Failed to retrieve connection info from server: %v\n", err)
return xerrors.Errorf("Failed to retrieve connection info from server: %w\n", err)
}
connDiags.ConnInfo = connInfo
ifReport, err := healthsdk.RunInterfacesReport()
Expand All @@ -180,7 +180,7 @@ func (r *RootCmd) ping() *serpent.Command {
_, _ = fmt.Fprintf(inv.Stdout, "Failed to retrieve local interfaces report: %v\n", err)
}

agentNetcheck, err := conn.Netcheck(ctx)
agentNetcheck, err := conn.Netcheck(diagCtx)
if err == nil {
connDiags.AgentNetcheck = &agentNetcheck
connDiags.AgentIPIsAWS = isAWSIP(awsRanges, agentNetcheck.NetInfo)
Expand Down
1 change: 1 addition & 0 deletions cli/ping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func TestPing(t *testing.T) {

pty.ExpectMatch("pong from " + workspace.Name)
pty.ExpectMatch("✔ received remote agent data from Coder networking coordinator")
pty.ExpectMatch("✔ You are connected directly (p2p)")
cancel()
<-cmdDone
})
Expand Down
2 changes: 1 addition & 1 deletion codersdk/healthsdk/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func generateInterfacesReport(st *interfaces.State) (report InterfacesReport) {
report.Severity = health.SeverityWarning
report.Warnings = append(report.Warnings,
health.Messagef(health.CodeInterfaceSmallMTU,
"network interface %s has MTU %d (less than %d), which may cause problems with direct connections", iface.Name, iface.MTU, safeMTU),
"Network interface %s has MTU %d (less than %d), which may degrade the quality of direct connections", iface.Name, iface.MTU, safeMTU),
)
}
}
Expand Down
Loading