Skip to content

Commit b418e59

Browse files
ben-childs-docusignrapphilmwear
authored
[exporter/prometheusremotewrite] fix snappy double alloc (#34274)
**Description:** Snappy Encode function is not using the buffer passed in by prometheus remote write as it is too small. Removing this unused buffer allocation and just passing nil. Snappy will allocate the required buffers. **Link to tracking Issue:** Fixes #34273 **Testing:** Ran existing unit tests which cover this code Ran this in our integration environment and verified reduced allocations. Before: ![dfce1b99-8998-422e-a9e6-ccc5f6401393](https://github.com/user-attachments/assets/df103b83-48a7-4df7-b9da-c829de02616c) After: ![image](https://github.com/user-attachments/assets/d4dc638c-dab6-4407-b8f1-5ecc24d60435) --------- Co-authored-by: Raphael Philipe Mendes da Silva <[email protected]> Co-authored-by: Matthew Wear <[email protected]>
1 parent 427f72d commit b418e59

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: exporter/prometheusremotewrite
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Reduce unnecessary memory allocation by removing buffer that was not used by Snappy encoding function.
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [34273]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: []

exporter/prometheusremotewriteexporter/exporter.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,9 @@ func (prwe *prwExporter) execute(ctx context.Context, writeReq *prompb.WriteRequ
274274
if errMarshal != nil {
275275
return consumererror.NewPermanent(errMarshal)
276276
}
277-
buf := make([]byte, len(data), cap(data))
278-
compressedData := snappy.Encode(buf, data)
277+
// If we don't pass a buffer large enough, Snappy Encode function will not use it and instead will allocate a new buffer.
278+
// Therefore we always let Snappy decide the size of the buffer.
279+
compressedData := snappy.Encode(nil, data)
279280

280281
// executeFunc can be used for backoff and non backoff scenarios.
281282
executeFunc := func() error {

0 commit comments

Comments
 (0)