Skip to content
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

[exporter/elasticsearch] Extend integration tests to cover traces #32512

Merged
merged 10 commits into from
May 1, 2024
61 changes: 38 additions & 23 deletions exporter/elasticsearchexporter/integrationtest/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package integrationtest

import (
"errors"
"fmt"
"sync/atomic"
"testing"
"time"
Expand All @@ -15,41 +16,55 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/testbed/testbed"
)

func TestLogExporter(t *testing.T) {
for _, tc := range []struct {
name string
// restartCollector restarts the OTEL collector. Restarting
// the collector allows durability testing of the ES exporter
// based on the OTEL config used for testing.
restartCollector bool
mockESFailure bool
}{
{name: "basic"},
{name: "es_intermittent_failure", mockESFailure: true},
/* Below tests should be enabled after https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/30792 is fixed
{name: "collector_restarts", restartCollector: true},
{name: "collector_restart_with_es_intermittent_failure", mockESFailure: true, restartCollector: true},
*/
} {
t.Run(tc.name, func(t *testing.T) {
runner(t, tc.restartCollector, tc.mockESFailure)
})
func TestExporter(t *testing.T) {
for _, eventType := range []string{"logs", "traces"} {
for _, tc := range []struct {
name string
eventType string
lahsivjar marked this conversation as resolved.
Show resolved Hide resolved
// restartCollector restarts the OTEL collector. Restarting
// the collector allows durability testing of the ES exporter
// based on the OTEL config used for testing.
restartCollector bool
mockESFailure bool
}{
{name: "basic"},
{name: "es_intermittent_failure", mockESFailure: true},
/* TODO: Below tests should be enabled after https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/30792 is fixed
{name: "collector_restarts", restartCollector: true},
{name: "collector_restart_with_es_intermittent_failure", mockESFailure: true, restartCollector: true},
*/
} {
t.Run(fmt.Sprintf("%s/%s", eventType, tc.name), func(t *testing.T) {
runner(t, eventType, tc.restartCollector, tc.mockESFailure)
})
}
}
}

func runner(t *testing.T, restartCollector, mockESFailure bool) {
func runner(t *testing.T, eventType string, restartCollector, mockESFailure bool) {
t.Helper()

sender := testbed.NewOTLPLogsDataSender(
testbed.DefaultHost, testutil.GetAvailablePort(t),
var (
sender testbed.DataSender
host = testbed.DefaultHost
port = testutil.GetAvailablePort(t)
)
switch eventType {
case "logs":
sender = testbed.NewOTLPLogsDataSender(host, port)
case "traces":
sender = testbed.NewOTLPTraceDataSender(host, port)
default:
t.Fatalf("failed to create data sender for type: %s", eventType)
}

receiver := newElasticsearchDataReceiver(t)
provider := testbed.NewPerfTestDataProvider(testbed.LoadOptions{
DataItemsPerSecond: 10_000,
ItemsPerBatch: 10,
})

cfg := createConfigYaml(t, sender, receiver, nil, nil, "logs", getDebugFlag(t))
cfg := createConfigYaml(t, sender, receiver, nil, nil, eventType, getDebugFlag(t))
t.Log("test otel collector configuration:", cfg)
collector := newRecreatableOtelCol(t)
cleanup, err := collector.PrepareConfig(cfg)
Expand Down
Loading