Skip to content

Commit

Permalink
[chore] clean up testbed (#291)
Browse files Browse the repository at this point in the history
Signed-off-by: odubajDT <[email protected]>
  • Loading branch information
odubajDT authored Sep 10, 2024
1 parent 7008c52 commit bd192a5
Show file tree
Hide file tree
Showing 11 changed files with 145 additions and 271 deletions.
2 changes: 1 addition & 1 deletion internal/testbed/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ require (
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/collector/component v0.108.1
go.opentelemetry.io/collector/consumer/consumertest v0.108.1
go.opentelemetry.io/collector/featuregate v1.14.1
go.opentelemetry.io/collector/pdata v1.14.1
go.opentelemetry.io/collector/semconv v0.108.1
gopkg.in/yaml.v3 v3.0.1
Expand Down Expand Up @@ -169,6 +168,7 @@ require (
go.opentelemetry.io/collector/extension v0.108.1 // indirect
go.opentelemetry.io/collector/extension/auth v0.108.1 // indirect
go.opentelemetry.io/collector/extension/zpagesextension v0.108.1 // indirect
go.opentelemetry.io/collector/featuregate v1.14.1 // indirect
go.opentelemetry.io/collector/internal/globalgates v0.108.1 // indirect
go.opentelemetry.io/collector/otelcol v0.108.1 // indirect
go.opentelemetry.io/collector/pdata/pprofile v0.108.1 // indirect
Expand Down
109 changes: 55 additions & 54 deletions internal/testbed/integration/config_examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,24 @@ import (
"go.opentelemetry.io/collector/pdata/ptrace"
semconv "go.opentelemetry.io/collector/semconv/v1.18.0"

"github.com/Dynatrace/dynatrace-otel-collector/internal/testbed/testutil"
"github.com/Dynatrace/dynatrace-otel-collector/internal/testcommon/idutils"
"github.com/Dynatrace/dynatrace-otel-collector/internal/testcommon/testutil"
)

const ConfigExamplesDir = "../../../config_examples"

func TestConfigTailSampling(t *testing.T) {
// arrange
col := testbed.NewChildProcessCollector(testbed.WithAgentExePath(CollectorTestsExecPath))
col := testbed.NewChildProcessCollector(testbed.WithAgentExePath(testutil.CollectorTestsExecPath))
cfg, err := os.ReadFile(path.Join(ConfigExamplesDir, "tail_sampling.yaml"))
require.NoError(t, err)

receiverPort := testutil.GetAvailablePort(t)
exporterPort := testutil.GetAvailablePort(t)

parsedConfig := string(cfg)
parsedConfig = replaceOtlpGrpcReceiverPort(parsedConfig, receiverPort)
parsedConfig = replaceDynatraceExporterEndpoint(parsedConfig, exporterPort)
parsedConfig = testutil.ReplaceOtlpGrpcReceiverPort(parsedConfig, receiverPort)
parsedConfig = testutil.ReplaceDynatraceExporterEndpoint(parsedConfig, exporterPort)

// replaces the sampling decision wait so the test doesn't timeout
parsedConfig = strings.Replace(parsedConfig, "decision_wait: 30s", "decision_wait: 10ms", 1)
Expand All @@ -50,8 +51,8 @@ func TestConfigTailSampling(t *testing.T) {

// Error ers
ers := actualSpans.AppendEmpty()
ers.SetTraceID(uInt64ToTraceID(0, uint64(1)))
ers.SetSpanID(uInt64ToSpanID(uint64(1)))
ers.SetTraceID(idutils.UInt64ToTraceID(0, uint64(1)))
ers.SetSpanID(idutils.UInt64ToSpanID(uint64(1)))
ers.SetName("Error span")
ers.SetKind(ptrace.SpanKindServer)
ers.Status().SetCode(ptrace.StatusCodeError)
Expand All @@ -60,8 +61,8 @@ func TestConfigTailSampling(t *testing.T) {

// Ok span
oks := actualSpans.AppendEmpty()
oks.SetTraceID(uInt64ToTraceID(0, uint64(2)))
oks.SetSpanID(uInt64ToSpanID(uint64(2)))
oks.SetTraceID(idutils.UInt64ToTraceID(0, uint64(2)))
oks.SetSpanID(idutils.UInt64ToSpanID(uint64(2)))
oks.SetName("OK span")
oks.SetKind(ptrace.SpanKindServer)
oks.Status().SetCode(ptrace.StatusCodeOk)
Expand All @@ -70,8 +71,8 @@ func TestConfigTailSampling(t *testing.T) {

// Long-running span
lrs := actualSpans.AppendEmpty()
lrs.SetTraceID(uInt64ToTraceID(0, uint64(3)))
lrs.SetSpanID(uInt64ToSpanID(uint64(3)))
lrs.SetTraceID(idutils.UInt64ToTraceID(0, uint64(3)))
lrs.SetSpanID(idutils.UInt64ToSpanID(uint64(3)))
lrs.SetName("Long-running span")
lrs.SetKind(ptrace.SpanKindServer)
lrs.Status().SetCode(ptrace.StatusCodeOk)
Expand Down Expand Up @@ -120,16 +121,16 @@ func TestConfigTailSampling(t *testing.T) {

func TestConfigJaegerGrpc(t *testing.T) {
// arrange
col := testbed.NewChildProcessCollector(testbed.WithAgentExePath(CollectorTestsExecPath))
col := testbed.NewChildProcessCollector(testbed.WithAgentExePath(testutil.CollectorTestsExecPath))
cfg, err := os.ReadFile(path.Join(ConfigExamplesDir, "jaeger.yaml"))
require.NoError(t, err)

grpcReceiverPort := testutil.GetAvailablePort(t)
exporterPort := testutil.GetAvailablePort(t)

parsedConfig := string(cfg)
parsedConfig = replaceJaegerGrpcReceiverPort(parsedConfig, grpcReceiverPort)
parsedConfig = replaceDynatraceExporterEndpoint(parsedConfig, exporterPort)
parsedConfig = testutil.ReplaceJaegerGrpcReceiverPort(parsedConfig, grpcReceiverPort)
parsedConfig = testutil.ReplaceDynatraceExporterEndpoint(parsedConfig, exporterPort)

configCleanup, err := col.PrepareConfig(parsedConfig)
require.NoError(t, err)
Expand All @@ -144,8 +145,8 @@ func TestConfigJaegerGrpc(t *testing.T) {

// Error ers
ers := actualSpans.AppendEmpty()
ers.SetTraceID(uInt64ToTraceID(0, uint64(1)))
ers.SetSpanID(uInt64ToSpanID(uint64(1)))
ers.SetTraceID(idutils.UInt64ToTraceID(0, uint64(1)))
ers.SetSpanID(idutils.UInt64ToSpanID(uint64(1)))
ers.SetName("Error span")
ers.SetKind(ptrace.SpanKindServer)
ers.Status().SetCode(ptrace.StatusCodeError)
Expand All @@ -154,8 +155,8 @@ func TestConfigJaegerGrpc(t *testing.T) {

// Ok span
oks := actualSpans.AppendEmpty()
oks.SetTraceID(uInt64ToTraceID(0, uint64(2)))
oks.SetSpanID(uInt64ToSpanID(uint64(2)))
oks.SetTraceID(idutils.UInt64ToTraceID(0, uint64(2)))
oks.SetSpanID(idutils.UInt64ToSpanID(uint64(2)))
oks.SetName("OK span")
oks.SetKind(ptrace.SpanKindServer)
oks.Status().SetCode(ptrace.StatusCodeOk)
Expand All @@ -164,8 +165,8 @@ func TestConfigJaegerGrpc(t *testing.T) {

// Long-running span
lrs := actualSpans.AppendEmpty()
lrs.SetTraceID(uInt64ToTraceID(0, uint64(3)))
lrs.SetSpanID(uInt64ToSpanID(uint64(3)))
lrs.SetTraceID(idutils.UInt64ToTraceID(0, uint64(3)))
lrs.SetSpanID(idutils.UInt64ToSpanID(uint64(3)))
lrs.SetName("Long-running span")
lrs.SetKind(ptrace.SpanKindServer)
lrs.Status().SetCode(ptrace.StatusCodeOk)
Expand Down Expand Up @@ -213,16 +214,16 @@ func TestConfigJaegerGrpc(t *testing.T) {

func TestConfigZipkin(t *testing.T) {
// arrange
col := testbed.NewChildProcessCollector(testbed.WithAgentExePath(CollectorTestsExecPath))
col := testbed.NewChildProcessCollector(testbed.WithAgentExePath(testutil.CollectorTestsExecPath))
cfg, err := os.ReadFile(path.Join(ConfigExamplesDir, "zipkin.yaml"))
require.NoError(t, err)

zipkinReceiverPort := testutil.GetAvailablePort(t)
exporterPort := testutil.GetAvailablePort(t)

parsedConfig := string(cfg)
parsedConfig = replaceZipkinReceiverPort(parsedConfig, zipkinReceiverPort)
parsedConfig = replaceDynatraceExporterEndpoint(parsedConfig, exporterPort)
parsedConfig = testutil.ReplaceZipkinReceiverPort(parsedConfig, zipkinReceiverPort)
parsedConfig = testutil.ReplaceDynatraceExporterEndpoint(parsedConfig, exporterPort)

configCleanup, err := col.PrepareConfig(parsedConfig)
require.NoError(t, err)
Expand All @@ -237,8 +238,8 @@ func TestConfigZipkin(t *testing.T) {

// Error ers
ers := actualSpans.AppendEmpty()
ers.SetTraceID(uInt64ToTraceID(0, uint64(1)))
ers.SetSpanID(uInt64ToSpanID(uint64(1)))
ers.SetTraceID(idutils.UInt64ToTraceID(0, uint64(1)))
ers.SetSpanID(idutils.UInt64ToSpanID(uint64(1)))
ers.SetName("Error span")
ers.SetKind(ptrace.SpanKindServer)
ers.Status().SetCode(ptrace.StatusCodeError)
Expand All @@ -247,8 +248,8 @@ func TestConfigZipkin(t *testing.T) {

// Ok span
oks := actualSpans.AppendEmpty()
oks.SetTraceID(uInt64ToTraceID(0, uint64(2)))
oks.SetSpanID(uInt64ToSpanID(uint64(2)))
oks.SetTraceID(idutils.UInt64ToTraceID(0, uint64(2)))
oks.SetSpanID(idutils.UInt64ToSpanID(uint64(2)))
oks.SetName("OK span")
oks.SetKind(ptrace.SpanKindServer)
oks.Status().SetCode(ptrace.StatusCodeOk)
Expand All @@ -257,8 +258,8 @@ func TestConfigZipkin(t *testing.T) {

// Long-running span
lrs := actualSpans.AppendEmpty()
lrs.SetTraceID(uInt64ToTraceID(0, uint64(3)))
lrs.SetSpanID(uInt64ToSpanID(uint64(3)))
lrs.SetTraceID(idutils.UInt64ToTraceID(0, uint64(3)))
lrs.SetSpanID(idutils.UInt64ToSpanID(uint64(3)))
lrs.SetName("Long-running span")
lrs.SetKind(ptrace.SpanKindServer)
lrs.Status().SetCode(ptrace.StatusCodeOk)
Expand Down Expand Up @@ -306,16 +307,16 @@ func TestConfigZipkin(t *testing.T) {

func TestConfigHistogramTransform(t *testing.T) {
// arrange
col := testbed.NewChildProcessCollector(testbed.WithAgentExePath(CollectorTestsExecPath))
col := testbed.NewChildProcessCollector(testbed.WithAgentExePath(testutil.CollectorTestsExecPath))
cfg, err := os.ReadFile(path.Join(ConfigExamplesDir, "split_histogram.yaml"))
require.NoError(t, err)

receiverPort := testutil.GetAvailablePort(t)
exporterPort := testutil.GetAvailablePort(t)

parsedConfig := string(cfg)
parsedConfig = replaceOtlpGrpcReceiverPort(parsedConfig, receiverPort)
parsedConfig = replaceDynatraceExporterEndpoint(parsedConfig, exporterPort)
parsedConfig = testutil.ReplaceOtlpGrpcReceiverPort(parsedConfig, receiverPort)
parsedConfig = testutil.ReplaceDynatraceExporterEndpoint(parsedConfig, exporterPort)

configCleanup, err := col.PrepareConfig(parsedConfig)
require.NoError(t, err)
Expand Down Expand Up @@ -416,16 +417,16 @@ func TestConfigHistogramTransform(t *testing.T) {

func TestConfigMetricsFromPreSampledTraces(t *testing.T) {
// arrange
col := testbed.NewChildProcessCollector(testbed.WithAgentExePath(CollectorTestsExecPath))
col := testbed.NewChildProcessCollector(testbed.WithAgentExePath(testutil.CollectorTestsExecPath))
cfg, err := os.ReadFile(path.Join(ConfigExamplesDir, "spanmetrics.yaml"))
require.NoError(t, err)

receiverPort := testutil.GetAvailablePort(t)
exporterPort := testutil.GetAvailablePort(t)

parsedConfig := string(cfg)
parsedConfig = replaceOtlpGrpcReceiverPort(parsedConfig, receiverPort)
parsedConfig = replaceDynatraceExporterEndpoint(parsedConfig, exporterPort)
parsedConfig = testutil.ReplaceOtlpGrpcReceiverPort(parsedConfig, receiverPort)
parsedConfig = testutil.ReplaceDynatraceExporterEndpoint(parsedConfig, exporterPort)

// replaces the sampling decision wait so the test doesn't timeout
parsedConfig = strings.Replace(parsedConfig, "decision_wait: 30s", "decision_wait: 10ms", 1)
Expand All @@ -449,8 +450,8 @@ func TestConfigMetricsFromPreSampledTraces(t *testing.T) {

// Error ers
ers := actualSpans.AppendEmpty()
ers.SetTraceID(uInt64ToTraceID(0, uint64(1)))
ers.SetSpanID(uInt64ToSpanID(uint64(1)))
ers.SetTraceID(idutils.UInt64ToTraceID(0, uint64(1)))
ers.SetSpanID(idutils.UInt64ToSpanID(uint64(1)))
ers.SetName("Error span")
ers.SetKind(ptrace.SpanKindServer)
ers.Status().SetCode(ptrace.StatusCodeError)
Expand All @@ -459,8 +460,8 @@ func TestConfigMetricsFromPreSampledTraces(t *testing.T) {

// Ok span
oks := actualSpans.AppendEmpty()
oks.SetTraceID(uInt64ToTraceID(0, uint64(2)))
oks.SetSpanID(uInt64ToSpanID(uint64(2)))
oks.SetTraceID(idutils.UInt64ToTraceID(0, uint64(2)))
oks.SetSpanID(idutils.UInt64ToSpanID(uint64(2)))
oks.SetName("OK span")
oks.SetKind(ptrace.SpanKindServer)
oks.Status().SetCode(ptrace.StatusCodeOk)
Expand All @@ -469,8 +470,8 @@ func TestConfigMetricsFromPreSampledTraces(t *testing.T) {

// Long-running span
lrs := actualSpans.AppendEmpty()
lrs.SetTraceID(uInt64ToTraceID(0, uint64(3)))
lrs.SetSpanID(uInt64ToSpanID(uint64(3)))
lrs.SetTraceID(idutils.UInt64ToTraceID(0, uint64(3)))
lrs.SetSpanID(idutils.UInt64ToSpanID(uint64(3)))
lrs.SetName("Long-running span")
lrs.SetKind(ptrace.SpanKindServer)
lrs.Status().SetCode(ptrace.StatusCodeOk)
Expand Down Expand Up @@ -518,16 +519,16 @@ func TestConfigMetricsFromPreSampledTraces(t *testing.T) {
}

func TestSyslog_WithF5Receiver(t *testing.T) {
col := testbed.NewChildProcessCollector(testbed.WithAgentExePath(CollectorTestsExecPath))
col := testbed.NewChildProcessCollector(testbed.WithAgentExePath(testutil.CollectorTestsExecPath))
cfg, err := os.ReadFile(path.Join(ConfigExamplesDir, "syslog.yaml"))
require.NoError(t, err)

syslogReceiverPort := testutil.GetAvailablePort(t)
exporterPort := testutil.GetAvailablePort(t)

parsedConfig := string(cfg)
parsedConfig = replaceSyslogF5ReceiverPort(parsedConfig, syslogReceiverPort)
parsedConfig = replaceDynatraceExporterEndpoint(parsedConfig, exporterPort)
parsedConfig = testutil.ReplaceSyslogF5ReceiverPort(parsedConfig, syslogReceiverPort)
parsedConfig = testutil.ReplaceDynatraceExporterEndpoint(parsedConfig, exporterPort)

configCleanup, err := col.PrepareConfig(parsedConfig)
require.NoError(t, err)
Expand All @@ -545,8 +546,8 @@ func TestSyslog_WithF5Receiver(t *testing.T) {
actualSimpleLog.Body().SetStr("simple_1")
actualSimpleLog.SetTimestamp(pcommon.NewTimestampFromTime(timestamp))
actualSimpleLog.SetObservedTimestamp(pcommon.NewTimestampFromTime(timestamp))
actualSimpleLog.SetTraceID(uInt64ToTraceID(0, uint64(1)))
actualSimpleLog.SetSpanID(uInt64ToSpanID(uint64(2)))
actualSimpleLog.SetTraceID(idutils.UInt64ToTraceID(0, uint64(1)))
actualSimpleLog.SetSpanID(idutils.UInt64ToSpanID(uint64(2)))
actualSimpleLog.Attributes().PutStr("foo", "bar")

expectedSimpleLog := expectedLogs.AppendEmpty()
Expand All @@ -560,8 +561,8 @@ func TestSyslog_WithF5Receiver(t *testing.T) {
expectedSimpleLogAttrDevice := expectedSimpleLog.Attributes().PutEmptyMap("device")
expectedSimpleLogAttrDevice.PutStr("type", "f5bigip")
// Trace ID and Span ID are not auto-mapped to plog by the receiver, so we test for empty IDs
expectedSimpleLog.SetTraceID(uInt64ToTraceID(0, uint64(0)))
expectedSimpleLog.SetSpanID(uInt64ToSpanID(uint64(0)))
expectedSimpleLog.SetTraceID(idutils.UInt64ToTraceID(0, uint64(0)))
expectedSimpleLog.SetSpanID(idutils.UInt64ToSpanID(uint64(0)))
expectedSimpleLog.Body().SetStr("<166> " + timestamp.Format(time.RFC3339Nano) + " 127.0.0.1 - - - [trace_id=\"00000000000000000000000000000001\" span_id=\"0000000000000002\" trace_flags=\"0\" foo=\"bar\" ] simple_1")
// ObservedTimestamp will be the time the receiver "observes" the log, so we test that the timestamp is after what's defined here.
expectedSimpleLog.SetObservedTimestamp(pcommon.NewTimestampFromTime(timestamp))
Expand Down Expand Up @@ -605,16 +606,16 @@ func TestSyslog_WithF5Receiver(t *testing.T) {
}

func TestSyslog_WithHostReceiver(t *testing.T) {
col := testbed.NewChildProcessCollector(testbed.WithAgentExePath(CollectorTestsExecPath))
col := testbed.NewChildProcessCollector(testbed.WithAgentExePath(testutil.CollectorTestsExecPath))
cfg, err := os.ReadFile(path.Join(ConfigExamplesDir, "syslog.yaml"))
require.NoError(t, err)

syslogReceiverPort := testutil.GetAvailablePort(t)
exporterPort := testutil.GetAvailablePort(t)

parsedConfig := string(cfg)
parsedConfig = replaceSyslogHostReceiverPort(parsedConfig, syslogReceiverPort)
parsedConfig = replaceDynatraceExporterEndpoint(parsedConfig, exporterPort)
parsedConfig = testutil.ReplaceSyslogHostReceiverPort(parsedConfig, syslogReceiverPort)
parsedConfig = testutil.ReplaceDynatraceExporterEndpoint(parsedConfig, exporterPort)

configCleanup, err := col.PrepareConfig(parsedConfig)
require.NoError(t, err)
Expand All @@ -632,8 +633,8 @@ func TestSyslog_WithHostReceiver(t *testing.T) {
actualSimpleLog.Body().SetStr("simple_1")
actualSimpleLog.SetTimestamp(pcommon.NewTimestampFromTime(timestamp))
actualSimpleLog.SetObservedTimestamp(pcommon.NewTimestampFromTime(timestamp))
actualSimpleLog.SetTraceID(uInt64ToTraceID(0, uint64(1)))
actualSimpleLog.SetSpanID(uInt64ToSpanID(uint64(2)))
actualSimpleLog.SetTraceID(idutils.UInt64ToTraceID(0, uint64(1)))
actualSimpleLog.SetSpanID(idutils.UInt64ToSpanID(uint64(2)))
actualSimpleLog.Attributes().PutStr("foo", "bar")

expectedSimpleLog := expectedLogs.AppendEmpty()
Expand All @@ -643,8 +644,8 @@ func TestSyslog_WithHostReceiver(t *testing.T) {
expectedSimpleLogAttrDevice := expectedSimpleLog.Attributes().PutEmptyMap("device")
expectedSimpleLogAttrDevice.PutStr("type", "ubuntu-syslog")
// Trace ID and Span ID are not auto-mapped to plog by the receiver, so we test for empty IDs
expectedSimpleLog.SetTraceID(uInt64ToTraceID(0, uint64(0)))
expectedSimpleLog.SetSpanID(uInt64ToSpanID(uint64(0)))
expectedSimpleLog.SetTraceID(idutils.UInt64ToTraceID(0, uint64(0)))
expectedSimpleLog.SetSpanID(idutils.UInt64ToSpanID(uint64(0)))
expectedSimpleLog.Body().SetStr("<166> " + timestamp.Format(time.RFC3339Nano) + " 127.0.0.1 - - - [trace_id=\"00000000000000000000000000000001\" span_id=\"0000000000000002\" trace_flags=\"0\" foo=\"bar\" ] simple_1")
// ObservedTimestamp will be the time the receiver "observes" the log, so we test that the timestamp is after what's defined here.
expectedSimpleLog.SetObservedTimestamp(pcommon.NewTimestampFromTime(timestamp))
Expand Down
57 changes: 0 additions & 57 deletions internal/testbed/integration/testutils.go

This file was deleted.

Loading

0 comments on commit bd192a5

Please sign in to comment.