Skip to content

Enhancement: Add path to Splunk errors #39026

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
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
27 changes: 27 additions & 0 deletions .chloggen/msg_signalfx-exporter-include-endpoint-in-error.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# 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: signalfxexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Errors will now include the URL that it was trying to access

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [ 39026 ]

# (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: [ user ]
27 changes: 27 additions & 0 deletions .chloggen/msg_splunk-hec-include-endpoint-in-error.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# 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: splunkhecexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Errors will now include the URL that it was trying to access

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [ 39026 ]

# (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: []
56 changes: 37 additions & 19 deletions exporter/signalfxexporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"context"
"crypto/tls"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -122,7 +123,7 @@ func TestConsumeMetrics(t *testing.T) {
wantErr bool
wantPermanentErr bool
wantThrottleErr bool
expectedErrorMsg string
wantStatusCode int
}{
{
name: "happy_path",
Expand All @@ -135,22 +136,23 @@ func TestConsumeMetrics(t *testing.T) {
httpResponseCode: http.StatusForbidden,
numDroppedTimeSeries: 1,
wantErr: true,
expectedErrorMsg: "HTTP 403 \"Forbidden\"",
wantStatusCode: 403,
},
{
name: "response_bad_request",
md: smallBatch,
httpResponseCode: http.StatusBadRequest,
numDroppedTimeSeries: 1,
wantPermanentErr: true,
expectedErrorMsg: "Permanent error: \"HTTP/1.1 400 Bad Request",
wantStatusCode: 400,
},
{
name: "response_throttle",
md: smallBatch,
httpResponseCode: http.StatusTooManyRequests,
numDroppedTimeSeries: 1,
wantThrottleErr: true,
wantStatusCode: 429,
},
{
name: "response_throttle_with_header",
Expand All @@ -159,6 +161,7 @@ func TestConsumeMetrics(t *testing.T) {
httpResponseCode: http.StatusServiceUnavailable,
numDroppedTimeSeries: 1,
wantThrottleErr: true,
wantStatusCode: 503,
},
{
name: "large_batch",
Expand Down Expand Up @@ -207,25 +210,29 @@ func TestConsumeMetrics(t *testing.T) {
converter: c,
}

errMsg := fmt.Sprintf("HTTP \"/v2/datapoint\" %d %q",
tt.wantStatusCode,
http.StatusText(tt.wantStatusCode),
)

numDroppedTimeSeries, err := dpClient.pushMetricsData(context.Background(), tt.md)
assert.Equal(t, tt.numDroppedTimeSeries, numDroppedTimeSeries)

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

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

if tt.wantThrottleErr {
expected := fmt.Errorf("HTTP %d %q", tt.httpResponseCode, http.StatusText(tt.httpResponseCode))
expected := errors.New(errMsg)
expected = exporterhelper.NewThrottleRetry(expected, time.Duration(tt.retryAfter)*time.Second)
assert.EqualValues(t, expected, err)
return
Expand Down Expand Up @@ -1892,8 +1899,8 @@ func TestConsumeMixedMetrics(t *testing.T) {
wantErr bool
wantPermanentErr bool
wantThrottleErr bool
expectedErrorMsg string
wantPartialMetricsErr bool
wantStatusCode int
}{
{
name: "happy_path",
Expand All @@ -1912,15 +1919,15 @@ func TestConsumeMixedMetrics(t *testing.T) {
sfxHTTPResponseCode: http.StatusForbidden,
numDroppedTimeSeries: 1,
wantErr: true,
expectedErrorMsg: "HTTP 403 \"Forbidden\"",
wantStatusCode: 403,
},
{
name: "response_forbidden_otlp",
md: smallBatchHistogramOnly,
otlpHTTPResponseCode: http.StatusForbidden,
numDroppedTimeSeries: 2,
wantErr: true,
expectedErrorMsg: "HTTP 403 \"Forbidden\"",
wantStatusCode: 403,
},
{
name: "response_forbidden_mixed",
Expand All @@ -1929,23 +1936,23 @@ func TestConsumeMixedMetrics(t *testing.T) {
otlpHTTPResponseCode: http.StatusForbidden,
numDroppedTimeSeries: 2,
wantErr: true,
expectedErrorMsg: "HTTP 403 \"Forbidden\"",
wantStatusCode: 403,
},
{
name: "response_bad_request_sfx",
md: smallBatch,
sfxHTTPResponseCode: http.StatusBadRequest,
numDroppedTimeSeries: 1,
wantPermanentErr: true,
expectedErrorMsg: "Permanent error: \"HTTP/1.1 400 Bad Request",
wantStatusCode: 400,
},
{
name: "response_bad_request_otlp",
md: smallBatchHistogramOnly,
otlpHTTPResponseCode: http.StatusBadRequest,
numDroppedTimeSeries: 2,
wantPermanentErr: true,
expectedErrorMsg: "Permanent error: \"HTTP/1.1 400 Bad Request",
wantStatusCode: 400,
},
{
name: "response_bad_request_mixed",
Expand All @@ -1954,14 +1961,15 @@ func TestConsumeMixedMetrics(t *testing.T) {
otlpHTTPResponseCode: http.StatusBadRequest,
numDroppedTimeSeries: 2,
wantPermanentErr: true,
expectedErrorMsg: "Permanent error: \"HTTP/1.1 400 Bad Request",
wantStatusCode: 400,
},
{
name: "response_throttle_sfx",
md: smallBatch,
sfxHTTPResponseCode: http.StatusTooManyRequests,
numDroppedTimeSeries: 1,
wantThrottleErr: true,
wantStatusCode: 429,
},
{
name: "response_throttle_mixed",
Expand All @@ -1971,6 +1979,7 @@ func TestConsumeMixedMetrics(t *testing.T) {
numDroppedTimeSeries: 2,
wantThrottleErr: true,
wantPartialMetricsErr: true,
wantStatusCode: 429,
},
{
name: "response_throttle_otlp",
Expand All @@ -1979,6 +1988,7 @@ func TestConsumeMixedMetrics(t *testing.T) {
numDroppedTimeSeries: 2,
wantThrottleErr: true,
wantPartialMetricsErr: true,
wantStatusCode: 429,
},
{
name: "response_throttle_with_header_sfx",
Expand All @@ -1987,6 +1997,7 @@ func TestConsumeMixedMetrics(t *testing.T) {
sfxHTTPResponseCode: http.StatusServiceUnavailable,
numDroppedTimeSeries: 1,
wantThrottleErr: true,
wantStatusCode: 503,
},
{
name: "response_throttle_with_header_otlp",
Expand All @@ -1996,6 +2007,7 @@ func TestConsumeMixedMetrics(t *testing.T) {
numDroppedTimeSeries: 2,
wantThrottleErr: true,
wantPartialMetricsErr: true,
wantStatusCode: 503,
},
{
name: "response_throttle_with_header_mixed",
Expand All @@ -2006,6 +2018,7 @@ func TestConsumeMixedMetrics(t *testing.T) {
numDroppedTimeSeries: 2,
wantThrottleErr: true,
wantPartialMetricsErr: true,
wantStatusCode: 503,
},
{
name: "large_batch",
Expand Down Expand Up @@ -2065,31 +2078,36 @@ func TestConsumeMixedMetrics(t *testing.T) {
numDroppedTimeSeries, err := sfxClient.pushMetricsData(context.Background(), tt.md)
assert.Equal(t, tt.numDroppedTimeSeries, numDroppedTimeSeries)

errMsg := fmt.Sprintf("HTTP \"/v2/datapoint\" %d %q",
tt.wantStatusCode,
http.StatusText(tt.wantStatusCode),
)

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

if tt.wantPermanentErr {
errMsg = "Permanent error: " + errMsg
assert.Error(t, err)
assert.True(t, consumererror.IsPermanent(err))
assert.True(t, strings.HasPrefix(err.Error(), tt.expectedErrorMsg))
assert.ErrorContains(t, err, "response content")
assert.EqualError(t, err, errMsg)
return
}

if tt.wantThrottleErr {
if tt.wantPartialMetricsErr {
partialMetrics, _ := utils.GetHistograms(smallBatch)
throttleErr := fmt.Errorf("HTTP %d %q", tt.otlpHTTPResponseCode, http.StatusText(tt.otlpHTTPResponseCode))
throttleErr := errors.New(errMsg)
throttleErr = exporterhelper.NewThrottleRetry(throttleErr, time.Duration(tt.retryAfter)*time.Second)
testErr := consumererror.NewMetrics(throttleErr, partialMetrics)
assert.EqualValues(t, testErr, err)
return
}

expected := fmt.Errorf("HTTP %d %q", tt.sfxHTTPResponseCode, http.StatusText(tt.sfxHTTPResponseCode))
expected := errors.New(errMsg)
expected = exporterhelper.NewThrottleRetry(expected, time.Duration(tt.retryAfter)*time.Second)
assert.EqualValues(t, expected, err)
return
Expand Down
18 changes: 12 additions & 6 deletions exporter/splunkhecexporter/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func newTestClientWithPresetResponses(codes []int, bodies []string) (*http.Clien

return &http.Response{
StatusCode: code,
Request: req,
Body: io.NopCloser(bytes.NewBufferString(body)),
Header: make(http.Header),
}
Expand Down Expand Up @@ -1316,7 +1317,11 @@ func TestErrorReceived(t *testing.T) {
case <-time.After(5 * time.Second):
t.Fatal("Should have received request")
}
assert.EqualError(t, err, "HTTP 500 \"Internal Server Error\"")
errMsg := fmt.Sprintf("HTTP \"/services/collector\" %d %q",
http.StatusInternalServerError,
http.StatusText(http.StatusInternalServerError),
)
assert.EqualError(t, err, errMsg)
}

func TestInvalidLogs(t *testing.T) {
Expand Down Expand Up @@ -1394,7 +1399,9 @@ func TestHeartbeatStartupFailed(t *testing.T) {
assert.NoError(t, err)
assert.EqualError(t,
exporter.Start(context.Background(), componenttest.NewNopHost()),
fmt.Sprintf("%s: heartbeat on startup failed: HTTP 403 \"Forbidden\"", params.ID.String()),
fmt.Sprintf("%s: heartbeat on startup failed: HTTP \"/services/collector\" 403 \"Forbidden\"",
params.ID.String(),
),
)
assert.NoError(t, exporter.Shutdown(context.Background()))
}
Expand Down Expand Up @@ -1593,7 +1600,7 @@ func Test_pushLogData_PostError(t *testing.T) {

func Test_pushLogData_ShouldAddResponseTo400Error(t *testing.T) {
config := NewFactory().CreateDefaultConfig().(*Config)
url := &url.URL{Scheme: "http", Host: "splunk"}
url := &url.URL{Scheme: "http", Host: "splunk", Path: "/v1/endpoint"}
splunkClient := newLogsClient(exportertest.NewNopSettings(metadata.Type), NewFactory().CreateDefaultConfig().(*Config))
logs := createLogData(1, 1, 1)

Expand All @@ -1605,17 +1612,16 @@ func Test_pushLogData_ShouldAddResponseTo400Error(t *testing.T) {
// Sending logs using the client.
err := splunkClient.pushLogData(context.Background(), logs)
require.True(t, consumererror.IsPermanent(err), "Expecting permanent error")
require.ErrorContains(t, err, "HTTP/0.0 400")
require.EqualError(t, err, "Permanent error: HTTP \"/v1/endpoint\" 400 \"Bad Request\"")
// The returned error should contain the response body responseBody.
assert.ErrorContains(t, err, responseBody)

// An HTTP client that returns some other status code other than 400 and response body responseBody.
httpClient, _ = newTestClient(500, responseBody)
splunkClient.hecWorker = &defaultHecWorker{url, httpClient, buildHTTPHeaders(config, component.NewDefaultBuildInfo()), zap.NewNop()}
// Sending logs using the client.
err = splunkClient.pushLogData(context.Background(), logs)
require.False(t, consumererror.IsPermanent(err), "Expecting non-permanent error")
require.ErrorContains(t, err, "HTTP 500")
require.EqualError(t, err, "HTTP \"/v1/endpoint\" 500 \"Internal Server Error\"")
// The returned error should not contain the response body responseBody.
assert.NotContains(t, err.Error(), responseBody)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/splunk/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ require (
go.opentelemetry.io/collector/pdata v1.29.0
go.opentelemetry.io/collector/semconv v0.123.0
go.uber.org/goleak v1.3.0
go.uber.org/multierr v1.11.0
)

require (
Expand Down Expand Up @@ -47,6 +46,7 @@ require (
go.opentelemetry.io/otel/metric v1.35.0 // indirect
go.opentelemetry.io/otel/sdk v1.35.0 // indirect
go.opentelemetry.io/otel/trace v1.35.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/net v0.37.0 // indirect
golang.org/x/sys v0.31.0 // indirect
Expand Down
Loading
Loading