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

Add unit test for OTLP receiver in jaeger-v1 #6541

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Changes from 8 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
5ce9b7e
unit test
chahatsagarmain Jan 13, 2025
1e1208e
changes
chahatsagarmain Jan 14, 2025
bd2ea16
Merge branch 'main' into e2e-otlp
chahatsagarmain Jan 15, 2025
b1116f5
logging tenant
chahatsagarmain Jan 15, 2025
24b9b7e
http test
chahatsagarmain Jan 16, 2025
bcc716a
resolved changes
chahatsagarmain Jan 18, 2025
e1d95b2
atomic operation on shared var
chahatsagarmain Jan 18, 2025
5ff0d50
Update cmd/collector/app/span_processor_test.go
yurishkuro Jan 18, 2025
105a171
use assert.eventually
chahatsagarmain Jan 18, 2025
25b68ec
Merge branch 'e2e-otlp' of https://github.com/chahatsagarmain/jaeger …
chahatsagarmain Jan 18, 2025
d750fbc
remove unecessasry code
chahatsagarmain Jan 18, 2025
3868088
Update cmd/collector/app/span_processor_test.go
yurishkuro Jan 19, 2025
90f8935
Merge branch 'e2e-otlp' of https://github.com/chahatsagarmain/jaeger …
chahatsagarmain Jan 21, 2025
28c1231
added grpc test
chahatsagarmain Jan 21, 2025
04c9aab
refactoring
chahatsagarmain Jan 21, 2025
a89135f
Merge branch 'main' into e2e-otlp
chahatsagarmain Jan 21, 2025
95712f2
changes
chahatsagarmain Jan 22, 2025
37b1105
Merge branch 'main' into e2e-otlp
chahatsagarmain Jan 23, 2025
a0b9aeb
changes
chahatsagarmain Jan 25, 2025
4330264
changes
chahatsagarmain Jan 25, 2025
1a9f494
Merge branch 'e2e-otlp' of https://github.com/chahatsagarmain/jaeger …
chahatsagarmain Jan 25, 2025
11d65ce
Merge branch 'main' into e2e-otlp
chahatsagarmain Jan 25, 2025
9544bad
lint
chahatsagarmain Jan 25, 2025
2befd5d
isoloate mock writer
chahatsagarmain Jan 26, 2025
b589977
valid tenant and refactored test
chahatsagarmain Jan 26, 2025
1d7f157
refactor
chahatsagarmain Jan 26, 2025
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
106 changes: 106 additions & 0 deletions cmd/collector/app/span_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"errors"
"fmt"
"io"
"net/http"
"reflect"
"slices"
"sync"
Expand All @@ -19,9 +20,16 @@ import (

"github.com/gogo/protobuf/jsonpb"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/config/configgrpc"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/config/confignet"
"go.opentelemetry.io/collector/pdata/ptrace"
"go.uber.org/zap"
"go.uber.org/zap/zaptest"

cFlags "github.com/jaegertracing/jaeger/cmd/collector/app/flags"
"github.com/jaegertracing/jaeger/cmd/collector/app/handler"
"github.com/jaegertracing/jaeger/cmd/collector/app/processor"
zipkinsanitizer "github.com/jaegertracing/jaeger/cmd/collector/app/sanitizer/zipkin"
Expand All @@ -30,6 +38,7 @@ import (
"github.com/jaegertracing/jaeger/pkg/metrics"
"github.com/jaegertracing/jaeger/pkg/tenancy"
"github.com/jaegertracing/jaeger/pkg/testutils"
"github.com/jaegertracing/jaeger/storage_v2/tracestore/mocks"
"github.com/jaegertracing/jaeger/storage_v2/v1adapter"
"github.com/jaegertracing/jaeger/thrift-gen/jaeger"
zc "github.com/jaegertracing/jaeger/thrift-gen/zipkincore"
Expand Down Expand Up @@ -807,3 +816,100 @@ func TestSpanProcessorWithOnDroppedSpanOption(t *testing.T) {
require.EqualError(t, err, processor.ErrBusy.Error())
assert.Equal(t, []string{"op3"}, droppedOperations)
}

func optionsWithPorts(portHttp string, portGrpc string) *cFlags.CollectorOptions {
opts := &cFlags.CollectorOptions{
OTLP: struct {
Enabled bool
GRPC configgrpc.ServerConfig
HTTP confighttp.ServerConfig
}{
Enabled: true,
HTTP: confighttp.ServerConfig{
Endpoint: portHttp,
},
GRPC: configgrpc.ServerConfig{
NetAddr: confignet.AddrConfig{
Endpoint: portGrpc,
Transport: confignet.TransportTypeTCP,
},
},
},
}
return opts
}

func TestOTLPReceiverWithV2Storage(t *testing.T) {
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
// Setup mock writer and expectations
mockWriter := mocks.NewWriter(t)
traces := ptrace.NewTraces()
rSpans := traces.ResourceSpans().AppendEmpty()
sSpans := rSpans.ScopeSpans().AppendEmpty()
span := sSpans.Spans().AppendEmpty()
span.SetName("test-trace")

var receivedTraces atomic.Pointer[ptrace.Traces]
mockWriter.On("WriteTraces", mock.Anything, mock.Anything).
Run(func(args mock.Arguments) {
storeTrace := args.Get(1).(ptrace.Traces)
receivedTraces.Store(&storeTrace)
}).Return(nil)

spanProcessor, err := NewSpanProcessor(
mockWriter,
nil,
Options.NumWorkers(1),
Options.QueueSize(1),
Options.ReportBusy(true),
)
require.NoError(t, err)
defer spanProcessor.Close()
logger := zaptest.NewLogger(t)

portHttp := "4318"
portGrpc := "4317"

// Can't send tenancy headers with http request to OTLP receiver
tenancyMgr := &tenancy.Manager{
Enabled: false,
}

// Create and start receiver
rec, err := handler.StartOTLPReceiver(
optionsWithPorts(fmt.Sprintf("localhost:%v", portHttp), fmt.Sprintf("localhost:%v", portGrpc)),
logger,
spanProcessor,
tenancyMgr,
)
require.NoError(t, err)
ctx := context.Background()
defer rec.Shutdown(ctx)

// Send trace via HTTP
url := fmt.Sprintf("http://localhost:%v/v1/traces", portHttp)
client := &http.Client{}

marshaler := ptrace.JSONMarshaler{}
data, err := marshaler.MarshalTraces(traces)
require.NoError(t, err)

req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewReader(data))
require.NoError(t, err)
req.Header.Add("Content-Type", "application/json")
req.Header.Add("x-tenant", "test-tenant")

resp, err := client.Do(req)
require.NoError(t, err)
defer resp.Body.Close()

require.Equal(t, http.StatusOK, resp.StatusCode)

time.Sleep(100 * time.Millisecond)
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved

receivedSpan := receivedTraces.Load().ResourceSpans().At(0).
ScopeSpans().At(0).
Spans().At(0)
require.Equal(t, span.Name(), receivedSpan.Name())

mockWriter.AssertExpectations(t)
}
Loading