From b265c3bf23e37b9bf9bb2649b34303adc546c6d7 Mon Sep 17 00:00:00 2001 From: Damian Murphy Date: Wed, 11 Dec 2024 15:22:41 +1030 Subject: [PATCH 1/4] datadogexporter: read response body on pushSketches --- exporter/datadogexporter/metrics_exporter.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/exporter/datadogexporter/metrics_exporter.go b/exporter/datadogexporter/metrics_exporter.go index ed2938e0a474..3ade5a0eeeda 100644 --- a/exporter/datadogexporter/metrics_exporter.go +++ b/exporter/datadogexporter/metrics_exporter.go @@ -154,6 +154,10 @@ 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 resp.StatusCode >= 400 { return clientutil.WrapError(fmt.Errorf("error when sending payload to %s: %s", sketches.SketchSeriesEndpoint, resp.Status), resp) } From 735bddfaf74b1cef5a7fd0931b81ee4a13754a78 Mon Sep 17 00:00:00 2001 From: Damian Murphy Date: Thu, 12 Dec 2024 10:17:20 +1100 Subject: [PATCH 2/4] Add changelog. --- ...ud_datadogexporter-read-response-body.yaml | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .chloggen/spud_datadogexporter-read-response-body.yaml diff --git a/.chloggen/spud_datadogexporter-read-response-body.yaml b/.chloggen/spud_datadogexporter-read-response-body.yaml new file mode 100644 index 000000000000..c11c5e108ff5 --- /dev/null +++ b/.chloggen/spud_datadogexporter-read-response-body.yaml @@ -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: [] From 7e72de31ec54b134fa97bfaa586b47dca96a76ee Mon Sep 17 00:00:00 2001 From: Damian Murphy Date: Fri, 13 Dec 2024 10:08:09 +1100 Subject: [PATCH 3/4] Missing import. --- exporter/datadogexporter/metrics_exporter.go | 1 + 1 file changed, 1 insertion(+) diff --git a/exporter/datadogexporter/metrics_exporter.go b/exporter/datadogexporter/metrics_exporter.go index 3ade5a0eeeda..e409be241891 100644 --- a/exporter/datadogexporter/metrics_exporter.go +++ b/exporter/datadogexporter/metrics_exporter.go @@ -8,6 +8,7 @@ import ( "context" "errors" "fmt" + "io" "net/http" "sync" "time" From c65bf5e5bec1925921ec70d6094ffe98c64dfdc6 Mon Sep 17 00:00:00 2001 From: Damian Murphy Date: Mon, 16 Dec 2024 12:58:13 +1100 Subject: [PATCH 4/4] Handle error on body read. --- exporter/datadogexporter/metrics_exporter.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/exporter/datadogexporter/metrics_exporter.go b/exporter/datadogexporter/metrics_exporter.go index e409be241891..89d8260eb3c1 100644 --- a/exporter/datadogexporter/metrics_exporter.go +++ b/exporter/datadogexporter/metrics_exporter.go @@ -158,6 +158,9 @@ func (exp *metricsExporter) pushSketches(ctx context.Context, sl sketches.Sketch // 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)