Skip to content

Commit

Permalink
[exporter/signalfx] fix invalid error response message (#12654)
Browse files Browse the repository at this point in the history
Fixing a bug - The signalfx exporter discards metric submission response messages and thus provides invalid error content
  • Loading branch information
rmfitzpatrick authored Jul 25, 2022
1 parent e5dc558 commit 05f3ece
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
6 changes: 4 additions & 2 deletions exporter/signalfxexporter/dpclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,10 @@ func (s *sfxDPClient) pushMetricsDataForToken(ctx context.Context, sfxDataPoints
return len(sfxDataPoints), err
}

io.Copy(ioutil.Discard, resp.Body)
resp.Body.Close()
defer func() {
io.Copy(ioutil.Discard, resp.Body)
resp.Body.Close()
}()

err = splunk.HandleHTTPCode(resp)
if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions exporter/signalfxexporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ func TestConsumeMetrics(t *testing.T) {
wantErr bool
wantPermanentErr bool
wantThrottleErr bool
expectedErrorMsg string
}{
{
name: "happy_path",
Expand All @@ -152,13 +153,15 @@ func TestConsumeMetrics(t *testing.T) {
httpResponseCode: http.StatusForbidden,
numDroppedTimeSeries: 1,
wantErr: true,
expectedErrorMsg: "HTTP 403 \"Forbidden\"",
},
{
name: "response_bad_request",
md: smallBatch,
httpResponseCode: http.StatusBadRequest,
numDroppedTimeSeries: 1,
wantPermanentErr: true,
expectedErrorMsg: "Permanent error: \"HTTP/1.1 400 Bad Request",
},
{
name: "response_throttle",
Expand Down Expand Up @@ -190,6 +193,7 @@ func TestConsumeMetrics(t *testing.T) {
w.Header().Add(splunk.HeaderRetryAfter, strconv.Itoa(tt.retryAfter))
}
w.WriteHeader(tt.httpResponseCode)
w.Write([]byte("response content"))
}))
defer server.Close()

Expand Down Expand Up @@ -219,12 +223,15 @@ func TestConsumeMetrics(t *testing.T) {

if tt.wantErr {
assert.Error(t, err)
assert.EqualError(t, err, tt.expectedErrorMsg)
return
}

if tt.wantPermanentErr {
assert.Error(t, err)
assert.True(t, consumererror.IsPermanent(err))
assert.True(t, strings.HasPrefix(err.Error(), tt.expectedErrorMsg))
assert.Contains(t, err.Error(), "response content")
return
}

Expand Down
5 changes: 5 additions & 0 deletions unreleased/sfxexportearlyrespclose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
change_type: bug_fix
component: signalfxexporter
note: fix invalid response error message
issues: [12654]

0 comments on commit 05f3ece

Please sign in to comment.