Skip to content

Commit

Permalink
[receiver/splunkhecreceiver] Updates Splunk receiver http status code…
Browse files Browse the repository at this point in the history
…s in order to be compliant with SplunkCloud (#14469)

* Updates all StatusAccepted on Splunk Receiver

* Fixes all tests by asserting StatusOK instead of StatusAccepted

* Adds CHANGELOG entry for Splunk HEC Receiver changes regarding http status codes

* Update splunkhecreceiver-http-status-code-return.yaml

Co-authored-by: Bogdan Drutu <lazy@splunk.com>
  • Loading branch information
pantuza and Bogdan Drutu authored Sep 28, 2022
1 parent 60fb9d3 commit d3cc2dd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
6 changes: 3 additions & 3 deletions receiver/splunkhecreceiver/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func (r *splunkReceiver) handleRawReq(resp http.ResponseWriter, req *http.Reques
if consumerErr != nil {
r.failRequest(ctx, resp, http.StatusInternalServerError, errInternalServerError, sl.LogRecords().Len(), consumerErr)
} else {
resp.WriteHeader(http.StatusAccepted)
resp.WriteHeader(http.StatusOK)
r.obsrecv.EndLogsOp(ctx, typeStr, sl.LogRecords().Len(), nil)
}
}
Expand Down Expand Up @@ -359,7 +359,7 @@ func (r *splunkReceiver) consumeMetrics(ctx context.Context, events []*splunk.Ev
if decodeErr != nil {
r.failRequest(ctx, resp, http.StatusInternalServerError, errInternalServerError, len(events), decodeErr)
} else {
resp.WriteHeader(http.StatusAccepted)
resp.WriteHeader(http.StatusOK)
_, err := resp.Write(okRespBody)
if err != nil {
r.failRequest(ctx, resp, http.StatusInternalServerError, errInternalServerError, len(events), err)
Expand All @@ -380,7 +380,7 @@ func (r *splunkReceiver) consumeLogs(ctx context.Context, events []*splunk.Event
if decodeErr != nil {
r.failRequest(ctx, resp, http.StatusInternalServerError, errInternalServerError, len(events), decodeErr)
} else {
resp.WriteHeader(http.StatusAccepted)
resp.WriteHeader(http.StatusOK)
if _, err := resp.Write(okRespBody); err != nil {
r.failRequest(ctx, resp, http.StatusInternalServerError, errInternalServerError, len(events), err)
}
Expand Down
22 changes: 11 additions & 11 deletions receiver/splunkhecreceiver/receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func Test_splunkhecReceiver_handleReq(t *testing.T) {
return req
}(),
assertResponse: func(t *testing.T, status int, body string) {
assert.Equal(t, http.StatusAccepted, status)
assert.Equal(t, http.StatusOK, status)
assert.Equal(t, responseOK, body)
},
},
Expand All @@ -275,7 +275,7 @@ func Test_splunkhecReceiver_handleReq(t *testing.T) {
return req
}(),
assertResponse: func(t *testing.T, status int, body string) {
assert.Equal(t, http.StatusAccepted, status)
assert.Equal(t, http.StatusOK, status)
assert.Equal(t, responseOK, body)
},
},
Expand Down Expand Up @@ -439,7 +439,7 @@ func Test_splunkhecReceiver_TLS(t *testing.T) {

resp, err := client.Do(req)
require.NoErrorf(t, err, "should not have failed when sending to splunk HEC receiver %v", err)
assert.Equal(t, http.StatusAccepted, resp.StatusCode)
assert.Equal(t, http.StatusOK, resp.StatusCode)
t.Log("Splunk HEC Request Received")

got := sink.AllLogs()
Expand Down Expand Up @@ -519,7 +519,7 @@ func Test_splunkhecReceiver_AccessTokenPassthrough(t *testing.T) {
endServer := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
_, err := io.Copy(io.Discard, req.Body)
assert.NoError(t, err)
rw.WriteHeader(http.StatusAccepted)
rw.WriteHeader(http.StatusOK)
accessTokensChan <- req.Header.Get("Authorization")
}))
defer endServer.Close()
Expand Down Expand Up @@ -619,7 +619,7 @@ func Test_Logs_splunkhecReceiver_IndexSourceTypePassthrough(t *testing.T) {
endServer := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
body, err := io.ReadAll(req.Body)
assert.NoError(t, err)
rw.WriteHeader(http.StatusAccepted)
rw.WriteHeader(http.StatusOK)
receivedSplunkLogs <- body
}))
defer endServer.Close()
Expand Down Expand Up @@ -671,7 +671,7 @@ func Test_Logs_splunkhecReceiver_IndexSourceTypePassthrough(t *testing.T) {
assert.NoError(t, err)
var bodyStr string
assert.NoError(t, json.Unmarshal(respBytes, &bodyStr))
assert.Equal(t, http.StatusAccepted, resp.StatusCode)
assert.Equal(t, http.StatusOK, resp.StatusCode)
assert.Equal(t, responseOK, bodyStr)
select {
case <-done:
Expand Down Expand Up @@ -712,7 +712,7 @@ func Test_Metrics_splunkhecReceiver_IndexSourceTypePassthrough(t *testing.T) {
endServer := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
body, err := io.ReadAll(req.Body)
assert.NoError(t, err)
rw.WriteHeader(http.StatusAccepted)
rw.WriteHeader(http.StatusOK)
receivedSplunkMetrics <- body
}))
defer endServer.Close()
Expand Down Expand Up @@ -765,7 +765,7 @@ func Test_Metrics_splunkhecReceiver_IndexSourceTypePassthrough(t *testing.T) {
assert.NoError(t, err)
var bodyStr string
assert.NoError(t, json.Unmarshal(respBytes, &bodyStr))
assert.Equal(t, http.StatusAccepted, resp.StatusCode)
assert.Equal(t, http.StatusOK, resp.StatusCode)
assert.Equal(t, responseOK, bodyStr)
select {
case <-done:
Expand Down Expand Up @@ -899,7 +899,7 @@ func Test_splunkhecReceiver_handleRawReq(t *testing.T) {
return req
}(),
assertResponse: func(t *testing.T, status int, body string) {
assert.Equal(t, http.StatusAccepted, status)
assert.Equal(t, http.StatusOK, status)
},
},
{
Expand All @@ -911,7 +911,7 @@ func Test_splunkhecReceiver_handleRawReq(t *testing.T) {
return req
}(),
assertResponse: func(t *testing.T, status int, body string) {
assert.Equal(t, http.StatusAccepted, status)
assert.Equal(t, http.StatusOK, status)
},
},
{
Expand All @@ -931,7 +931,7 @@ func Test_splunkhecReceiver_handleRawReq(t *testing.T) {
return req
}(),
assertResponse: func(t *testing.T, status int, body string) {
assert.Equal(t, http.StatusAccepted, status)
assert.Equal(t, http.StatusOK, status)
},
},
{
Expand Down
11 changes: 11 additions & 0 deletions unreleased/splunkhecreceiver-http-status-code-return.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

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

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Updates Splunk receiver http status codes in order to be compliant with SplunkCloud

# One or more tracking issues related to the change
issues: [14469]

0 comments on commit d3cc2dd

Please sign in to comment.