- Notifications
You must be signed in to change notification settings - Fork914
feat(cli): add p2p diagnostics to ping#14426
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
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
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
1 change: 1 addition & 0 deletionsagent/api.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
31 changes: 31 additions & 0 deletionsagent/health.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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package agent | ||
import ( | ||
"net/http" | ||
"github.com/coder/coder/v2/coderd/healthcheck/health" | ||
"github.com/coder/coder/v2/coderd/httpapi" | ||
"github.com/coder/coder/v2/codersdk" | ||
"github.com/coder/coder/v2/codersdk/healthsdk" | ||
) | ||
func (a *agent) HandleNetcheck(rw http.ResponseWriter, r *http.Request) { | ||
ni := a.TailnetConn().GetNetInfo() | ||
ifReport, err := healthsdk.RunInterfacesReport() | ||
if err != nil { | ||
httpapi.Write(r.Context(), rw, http.StatusInternalServerError, codersdk.Response{ | ||
Message: "Failed to run interfaces report", | ||
Detail: err.Error(), | ||
}) | ||
return | ||
} | ||
httpapi.Write(r.Context(), rw, http.StatusOK, healthsdk.AgentNetcheckReport{ | ||
BaseReport: healthsdk.BaseReport{ | ||
Severity: health.SeverityOK, | ||
}, | ||
NetInfo: ni, | ||
Interfaces: ifReport, | ||
}) | ||
} |
55 changes: 55 additions & 0 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 |
---|---|---|
@@ -10,8 +10,11 @@ import ( | ||
"github.com/google/uuid" | ||
"golang.org/x/xerrors" | ||
"tailscale.com/tailcfg" | ||
"github.com/coder/coder/v2/codersdk" | ||
"github.com/coder/coder/v2/codersdk/healthsdk" | ||
"github.com/coder/coder/v2/codersdk/workspacesdk" | ||
"github.com/coder/coder/v2/tailnet" | ||
) | ||
@@ -346,3 +349,55 @@ func PeerDiagnostics(w io.Writer, d tailnet.PeerDiagnostics) { | ||
_, _ = fmt.Fprint(w, "✘ Wireguard is not connected\n") | ||
} | ||
} | ||
type ConnDiags struct { | ||
ConnInfo *workspacesdk.AgentConnectionInfo | ||
PingP2P bool | ||
DisableDirect bool | ||
LocalNetInfo *tailcfg.NetInfo | ||
LocalInterfaces *healthsdk.InterfacesReport | ||
AgentNetcheck *healthsdk.AgentNetcheckReport | ||
// TODO: More diagnostics | ||
} | ||
func ConnDiagnostics(w io.Writer, d ConnDiags) { | ||
if d.AgentNetcheck != nil { | ||
for _, msg := range d.AgentNetcheck.Interfaces.Warnings { | ||
_, _ = fmt.Fprintf(w, "❗ Agent: %s\n", msg.Message) | ||
} | ||
} | ||
if d.LocalInterfaces != nil { | ||
for _, msg := range d.LocalInterfaces.Warnings { | ||
_, _ = fmt.Fprintf(w, "❗ Client: %s\n", msg.Message) | ||
} | ||
} | ||
if d.PingP2P { | ||
_, _ = fmt.Fprint(w, "✔ You are connected directly (p2p)\n") | ||
return | ||
} | ||
ethanndickson marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
_, _ = fmt.Fprint(w, "❗ You are connected via a DERP relay, not directly (p2p)\n") | ||
if d.DisableDirect { | ||
_, _ = fmt.Fprint(w, "❗ Direct connections are disabled locally, by `--disable-direct` or `CODER_DISABLE_DIRECT`\n") | ||
return | ||
} | ||
if d.ConnInfo != nil && d.ConnInfo.DisableDirectConnections { | ||
_, _ = fmt.Fprint(w, "❗ Your Coder administrator has blocked direct connections\n") | ||
return | ||
ethanndickson marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
} | ||
if d.ConnInfo != nil && d.ConnInfo.DERPMap != nil && !d.ConnInfo.DERPMap.HasSTUN() { | ||
_, _ = fmt.Fprint(w, "✘ The DERP map is not configured to use STUN, which will prevent direct connections from starting outside of local networks\n") | ||
} | ||
if d.LocalNetInfo != nil && d.LocalNetInfo.MappingVariesByDestIP.EqualBool(true) { | ||
_, _ = fmt.Fprint(w, "❗ Client is potentially behind a hard NAT, as multiple endpoints were retrieved from different STUN servers\n") | ||
} | ||
if d.AgentNetcheck != nil && d.AgentNetcheck.NetInfo != nil && d.AgentNetcheck.NetInfo.MappingVariesByDestIP.EqualBool(true) { | ||
_, _ = fmt.Fprint(w, "❗ Agent is potentially behind a hard NAT, as multiple endpoints were retrieved from different STUN servers\n") | ||
} | ||
} |
129 changes: 129 additions & 0 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
45 changes: 41 additions & 4 deletionscli/ping.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
7 changes: 7 additions & 0 deletionscodersdk/healthsdk/healthsdk.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
18 changes: 18 additions & 0 deletionscodersdk/workspacesdk/agentconn.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.