Skip to content

Commit f34a22f

Browse files
committed
Including SplunkHec as the result
1 parent 6bb18d9 commit f34a22f

File tree

4 files changed

+68
-6
lines changed

4 files changed

+68
-6
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: signalfxexporter
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Errors will now include the URL that it was trying to access
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [ 39026 ]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [ user ]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: splunkhecexporter
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Errors will now include the URL that it was trying to access
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [ 39026 ]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: []

exporter/splunkhecexporter/client_test.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ func newTestClientWithPresetResponses(codes []int, bodies []string) (*http.Clien
6666

6767
return &http.Response{
6868
StatusCode: code,
69+
Request: req,
6970
Body: io.NopCloser(bytes.NewBufferString(body)),
7071
Header: make(http.Header),
7172
}
@@ -1316,7 +1317,12 @@ func TestErrorReceived(t *testing.T) {
13161317
case <-time.After(5 * time.Second):
13171318
t.Fatal("Should have received request")
13181319
}
1319-
assert.EqualError(t, err, "HTTP 500 \"Internal Server Error\"")
1320+
errMsg := fmt.Sprintf("HTTP %q %d %q",
1321+
cfg.ClientConfig.Endpoint,
1322+
http.StatusInternalServerError,
1323+
http.StatusText(http.StatusInternalServerError),
1324+
)
1325+
assert.EqualError(t, err, errMsg)
13201326
}
13211327

13221328
func TestInvalidLogs(t *testing.T) {
@@ -1394,7 +1400,10 @@ func TestHeartbeatStartupFailed(t *testing.T) {
13941400
assert.NoError(t, err)
13951401
assert.EqualError(t,
13961402
exporter.Start(context.Background(), componenttest.NewNopHost()),
1397-
fmt.Sprintf("%s: heartbeat on startup failed: HTTP 403 \"Forbidden\"", params.ID.String()),
1403+
fmt.Sprintf("%s: heartbeat on startup failed: HTTP %q 403 \"Forbidden\"",
1404+
params.ID.String(),
1405+
cfg.ClientConfig.Endpoint,
1406+
),
13981407
)
13991408
assert.NoError(t, exporter.Shutdown(context.Background()))
14001409
}
@@ -1605,17 +1614,16 @@ func Test_pushLogData_ShouldAddResponseTo400Error(t *testing.T) {
16051614
// Sending logs using the client.
16061615
err := splunkClient.pushLogData(context.Background(), logs)
16071616
require.True(t, consumererror.IsPermanent(err), "Expecting permanent error")
1608-
require.ErrorContains(t, err, "HTTP/0.0 400")
1617+
require.EqualError(t, err, "Permanent error: HTTP \"http://splunk\" 400 \"Bad Request\"")
16091618
// The returned error should contain the response body responseBody.
1610-
assert.ErrorContains(t, err, responseBody)
16111619

16121620
// An HTTP client that returns some other status code other than 400 and response body responseBody.
16131621
httpClient, _ = newTestClient(500, responseBody)
16141622
splunkClient.hecWorker = &defaultHecWorker{url, httpClient, buildHTTPHeaders(config, component.NewDefaultBuildInfo()), zap.NewNop()}
16151623
// Sending logs using the client.
16161624
err = splunkClient.pushLogData(context.Background(), logs)
16171625
require.False(t, consumererror.IsPermanent(err), "Expecting non-permanent error")
1618-
require.ErrorContains(t, err, "HTTP 500")
1626+
require.EqualError(t, err, "HTTP \"http://splunk\" 500 \"Internal Server Error\"")
16191627
// The returned error should not contain the response body responseBody.
16201628
assert.NotContains(t, err.Error(), responseBody)
16211629
}

internal/splunk/httprequest.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const HeaderRetryAfter = "Retry-After"
1818
// HandleHTTPCode handles an http response and returns the right type of error in case of a failure.
1919
func HandleHTTPCode(resp *http.Response) error {
2020
// Splunk accepts all 2XX codes.
21-
if resp.StatusCode/100 == 2 {
21+
if resp.StatusCode >= http.StatusOK && resp.StatusCode < http.StatusMultipleChoices {
2222
return nil
2323
}
2424

0 commit comments

Comments
 (0)