Skip to content

[exporter/signalfx] fix invalid error response message #12654

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]