- Notifications
You must be signed in to change notification settings - Fork913
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
ethanndickson merged 5 commits intomainfrom08-27-feat_cli_add_aws_check_to_ping_p2p_diagnosticsAug 29, 2024
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
5 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
83 changes: 65 additions & 18 deletionscli/cliui/agent.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -351,53 +351,100 @@ func PeerDiagnostics(w io.Writer, d tailnet.PeerDiagnostics) { | ||
} | ||
type ConnDiags struct { | ||
ConnInfo workspacesdk.AgentConnectionInfo | ||
PingP2P bool | ||
DisableDirect bool | ||
LocalNetInfo *tailcfg.NetInfo | ||
LocalInterfaces *healthsdk.InterfacesReport | ||
AgentNetcheck *healthsdk.AgentNetcheckReport | ||
ClientIPIsAWS bool | ||
AgentIPIsAWS bool | ||
Verbose bool | ||
// TODO: More diagnostics | ||
} | ||
func (d ConnDiags) Write(w io.Writer) { | ||
_, _ = fmt.Fprintln(w, "") | ||
general, client, agent := d.splitDiagnostics() | ||
for _, msg := range general { | ||
_, _ = fmt.Fprintln(w, msg) | ||
} | ||
if len(client) > 0 { | ||
_, _ = fmt.Fprint(w, "Possible client-side issues with direct connection:\n\n") | ||
for _, msg := range client { | ||
_, _ = fmt.Fprintf(w, " - %s\n\n", msg) | ||
} | ||
} | ||
if len(agent) > 0 { | ||
_, _ = fmt.Fprint(w, "Possible agent-side issues with direct connections:\n\n") | ||
for _, msg := range agent { | ||
_, _ = fmt.Fprintf(w, " - %s\n\n", msg) | ||
} | ||
} | ||
} | ||
func (d ConnDiags) splitDiagnostics() (general, client, agent []string) { | ||
if d.PingP2P { | ||
ethanndickson marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
general = append(general, "✔ You are connected directly (p2p)") | ||
} else { | ||
general = append(general, "❗ You are connected via a DERP relay, not directly (p2p)") | ||
} | ||
if d.AgentNetcheck != nil { | ||
for _, msg := range d.AgentNetcheck.Interfaces.Warnings { | ||
agent = append(agent, msg.Message) | ||
} | ||
} | ||
if d.LocalInterfaces != nil { | ||
for _, msg := range d.LocalInterfaces.Warnings { | ||
client = append(client, msg.Message) | ||
} | ||
} | ||
if d.PingP2P && !d.Verbose { | ||
return general, client, agent | ||
} | ||
if d.DisableDirect { | ||
general = append(general, "❗ Direct connections are disabled locally, by `--disable-direct` or `CODER_DISABLE_DIRECT`") | ||
if !d.Verbose { | ||
return general, client, agent | ||
} | ||
} | ||
if d.ConnInfo.DisableDirectConnections { | ||
general = append(general, "❗ Your Coder administrator has blocked direct connections") | ||
if !d.Verbose { | ||
return general, client, agent | ||
} | ||
} | ||
if !d.ConnInfo.DERPMap.HasSTUN() { | ||
general = append(general, "The DERP map is not configured to use STUN") | ||
} else if d.LocalNetInfo != nil && !d.LocalNetInfo.UDP { | ||
client = append(client, "Client could not connect to STUN over UDP") | ||
} | ||
if d.LocalNetInfo != nil && d.LocalNetInfo.MappingVariesByDestIP.EqualBool(true) { | ||
client = append(client, "Client is potentially behind a hard NAT, as multiple endpoints were retrieved from different STUN servers") | ||
} | ||
if d.AgentNetcheck != nil && d.AgentNetcheck.NetInfo != nil { | ||
if d.AgentNetcheck.NetInfo.MappingVariesByDestIP.EqualBool(true) { | ||
agent = append(agent, "Agent is potentially behind a hard NAT, as multiple endpoints were retrieved from different STUN servers") | ||
} | ||
if !d.AgentNetcheck.NetInfo.UDP { | ||
agent = append(agent, "Agent could not connect to STUN over UDP") | ||
} | ||
} | ||
if d.ClientIPIsAWS { | ||
client = append(client, "Client IP address is within an AWS range (AWS uses hard NAT)") | ||
} | ||
if d.AgentIPIsAWS { | ||
agent = append(agent, "AgentIP address is within an AWS range (AWS uses hard NAT)") | ||
} | ||
return general, client, agent | ||
} |
118 changes: 106 additions & 12 deletionscli/cliui/agent_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.