@@ -23,6 +23,7 @@ import (
23
23
"github.com/coder/coder/v2/coderd/externalauth"
24
24
"github.com/coder/coder/v2/coderd/prometheusmetrics"
25
25
"github.com/coder/coder/v2/coderd/schedule"
26
+ "github.com/coder/coder/v2/coderd/telemetry"
26
27
"github.com/coder/coder/v2/coderd/tracing"
27
28
"github.com/coder/coder/v2/coderd/workspacestats"
28
29
"github.com/coder/coder/v2/codersdk"
@@ -47,6 +48,7 @@ type API struct {
47
48
48
49
mu sync.Mutex
49
50
cachedWorkspaceID uuid.UUID
51
+ drpcServiceClose func ()
50
52
}
51
53
52
54
var _ agentproto.DRPCAgentServer = & API {}
@@ -65,15 +67,18 @@ type Options struct {
65
67
AppearanceFetcher * atomic.Pointer [appearance.Fetcher ]
66
68
PublishWorkspaceUpdateFn func (ctx context.Context , workspaceID uuid.UUID )
67
69
PublishWorkspaceAgentLogsUpdateFn func (ctx context.Context , workspaceAgentID uuid.UUID , msg agentsdk.LogsNotifyMessage )
68
-
69
- AccessURL * url.URL
70
- AppHostname string
71
- AgentStatsRefreshInterval time.Duration
72
- DisableDirectConnections bool
73
- DerpForceWebSockets bool
74
- DerpMapUpdateFrequency time.Duration
75
- ExternalAuthConfigs []* externalauth.Config
76
- Experiments codersdk.Experiments
70
+ NetworkTelemetryBatchFn func (batch []telemetry.NetworkEvent )
71
+
72
+ AccessURL * url.URL
73
+ AppHostname string
74
+ AgentStatsRefreshInterval time.Duration
75
+ DisableDirectConnections bool
76
+ DerpForceWebSockets bool
77
+ DerpMapUpdateFrequency time.Duration
78
+ NetworkTelemetryBatchFrequency time.Duration
79
+ NetworkTelemetryBatchMaxSize int
80
+ ExternalAuthConfigs []* externalauth.Config
81
+ Experiments codersdk.Experiments
77
82
78
83
// Optional:
79
84
// WorkspaceID avoids a future lookup to find the workspace ID by setting
@@ -154,15 +159,24 @@ func New(opts Options) *API {
154
159
}
155
160
156
161
api .DRPCService = & tailnet.DRPCService {
157
- CoordPtr : opts .TailnetCoordinator ,
158
- Logger : opts .Log ,
159
- DerpMapUpdateFrequency : opts .DerpMapUpdateFrequency ,
160
- DerpMapFn : opts .DerpMapFn ,
162
+ CoordPtr : opts .TailnetCoordinator ,
163
+ Logger : opts .Log ,
164
+ DerpMapUpdateFrequency : opts .DerpMapUpdateFrequency ,
165
+ DerpMapFn : opts .DerpMapFn ,
166
+ NetworkTelemetryBatchFrequency : opts .NetworkTelemetryBatchFrequency ,
167
+ NetworkTelemetryBatchMaxSize : opts .NetworkTelemetryBatchMaxSize ,
168
+ NetworkTelemetryBatchFn : opts .NetworkTelemetryBatchFn ,
161
169
}
170
+ api .drpcServiceClose = api .DRPCService .PeriodicTelemetryBatcher ()
162
171
163
172
return api
164
173
}
165
174
175
+ func (a * API ) Close () error {
176
+ a .drpcServiceClose ()
177
+ return nil
178
+ }
179
+
166
180
func (a * API ) Server (ctx context.Context ) (* drpcserver.Server , error ) {
167
181
mux := drpcmux .New ()
168
182
err := agentproto .DRPCRegisterAgent (mux , a )
0 commit comments