@@ -14,6 +14,7 @@ import (
14
14
"errors"
15
15
"fmt"
16
16
"io"
17
+ "log/slog"
17
18
"os"
18
19
"path"
19
20
"strings"
@@ -29,8 +30,6 @@ import (
29
30
"github.com/apache/arrow/go/v16/arrow/memory"
30
31
lru "github.com/elastic/go-freelru"
31
32
"github.com/klauspost/compress/zstd"
32
- "github.com/parca-dev/parca-agent/metrics"
33
- "github.com/parca-dev/parca-agent/reporter/metadata"
34
33
"github.com/prometheus/client_golang/prometheus"
35
34
"github.com/prometheus/common/model"
36
35
"github.com/prometheus/prometheus/model/labels"
@@ -42,6 +41,9 @@ import (
42
41
"go.opentelemetry.io/ebpf-profiler/libpf/xsync"
43
42
otelmetrics "go.opentelemetry.io/ebpf-profiler/metrics"
44
43
"go.opentelemetry.io/ebpf-profiler/reporter"
44
+
45
+ "github.com/parca-dev/parca-agent/metrics"
46
+ "github.com/parca-dev/parca-agent/reporter/metadata"
45
47
)
46
48
47
49
// Assert that we implement the full Reporter interface.
@@ -117,6 +119,9 @@ type ParcaReporter struct {
117
119
// disableSymbolUpload disables the symbol upload.
118
120
disableSymbolUpload bool
119
121
122
+ // symbolUploadAllowlist is checked before uploading symbols.
123
+ symbolUploadAllowlist []string
124
+
120
125
// reportInterval is the interval at which to report data.
121
126
reportInterval time.Duration
122
127
@@ -167,8 +172,8 @@ func (r *ParcaReporter) SupportsReportTraceEvent() bool { return true }
167
172
168
173
// ReportTraceEvent enqueues reported trace events for the OTLP reporter.
169
174
func (r * ParcaReporter ) ReportTraceEvent (trace * libpf.Trace ,
170
- meta * reporter.TraceEventMeta ) {
171
-
175
+ meta * reporter.TraceEventMeta ,
176
+ ) {
172
177
// This is an LRU so we need to check every time if the stack is already
173
178
// known, as it might have been evicted.
174
179
if _ , exists := r .stacks .Get (trace .Hash ); ! exists {
@@ -266,7 +271,6 @@ func (r *ParcaReporter) ExecutableKnown(fileID libpf.FileID) bool {
266
271
// ExecutableMetadata accepts a fileID with the corresponding filename
267
272
// and caches this information.
268
273
func (r * ParcaReporter ) ExecutableMetadata (args * reporter.ExecutableMetadataArgs ) {
269
-
270
274
if args .Interp != libpf .Native {
271
275
r .executables .Add (args .FileID , metadata.ExecInfo {
272
276
FileName : args .FileName ,
@@ -275,6 +279,20 @@ func (r *ParcaReporter) ExecutableMetadata(args *reporter.ExecutableMetadataArgs
275
279
return
276
280
}
277
281
282
+ if len (r .symbolUploadAllowlist ) > 0 {
283
+ var allowed bool
284
+ for _ , s := range r .symbolUploadAllowlist {
285
+ if strings .Contains (args .FileName , s ) {
286
+ log .Infof ("executable found in allowlist, file: '%s' matches '%s'" , args .FileName , s )
287
+ allowed = true
288
+ break
289
+ }
290
+ }
291
+ if ! allowed {
292
+ log .Debugf ("ignoring executable, not found in allowlist, file: %s" , args .FileName )
293
+ }
294
+ }
295
+
278
296
// Always attempt to upload, the uploader is responsible for deduplication.
279
297
if ! r .disableSymbolUpload {
280
298
r .uploader .Upload (context .TODO (), args .FileID , args .GnuBuildID , args .Open )
@@ -363,8 +381,12 @@ func (r *ParcaReporter) ReportHostMetadata(metadataMap map[string]string) {
363
381
}
364
382
365
383
// ReportHostMetadataBlocking enqueues host metadata.
366
- func (r * ParcaReporter ) ReportHostMetadataBlocking (_ context.Context ,
367
- metadataMap map [string ]string , _ int , _ time.Duration ) error {
384
+ func (r * ParcaReporter ) ReportHostMetadataBlocking (
385
+ _ context.Context ,
386
+ _ map [string ]string ,
387
+ _ int ,
388
+ _ time.Duration ,
389
+ ) error {
368
390
// noop
369
391
return nil
370
392
}
@@ -460,6 +482,7 @@ func New(
460
482
stripTextSection bool ,
461
483
symbolUploadConcurrency int ,
462
484
disableSymbolUpload bool ,
485
+ symbolUploadAllowlist []string ,
463
486
samplesPerSecond int64 ,
464
487
cacheSize uint32 ,
465
488
uploaderQueueSize uint32 ,
@@ -524,21 +547,24 @@ func New(
524
547
reg .MustRegister (sampleWriteRequestBytes )
525
548
reg .MustRegister (stacktraceWriteRequestBytes )
526
549
550
+ slog .Info ("reporter found allowlist" , "list" , symbolUploadAllowlist )
551
+
527
552
r := & ParcaReporter {
528
- stopSignal : make (chan libpf.Void ),
529
- client : nil ,
530
- executables : executables ,
531
- labels : labels ,
532
- frames : frames ,
533
- sampleWriter : NewSampleWriter (mem ),
534
- stacks : stacks ,
535
- mem : mem ,
536
- externalLabels : externalLabels ,
537
- samplesPerSecond : samplesPerSecond ,
538
- disableSymbolUpload : disableSymbolUpload ,
539
- reportInterval : reportInterval ,
540
- nodeName : nodeName ,
541
- relabelConfigs : relabelConfigs ,
553
+ stopSignal : make (chan libpf.Void ),
554
+ client : nil ,
555
+ executables : executables ,
556
+ labels : labels ,
557
+ frames : frames ,
558
+ sampleWriter : NewSampleWriter (mem ),
559
+ stacks : stacks ,
560
+ mem : mem ,
561
+ externalLabels : externalLabels ,
562
+ samplesPerSecond : samplesPerSecond ,
563
+ disableSymbolUpload : disableSymbolUpload ,
564
+ symbolUploadAllowlist : symbolUploadAllowlist ,
565
+ reportInterval : reportInterval ,
566
+ nodeName : nodeName ,
567
+ relabelConfigs : relabelConfigs ,
542
568
metadataProviders : []metadata.MetadataProvider {
543
569
metadata .NewProcessMetadataProvider (),
544
570
metadata .NewMainExecutableMetadataProvider (executables ),
@@ -575,8 +601,10 @@ func New(
575
601
return r , nil
576
602
}
577
603
578
- const DATA_FILE_EXTENSION string = ".padata"
579
- const DATA_FILE_COMPRESSED_EXTENSION string = ".padata.zst"
604
+ const (
605
+ DATA_FILE_EXTENSION string = ".padata"
606
+ DATA_FILE_COMPRESSED_EXTENSION string = ".padata.zst"
607
+ )
580
608
581
609
// initialScan inspects the storage directory to determine its size, and whether there are any
582
610
// uncompressed files lying around.
@@ -615,7 +643,7 @@ func initialScan(storagePath string) (map[string]uint64, []string, uint64, error
615
643
}
616
644
617
645
func compressFile (file io.Reader , fpath , compressedFpath string ) error {
618
- compressedLog , err := os .OpenFile (compressedFpath , os .O_RDWR | os .O_CREATE | os .O_TRUNC , 0660 )
646
+ compressedLog , err := os .OpenFile (compressedFpath , os .O_RDWR | os .O_CREATE | os .O_TRUNC , 0o660 )
619
647
if err != nil {
620
648
return fmt .Errorf ("Failed to create compressed file %s for log rotation: %w" , compressedFpath , err )
621
649
}
@@ -641,7 +669,7 @@ func compressFile(file io.Reader, fpath, compressedFpath string) error {
641
669
642
670
func setupOfflineModeLog (fpath string ) (* os.File , error ) {
643
671
// Open the log file
644
- file , err := os .OpenFile (fpath , os .O_RDWR | os .O_CREATE | os .O_EXCL , 0660 )
672
+ file , err := os .OpenFile (fpath , os .O_RDWR | os .O_CREATE | os .O_EXCL , 0o660 )
645
673
if err != nil {
646
674
return nil , fmt .Errorf ("failed to create new offline mode file %s: %w" , fpath , err )
647
675
}
@@ -661,7 +689,6 @@ func (r *ParcaReporter) rotateOfflineModeLog() error {
661
689
logFile , err := setupOfflineModeLog (fpath )
662
690
if err != nil {
663
691
return fmt .Errorf ("Failed to create new log %s for offline mode: %w" , fpath , err )
664
-
665
692
}
666
693
// We are connected to the new log, let's take the old one and compress it
667
694
r .offlineModeLogMu .Lock ()
@@ -727,7 +754,7 @@ func (r *ParcaReporter) Start(mainCtx context.Context) error {
727
754
}
728
755
729
756
if r .offlineModeConfig != nil {
730
- if err := os .MkdirAll (r .offlineModeConfig .StoragePath , 0770 ); err != nil {
757
+ if err := os .MkdirAll (r .offlineModeConfig .StoragePath , 0o770 ); err != nil {
731
758
return fmt .Errorf ("error creating offline mode storage: %v" , err )
732
759
}
733
760
go func () {
@@ -993,7 +1020,6 @@ func (r *ParcaReporter) reportDataToBackend(ctx context.Context, buf *bytes.Buff
993
1020
}
994
1021
995
1022
rec , err = r .buildStacktraceRecord (ctx , stacktraceIDs )
996
-
997
1023
if err != nil {
998
1024
return err
999
1025
}
0 commit comments