Skip to content

[exporter/prometheusremotewrite] Double allocation in execute function due to snappy buffer size mismatch #34273

Closed
@ben-childs-docusign

Description

@ben-childs-docusign

Component(s)

exporter/prometheusremotewrite

What happened?

Description

We observed extra allocations in the execute function due to a mismatch between the buffer size passed into snappy and the buffer size that snappy needs to handle the worst case compression outcome.

Specifically this code in snappy generates a buffer size > the size of the input buffer:
https://github.com/golang/snappy/blob/master/encode.go#L24

But the buffer allocated and passed into snappy is only equal to the size of our input buffer:
https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/exporter/prometheusremotewriteexporter/exporter.go#L277

Therefore snappy ends up allocating an extra buffer and the buffer allocated by prometheus remote write is unused.

Solution is to just not pre-allocate the buffer and pass nil which is valid per the snappy documentation.

This double allocation is responsible for ~10% of overall allocations in our otel collector after fixing
#34269
dfce1b99-8998-422e-a9e6-ccc5f6401393

Steps to Reproduce

Use go tool pprof to profile memory allocations of the prometheus remote write exporter

Expected Result

Compression allocates a single buffer to handle the export

Actual Result

We allocate an extra buffer in execute which then does not get used by the snappy function.

Collector version

v0.101.0

Environment information

Environment

OS: (e.g., "Ubuntu 20.04")
Compiler(if manually compiled): (e.g., "go 14.2")

OpenTelemetry Collector configuration

No response

Log output

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions