Skip to content
Merged
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
37 changes: 33 additions & 4 deletions exporter/splunkhecexporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package splunkhecexporter

import (
"bytes"
"compress/gzip"
"context"
"encoding/json"
"io"
Expand Down Expand Up @@ -89,6 +91,7 @@ func TestConsumeMetricsData(t *testing.T) {
md pmetric.Metrics
reqTestFunc func(t *testing.T, r *http.Request)
httpResponseCode int
maxContentLength int
wantErr bool
}{
{
Expand Down Expand Up @@ -127,9 +130,33 @@ func TestConsumeMetricsData(t *testing.T) {
wantErr: true,
},
{
name: "large_batch",
md: generateLargeBatch(),
reqTestFunc: nil,
name: "large_batch",
md: generateLargeBatch(),
reqTestFunc: func(t *testing.T, r *http.Request) {
body, err := io.ReadAll(r.Body)
if err != nil {
t.Fatal(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)
}
assert.Equal(t, "test_splunk", metric.Source)
assert.Equal(t, "test_type", metric.SourceType)
assert.Equal(t, "test_index", metric.Index)

},
maxContentLength: 1800,
httpResponseCode: http.StatusAccepted,
},
}
Expand Down Expand Up @@ -158,6 +185,7 @@ func TestConsumeMetricsData(t *testing.T) {
config.Index = "test_index"
config.SplunkAppName = "OpenTelemetry-Collector Splunk Exporter"
config.SplunkAppVersion = "v0.0.1"
config.MaxContentLengthMetrics = 1800

sender, err := buildClient(options, config, zap.NewNop())
assert.NoError(t, err)
Expand All @@ -178,9 +206,10 @@ func generateLargeBatch() pmetric.Metrics {
metrics := pmetric.NewMetrics()
rm := metrics.ResourceMetrics().AppendEmpty()
rm.Resource().Attributes().PutStr(conventions.AttributeServiceName, "test_splunkhec")
rm.Resource().Attributes().PutStr(splunk.DefaultSourceLabel, "test_splunk")
ms := rm.ScopeMetrics().AppendEmpty().Metrics()

for i := 0; i < 65000; i++ {
for i := 0; i < 6500; i++ {
m := ms.AppendEmpty()
m.SetName("test_" + strconv.Itoa(i))
dp := m.SetEmptyGauge().DataPoints().AppendEmpty()
Expand Down