Skip to content

Commit a77ceac

Browse files
committed
chore: put connection reports behind experimental flag
1 parent 58463c6 commit a77ceac

File tree

3 files changed

+45
-5
lines changed

3 files changed

+45
-5
lines changed

agent/agent.go

+11
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ type Options struct {
8888
BlockFileTransfer bool
8989
Execer agentexec.Execer
9090
ContainerLister agentcontainers.Lister
91+
92+
ExperimentalConnectionReports bool
9193
}
9294

9395
type Client interface {
@@ -189,6 +191,8 @@ func New(options Options) Agent {
189191
metrics: newAgentMetrics(prometheusRegistry),
190192
execer: options.Execer,
191193
lister: options.ContainerLister,
194+
195+
experimentalConnectionReports: options.ExperimentalConnectionReports,
192196
}
193197
// Initially, we have a closed channel, reflecting the fact that we are not initially connected.
194198
// Each time we connect we replace the channel (while holding the closeMutex) with a new one
@@ -263,6 +267,8 @@ type agent struct {
263267
metrics *agentMetrics
264268
execer agentexec.Execer
265269
lister agentcontainers.Lister
270+
271+
experimentalConnectionReports bool
266272
}
267273

268274
func (a *agent) TailnetConn() *tailnet.Conn {
@@ -770,6 +776,11 @@ func (a *agent) reportConnectionsLoop(ctx context.Context, aAPI proto.DRPCAgentC
770776
}
771777

772778
func (a *agent) reportConnection(id uuid.UUID, connectionType proto.Connection_Type, ip string) (disconnected func(code int, reason string)) {
779+
// If the experiment hasn't been enabled, we don't report connections.
780+
if !a.experimentalConnectionReports {
781+
return func(int, string) {} // Noop.
782+
}
783+
773784
// Remove the port from the IP.
774785
if portIndex := strings.LastIndex(ip, ":"); portIndex != -1 {
775786
ip = ip[:portIndex]

agent/agent_test.go

+18-5
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ func TestAgent_Stats_Magic(t *testing.T) {
159159
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
160160
defer cancel()
161161
//nolint:dogsled
162-
conn, agentClient, stats, _, _ := setupAgent(t, agentsdk.Manifest{}, 0)
162+
conn, agentClient, stats, _, _ := setupAgent(t, agentsdk.Manifest{}, 0, func(_ *agenttest.Client, o *agent.Options) {
163+
o.ExperimentalConnectionReports = true
164+
})
163165
sshClient, err := conn.SSHClient(ctx)
164166
require.NoError(t, err)
165167
defer sshClient.Close()
@@ -227,7 +229,9 @@ func TestAgent_Stats_Magic(t *testing.T) {
227229
remotePort := sc.Text()
228230

229231
//nolint:dogsled
230-
conn, agentClient, stats, _, _ := setupAgent(t, agentsdk.Manifest{}, 0)
232+
conn, agentClient, stats, _, _ := setupAgent(t, agentsdk.Manifest{}, 0, func(_ *agenttest.Client, o *agent.Options) {
233+
o.ExperimentalConnectionReports = true
234+
})
231235
sshClient, err := conn.SSHClient(ctx)
232236
require.NoError(t, err)
233237

@@ -922,7 +926,9 @@ func TestAgent_SFTP(t *testing.T) {
922926
home = "/" + strings.ReplaceAll(home, "\\", "/")
923927
}
924928
//nolint:dogsled
925-
conn, agentClient, _, _, _ := setupAgent(t, agentsdk.Manifest{}, 0)
929+
conn, agentClient, _, _, _ := setupAgent(t, agentsdk.Manifest{}, 0, func(_ *agenttest.Client, o *agent.Options) {
930+
o.ExperimentalConnectionReports = true
931+
})
926932
sshClient, err := conn.SSHClient(ctx)
927933
require.NoError(t, err)
928934
defer sshClient.Close()
@@ -958,7 +964,9 @@ func TestAgent_SCP(t *testing.T) {
958964
defer cancel()
959965

960966
//nolint:dogsled
961-
conn, agentClient, _, _, _ := setupAgent(t, agentsdk.Manifest{}, 0)
967+
conn, agentClient, _, _, _ := setupAgent(t, agentsdk.Manifest{}, 0, func(_ *agenttest.Client, o *agent.Options) {
968+
o.ExperimentalConnectionReports = true
969+
})
962970
sshClient, err := conn.SSHClient(ctx)
963971
require.NoError(t, err)
964972
defer sshClient.Close()
@@ -1001,6 +1009,7 @@ func TestAgent_FileTransferBlocked(t *testing.T) {
10011009
//nolint:dogsled
10021010
conn, agentClient, _, _, _ := setupAgent(t, agentsdk.Manifest{}, 0, func(_ *agenttest.Client, o *agent.Options) {
10031011
o.BlockFileTransfer = true
1012+
o.ExperimentalConnectionReports = true
10041013
})
10051014
sshClient, err := conn.SSHClient(ctx)
10061015
require.NoError(t, err)
@@ -1021,6 +1030,7 @@ func TestAgent_FileTransferBlocked(t *testing.T) {
10211030
//nolint:dogsled
10221031
conn, agentClient, _, _, _ := setupAgent(t, agentsdk.Manifest{}, 0, func(_ *agenttest.Client, o *agent.Options) {
10231032
o.BlockFileTransfer = true
1033+
o.ExperimentalConnectionReports = true
10241034
})
10251035
sshClient, err := conn.SSHClient(ctx)
10261036
require.NoError(t, err)
@@ -1049,6 +1059,7 @@ func TestAgent_FileTransferBlocked(t *testing.T) {
10491059
//nolint:dogsled
10501060
conn, agentClient, _, _, _ := setupAgent(t, agentsdk.Manifest{}, 0, func(_ *agenttest.Client, o *agent.Options) {
10511061
o.BlockFileTransfer = true
1062+
o.ExperimentalConnectionReports = true
10521063
})
10531064
sshClient, err := conn.SSHClient(ctx)
10541065
require.NoError(t, err)
@@ -1679,7 +1690,9 @@ func TestAgent_ReconnectingPTY(t *testing.T) {
16791690
defer cancel()
16801691

16811692
//nolint:dogsled
1682-
conn, agentClient, _, _, _ := setupAgent(t, agentsdk.Manifest{}, 0)
1693+
conn, agentClient, _, _, _ := setupAgent(t, agentsdk.Manifest{}, 0, func(_ *agenttest.Client, o *agent.Options) {
1694+
o.ExperimentalConnectionReports = true
1695+
})
16831696
id := uuid.New()
16841697

16851698
// Test that the connection is reported. This must be tested in the

cli/agent.go

+16
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ func (r *RootCmd) workspaceAgent() *serpent.Command {
5454
agentHeaderCommand string
5555
agentHeader []string
5656
devcontainersEnabled bool
57+
58+
experimentalConnectionReports bool
5759
)
5860
cmd := &serpent.Command{
5961
Use: "agent",
@@ -325,6 +327,10 @@ func (r *RootCmd) workspaceAgent() *serpent.Command {
325327
containerLister = agentcontainers.NewDocker(execer)
326328
}
327329

330+
if experimentalConnectionReports {
331+
logger.Info(ctx, "experimental connection reports enabled")
332+
}
333+
328334
agnt := agent.New(agent.Options{
329335
Client: client,
330336
Logger: logger,
@@ -351,6 +357,8 @@ func (r *RootCmd) workspaceAgent() *serpent.Command {
351357
BlockFileTransfer: blockFileTransfer,
352358
Execer: execer,
353359
ContainerLister: containerLister,
360+
361+
ExperimentalConnectionReports: experimentalConnectionReports,
354362
})
355363

356364
promHandler := agent.PrometheusMetricsHandler(prometheusRegistry, logger)
@@ -480,6 +488,14 @@ func (r *RootCmd) workspaceAgent() *serpent.Command {
480488
Description: "Allow the agent to automatically detect running devcontainers.",
481489
Value: serpent.BoolOf(&devcontainersEnabled),
482490
},
491+
{
492+
Flag: "experimental-connection-reports-enable",
493+
Hidden: true,
494+
Default: "false",
495+
Env: "CODER_AGENT_EXPERIMENTAL_CONNECTION_REPORTS_ENABLE",
496+
Description: "Enable experimental connection reports.",
497+
Value: serpent.BoolOf(&experimentalConnectionReports),
498+
},
483499
}
484500

485501
return cmd

0 commit comments

Comments
 (0)