From 8d0a5c496a1627aa3e1fd888b20718b9befcac00 Mon Sep 17 00:00:00 2001 From: Nayef Ghattas Date: Thu, 29 Aug 2024 15:03:51 +0000 Subject: [PATCH] reporter: compress uploaded profiles with zstd --- reporter/datadog_reporter.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/reporter/datadog_reporter.go b/reporter/datadog_reporter.go index 332bc2c..5e2e619 100644 --- a/reporter/datadog_reporter.go +++ b/reporter/datadog_reporter.go @@ -18,6 +18,7 @@ import ( "strings" "time" + "github.com/DataDog/zstd" lru "github.com/elastic/go-freelru" pprofile "github.com/google/pprof/profile" log "github.com/sirupsen/logrus" @@ -304,10 +305,14 @@ func (r *DatadogReporter) reportProfile(ctx context.Context) error { } // serialize the profile to a buffer and send it out - var b bytes.Buffer - if err := profile.Write(&b); err != nil { + b := new(bytes.Buffer) + compressed := zstd.NewWriter(b) + if err := profile.WriteUncompressed(compressed); err != nil { return err } + if err := compressed.Close(); err != nil { + return fmt.Errorf("failed to compress profile: %w", err) + } if r.saveCPUProfile { // write profile to cpu.pprof