Skip to content

Commit

Permalink
datadogexporter: read response body on pushSketches (#36779)
Browse files Browse the repository at this point in the history
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description

The pushSketches function in the datadogexporter does not read the
contents of the HTTP response's Body on return.

The Go documentation states that the full response body from the http
request should be read and closed to ensure that connections can be
properly re-used: https://pkg.go.dev/net/http#Client.Do

We saw this manifest as a high load of incoming metric traffic through
the exporter creating a connection per request and essentially killing
platform infrastructure (proxy, DNS) as a result.


<!--Describe what testing was performed and which tests were added.-->
#### Testing

No additional testing added. Fix is running to great effect in private
internal fork at extremely high scale.
  • Loading branch information
spudlymurf authored Dec 16, 2024
1 parent 7502a1e commit 9aadead
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
28 changes: 28 additions & 0 deletions .chloggen/spud_datadogexporter-read-response-body.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: datadogexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: read response body on pushSketches to allow connection re-use

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues:
- 36779

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
8 changes: 8 additions & 0 deletions exporter/datadogexporter/metrics_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"context"
"errors"
"fmt"
"io"
"net/http"
"sync"
"time"
Expand Down Expand Up @@ -154,6 +155,13 @@ func (exp *metricsExporter) pushSketches(ctx context.Context, sl sketches.Sketch
}
defer resp.Body.Close()

// We must read the full response body from the http request to ensure that connections can be
// properly re-used. https://pkg.go.dev/net/http#Client.Do
_, err = io.Copy(io.Discard, resp.Body)
if err != nil {
return clientutil.WrapError(fmt.Errorf("failed to read response body from sketches HTTP request: %w", err), resp)
}

if resp.StatusCode >= 400 {
return clientutil.WrapError(fmt.Errorf("error when sending payload to %s: %s", sketches.SketchSeriesEndpoint, resp.Status), resp)
}
Expand Down

0 comments on commit 9aadead

Please sign in to comment.