mirror of
https://github.com/coder/coder.git
synced 2025-03-14 10:09:57 +00:00
re: #13327 Adds local interfaces to `coder netcheck` and checks their MTUs for potential problems. This is mostly relevant for end-user systems where VPNs are common. We _could_ also add it to coderd healthcheck, but until I see coderd connecting to workspaces over a VPN in the wild, I don't think its worth the UX effort. Netcheck results get the following: ``` "interfaces": { "error": null, "severity": "ok", "warnings": null, "dismissed": false, "interfaces": [ { "name": "lo0", "mtu": 16384, "addresses": [ "127.0.0.1/8", "::1/128", "fe80::1/64" ] }, { "name": "en8", "mtu": 1500, "addresses": [ "192.168.50.217/24", "fe80::c13:1a92:3fa5:dd7e/64" ] } ] } ``` _Technically_ not back compatible if anyone is parsing `coder netcheck` output as JSON, since the original output is now under `"derp"` in the output.
74 lines
1.7 KiB
Go
74 lines
1.7 KiB
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"time"
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
"github.com/coder/coder/v2/coderd/healthcheck/derphealth"
|
|
"github.com/coder/coder/v2/codersdk"
|
|
"github.com/coder/coder/v2/codersdk/healthsdk"
|
|
"github.com/coder/coder/v2/codersdk/workspacesdk"
|
|
"github.com/coder/serpent"
|
|
)
|
|
|
|
func (r *RootCmd) netcheck() *serpent.Command {
|
|
client := new(codersdk.Client)
|
|
|
|
cmd := &serpent.Command{
|
|
Use: "netcheck",
|
|
Short: "Print network debug information for DERP and STUN",
|
|
Middleware: serpent.Chain(
|
|
r.InitClient(client),
|
|
),
|
|
Handler: func(inv *serpent.Invocation) error {
|
|
ctx, cancel := context.WithTimeout(inv.Context(), 30*time.Second)
|
|
defer cancel()
|
|
|
|
connInfo, err := workspacesdk.New(client).AgentConnectionInfoGeneric(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
_, _ = fmt.Fprint(inv.Stderr, "Gathering a network report. This may take a few seconds...\n\n")
|
|
|
|
var derpReport derphealth.Report
|
|
derpReport.Run(ctx, &derphealth.ReportOptions{
|
|
DERPMap: connInfo.DERPMap,
|
|
})
|
|
|
|
ifReport, err := healthsdk.RunInterfacesReport()
|
|
if err != nil {
|
|
return xerrors.Errorf("failed to run interfaces report: %w", err)
|
|
}
|
|
|
|
report := healthsdk.ClientNetcheckReport{
|
|
DERP: healthsdk.DERPHealthReport(derpReport),
|
|
Interfaces: ifReport,
|
|
}
|
|
|
|
raw, err := json.MarshalIndent(report, "", " ")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
n, err := inv.Stdout.Write(raw)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if n != len(raw) {
|
|
return xerrors.Errorf("failed to write all bytes to stdout; wrote %d, len %d", n, len(raw))
|
|
}
|
|
|
|
_, _ = inv.Stdout.Write([]byte("\n"))
|
|
return nil
|
|
},
|
|
}
|
|
|
|
cmd.Options = serpent.OptionSet{}
|
|
return cmd
|
|
}
|