Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uploads: update compression to zstd #53

Merged
merged 2 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.22.2

require (
cloud.google.com/go/compute/metadata v0.3.0
github.com/DataDog/zstd v1.5.7-0.20240809173922-01236a179a11
github.com/aws/aws-sdk-go-v2/config v1.27.21
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.8
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ github.com/AdamKorcz/go-118-fuzz-build v0.0.0-20230306123547-8075edf89bb0/go.mod
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8=
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/DataDog/zstd v1.5.7-0.20240809173922-01236a179a11 h1:6YQbimbKhZdYzmxeK86+enPpwE1QzXD6txp5CkE5kI8=
github.com/DataDog/zstd v1.5.7-0.20240809173922-01236a179a11/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw=
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
github.com/Microsoft/hcsshim v0.11.5 h1:haEcLNpj9Ka1gd3B3tAEs9CpE0c+1IhoL59w/exYU38=
Expand Down
9 changes: 7 additions & 2 deletions reporter/datadog_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions symbolication/datadog_uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package symbolication

import (
"bytes"
"compress/gzip"
"context"
"encoding/json"
"errors"
Expand All @@ -19,6 +18,7 @@ import (
"strings"
"time"

"github.com/DataDog/zstd"
lru "github.com/elastic/go-freelru"
log "github.com/sirupsen/logrus"

Expand Down Expand Up @@ -268,9 +268,9 @@ func (d *DatadogUploader) buildSymbolUploadRequest(symbolFile *os.File,
e *executableMetadata) (*http.Request, error) {
b := new(bytes.Buffer)

gzipped := gzip.NewWriter(b)
compressed := zstd.NewWriter(b)

mw := multipart.NewWriter(gzipped)
mw := multipart.NewWriter(compressed)

// Copy the symbol file into the multipart writer
filePart, err := mw.CreateFormFile("elf_symbol_file", "elf_symbol_file")
Expand All @@ -297,15 +297,15 @@ func (d *DatadogUploader) buildSymbolUploadRequest(symbolFile *os.File,
return nil, fmt.Errorf("failed to write JSON metadata: %w", err)
}

// Close the multipart writer then the gzip writer
// Close the multipart writer then the zstd writer
err = mw.Close()
if err != nil {
return nil, fmt.Errorf("failed to close multipart writer: %w", err)
}

err = gzipped.Close()
err = compressed.Close()
if err != nil {
return nil, fmt.Errorf("failed to close gzip writer: %w", err)
return nil, fmt.Errorf("failed to close zstd writer: %w", err)
}

r, err := http.NewRequest(http.MethodPost, d.intakeURL, b)
Expand All @@ -317,7 +317,7 @@ func (d *DatadogUploader) buildSymbolUploadRequest(symbolFile *os.File,
r.Header.Set("Dd-Evp-Origin", "otel-profiling-agent")
r.Header.Set("Dd-Evp-Origin-Version", vc.Version())
r.Header.Set("Content-Type", mw.FormDataContentType())
r.Header.Set("Content-Encoding", "gzip")
r.Header.Set("Content-Encoding", "zstd")
return r, nil
}

Expand Down