@@ -46,11 +46,13 @@ import (
46
46
"go.opentelemetry.io/otel/trace"
47
47
"go.opentelemetry.io/otel/trace/noop"
48
48
"golang.org/x/sys/unix"
49
+ "google.golang.org/grpc"
49
50
50
51
"github.com/parca-dev/parca-agent/analytics"
51
52
"github.com/parca-dev/parca-agent/config"
52
53
"github.com/parca-dev/parca-agent/flags"
53
54
"github.com/parca-dev/parca-agent/reporter"
55
+ "github.com/parca-dev/parca-agent/uploader"
54
56
)
55
57
56
58
var (
@@ -136,6 +138,14 @@ func mainWithExitCode() flags.ExitCode {
136
138
return code
137
139
}
138
140
141
+ if f .OfflineMode .Upload {
142
+ code , err := uploader .OfflineModeDoUpload (f )
143
+ if err != nil {
144
+ log .Errorf ("failed to upload offline mode logs: %v" , err )
145
+ }
146
+ return code
147
+ }
148
+
139
149
reg := prometheus .NewRegistry ()
140
150
reg .MustRegister (
141
151
collectors .NewBuildInfoCollector (),
@@ -164,12 +174,17 @@ func mainWithExitCode() flags.ExitCode {
164
174
}
165
175
}
166
176
167
- grpcConn , err := f .RemoteStore .WaitGrpcEndpoint (ctx , reg , tp )
168
- if err != nil {
169
- log .Errorf ("failed to connect to server: %v" , err )
170
- return flags .ExitFailure
177
+ isOfflineMode := len (f .OfflineMode .StoragePath ) > 0
178
+
179
+ var grpcConn * grpc.ClientConn
180
+ if ! isOfflineMode {
181
+ grpcConn , err = f .RemoteStore .WaitGrpcEndpoint (ctx , reg , tp )
182
+ if err != nil {
183
+ log .Errorf ("failed to connect to server: %v" , err )
184
+ return flags .ExitFailure
185
+ }
186
+ defer grpcConn .Close ()
171
187
}
172
- defer grpcConn .Close ()
173
188
174
189
presentCores , err := numcpus .GetPresent ()
175
190
if err != nil {
@@ -291,17 +306,32 @@ func mainWithExitCode() flags.ExitCode {
291
306
intervals := times .New (5 * time .Second , f .Profiling .Duration , f .Profiling .ProbabilisticInterval )
292
307
times .StartRealtimeSync (mainCtx , f .ClockSyncInterval )
293
308
309
+ var client profilestoregrpc.ProfileStoreServiceClient
310
+ var debuginfoClient debuginfogrpc.DebuginfoServiceClient
311
+ if grpcConn != nil {
312
+ client = profilestoregrpc .NewProfileStoreServiceClient (grpcConn )
313
+ debuginfoClient = debuginfogrpc .NewDebuginfoServiceClient (grpcConn )
314
+ }
315
+
316
+ var offlineModeConfig * reporter.OfflineModeConfig
317
+ if isOfflineMode {
318
+ offlineModeConfig = & reporter.OfflineModeConfig {
319
+ StoragePath : f .OfflineMode .StoragePath ,
320
+ RotationInterval : f .OfflineMode .RotationInterval ,
321
+ }
322
+ }
323
+
294
324
// Network operations to CA start here
295
325
// Connect to the collection agent
296
326
parcaReporter , err := reporter .New (
297
327
memory .DefaultAllocator ,
298
- profilestoregrpc . NewProfileStoreServiceClient ( grpcConn ) ,
299
- debuginfogrpc . NewDebuginfoServiceClient ( grpcConn ) ,
328
+ client ,
329
+ debuginfoClient ,
300
330
externalLabels ,
301
331
f .Profiling .Duration ,
302
332
f .Debuginfo .Strip ,
303
333
f .Debuginfo .UploadMaxParallel ,
304
- f .Debuginfo .UploadDisable ,
334
+ f .Debuginfo .UploadDisable || isOfflineMode ,
305
335
int64 (f .Profiling .CPUSamplingFrequency ),
306
336
traceHandlerCacheSize ,
307
337
f .Debuginfo .UploadQueueSize ,
@@ -310,6 +340,7 @@ func mainWithExitCode() flags.ExitCode {
310
340
relabelConfigs ,
311
341
buildInfo .VcsRevision ,
312
342
reg ,
343
+ offlineModeConfig ,
313
344
)
314
345
if err != nil {
315
346
return flags .Failure ("Failed to start reporting: %v" , err )
@@ -413,8 +444,10 @@ func mainWithExitCode() flags.ExitCode {
413
444
414
445
log .Info ("Stop processing ..." )
415
446
rep .Stop ()
416
- if err := grpcConn .Close (); err != nil {
417
- log .Fatalf ("Stopping connection of OTLP client client failed: %v" , err )
447
+ if grpcConn != nil {
448
+ if err := grpcConn .Close (); err != nil {
449
+ log .Fatalf ("Stopping connection of OTLP client client failed: %v" , err )
450
+ }
418
451
}
419
452
420
453
log .Info ("Exiting ..." )
0 commit comments