Skip to content

Commit 0efd6ed

Browse files
committed
write diags to stderr
1 parent 1351717 commit 0efd6ed

File tree

4 files changed

+25
-20
lines changed

4 files changed

+25
-20
lines changed

cli/cliui/agent.go

-6
Original file line numberDiff line numberDiff line change
@@ -406,12 +406,6 @@ func (d ConnDiags) splitDiagnostics() (general, client, agent []string) {
406406
}
407407
}
408408

409-
if d.PingP2P {
410-
general = append(general, "✔ You are connected directly (p2p)")
411-
} else {
412-
general = append(general, fmt.Sprintf("❗ You are connected via a DERP relay, not directly (p2p)\n%s#common-problems-with-direct-connections", d.TroubleshootingURL))
413-
}
414-
415409
if d.PingP2P && !d.Verbose {
416410
return general, client, agent
417411
}

cli/ping.go

+13-6
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ func (s *pingSummary) addResult(r *ipnstate.PingResult) {
6262
}
6363

6464
// Write finalizes the summary and writes it
65-
func (s *pingSummary) Write(wsname string, w io.Writer) {
66-
s.Workspace = wsname
65+
func (s *pingSummary) Write(w io.Writer) {
6766
if s.Successful > 0 {
6867
s.Avg = ptr.Ref(time.Duration(s.latencySum / float64(s.Successful) * float64(time.Second)))
6968
}
@@ -140,7 +139,7 @@ func (r *RootCmd) ping() *serpent.Command {
140139
diagCtx, diagCancel := context.WithTimeout(inv.Context(), 30*time.Second)
141140
defer diagCancel()
142141
diags := conn.GetPeerDiagnostics()
143-
cliui.PeerDiagnostics(inv.Stdout, diags)
142+
cliui.PeerDiagnostics(inv.Stderr, diags)
144143

145144
// Silent ping to determine whether we should show diags
146145
_, didP2p, _, _ := conn.Ping(ctx)
@@ -186,8 +185,10 @@ func (r *RootCmd) ping() *serpent.Command {
186185
}
187186
}
188187

189-
connDiags.Write(inv.Stdout)
190-
results := &pingSummary{}
188+
connDiags.Write(inv.Stderr)
189+
results := &pingSummary{
190+
Workspace: workspaceName,
191+
}
191192
n := 0
192193
start := time.Now()
193194
pingLoop:
@@ -266,7 +267,13 @@ func (r *RootCmd) ping() *serpent.Command {
266267
}
267268
}
268269

269-
results.Write(workspaceName, inv.Stdout)
270+
if didP2p {
271+
_, _ = fmt.Fprintf(inv.Stderr, "✔ You are connected directly (p2p)\n")
272+
} else {
273+
_, _ = fmt.Fprintf(inv.Stderr, "❗ You are connected via a DERP relay, not directly (p2p)\n%s#common-problems-with-direct-connections\n", connDiags.TroubleshootingURL)
274+
}
275+
276+
results.Write(inv.Stdout)
270277

271278
return nil
272279
},

cli/ping_internal_test.go

+12-6
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ func TestBuildSummary(t *testing.T) {
3333
},
3434
}
3535

36-
actual := pingSummary{}
36+
actual := pingSummary{
37+
Workspace: "test",
38+
}
3739
for _, r := range input {
3840
actual.addResult(r)
3941
}
40-
actual.Write("test", io.Discard)
42+
actual.Write(io.Discard)
4143
require.Equal(t, time.Duration(0.1*float64(time.Second)), *actual.Min)
4244
require.Equal(t, time.Duration(0.2*float64(time.Second)), *actual.Avg)
4345
require.Equal(t, time.Duration(0.3*float64(time.Second)), *actual.Max)
@@ -53,11 +55,13 @@ func TestBuildSummary(t *testing.T) {
5355
},
5456
}
5557

56-
actual := &pingSummary{}
58+
actual := &pingSummary{
59+
Workspace: "test",
60+
}
5761
for _, r := range input {
5862
actual.addResult(r)
5963
}
60-
actual.Write("test", io.Discard)
64+
actual.Write(io.Discard)
6165
require.Equal(t, actual.Successful, 1)
6266
require.Equal(t, time.Duration(0.2*float64(time.Second)), *actual.Min)
6367
require.Equal(t, time.Duration(0.2*float64(time.Second)), *actual.Avg)
@@ -90,11 +94,13 @@ func TestBuildSummary(t *testing.T) {
9094
m2: 0,
9195
}
9296

93-
actual := &pingSummary{}
97+
actual := &pingSummary{
98+
Workspace: "test",
99+
}
94100
for _, r := range input {
95101
actual.addResult(r)
96102
}
97-
actual.Write("test", io.Discard)
103+
actual.Write(io.Discard)
98104
require.Equal(t, expected, actual)
99105
})
100106
}

cli/ping_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ func TestPing(t *testing.T) {
6565
assert.NoError(t, err)
6666
})
6767

68-
pty.ExpectMatch("✔ received remote agent data from Coder networking coordinator")
69-
pty.ExpectMatch("You are connected")
7068
pty.ExpectMatch("pong from " + workspace.Name)
7169
cancel()
7270
<-cmdDone

0 commit comments

Comments
 (0)