-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
[chore] [exporter/splunkhec] fix flaky test expecting all requests to be gzipped. #17178
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5994b76
do not close the body of the request explicitly as net/http does that…
atoulme a18a1e3
fix flaky test, make sure we catch that we have a dirty buffer
atoulme 5570c7d
remove the loop to run the export 100 times
atoulme a5ee6b7
simplify close logic
atoulme 751429c
remove closed flag and fix govet error
atoulme b841b19
remove changelog entry
atoulme File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ import ( | |
"compress/gzip" | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"net" | ||
"net/http" | ||
|
@@ -158,7 +159,7 @@ func TestConsumeMetricsData(t *testing.T) { | |
md pmetric.Metrics | ||
reqTestFunc func(t *testing.T, r *http.Request) | ||
httpResponseCode int | ||
maxContentLength int | ||
maxContentLength uint | ||
wantErr bool | ||
}{ | ||
{ | ||
|
@@ -201,23 +202,28 @@ func TestConsumeMetricsData(t *testing.T) { | |
md: generateLargeBatch(), | ||
reqTestFunc: func(t *testing.T, r *http.Request) { | ||
body, err := io.ReadAll(r.Body) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
assert.NoError(t, err) | ||
assert.Equal(t, "keep-alive", r.Header.Get("Connection")) | ||
assert.Equal(t, "application/json", r.Header.Get("Content-Type")) | ||
assert.Equal(t, "OpenTelemetry-Collector Splunk Exporter/v0.0.1", r.Header.Get("User-Agent")) | ||
assert.Equal(t, "Splunk 1234", r.Header.Get("Authorization")) | ||
assert.Equal(t, "gzip", r.Header.Get("Content-Encoding")) | ||
zipReader, err := gzip.NewReader(bytes.NewReader(body)) | ||
assert.NoError(t, err) | ||
bodyBytes, _ := io.ReadAll(zipReader) | ||
firstPayload := strings.Split(string(bodyBytes), "}{")[0] | ||
var metric splunk.Event | ||
err = json.Unmarshal([]byte(firstPayload+"}"), &metric) | ||
if err != nil { | ||
t.Fatal(err) | ||
bodyBytes := body | ||
// the last batch might not be zipped. | ||
if "gzip" == r.Header.Get("Content-Encoding") { | ||
zipReader, err2 := gzip.NewReader(bytes.NewReader(body)) | ||
require.NoError(t, err2) | ||
bodyBytes, _ = io.ReadAll(zipReader) | ||
} | ||
|
||
events := strings.Split(string(bodyBytes), "}{") | ||
firstPayload := events[0] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also sometimes the last batch had just one event. We fix it here by doing a better job separating HEC events. |
||
if len(events) > 1 { | ||
firstPayload += "}" | ||
} | ||
|
||
var metric splunk.Event | ||
err = json.Unmarshal([]byte(firstPayload), &metric) | ||
assert.NoError(t, err, fmt.Sprintf("could not read: %s", firstPayload)) | ||
assert.Equal(t, "test_splunk", metric.Source) | ||
assert.Equal(t, "test_type", metric.SourceType) | ||
assert.Equal(t, "test_index", metric.Index) | ||
|
@@ -252,7 +258,7 @@ func TestConsumeMetricsData(t *testing.T) { | |
config.Index = "test_index" | ||
config.SplunkAppName = "OpenTelemetry-Collector Splunk Exporter" | ||
config.SplunkAppVersion = "v0.0.1" | ||
config.MaxContentLengthMetrics = 1800 | ||
config.MaxContentLengthMetrics = tt.maxContentLength | ||
|
||
sender, err := buildClient(options, config, zap.NewNop()) | ||
assert.NoError(t, err) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this created flakiness. Sometimes the last request sent by the batch was not gzipped. We account for it.