Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Yuri Shkuro <[email protected]>
  • Loading branch information
yurishkuro committed May 27, 2022
1 parent e107cd6 commit b6bb0f8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 26 deletions.
4 changes: 1 addition & 3 deletions cmd/collector/app/handler/grpc_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,14 @@ import (

// GRPCHandler implements gRPC CollectorService.
type GRPCHandler struct {
logger *zap.Logger
// spanProcessor processor.SpanProcessor
logger *zap.Logger
batchConsumer batchConsumer
}

// NewGRPCHandler registers routes for this handler on the given router.
func NewGRPCHandler(logger *zap.Logger, spanProcessor processor.SpanProcessor) *GRPCHandler {
return &GRPCHandler{
logger: logger,
// spanProcessor: spanProcessor,
batchConsumer: batchConsumer{
logger: logger,
spanProcessor: spanProcessor,
Expand Down
5 changes: 0 additions & 5 deletions cmd/collector/app/handler/otlp_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ import (
"github.com/jaegertracing/jaeger/model"
)

// // A delegation function to assist in tests, because ProtoFromTraces never returns errors despite its API.
// var protoFromTraces func(td ptrace.Traces) ([]*model.Batch, error) = otlp2jaeger.ProtoFromTraces

var _ component.Host = (*otelHost)(nil) // API check

// OtelReceiverOptions allows configuration of the receiver.
Expand Down Expand Up @@ -76,7 +73,6 @@ func StartOtelReceiver(options OtelReceiverOptions, logger *zap.Logger, spanProc

func newConsumerDelegate(logger *zap.Logger, spanProcessor processor.SpanProcessor) *consumerDelegate {
return &consumerDelegate{
logger: logger,
batchConsumer: batchConsumer{
logger: logger,
spanProcessor: spanProcessor,
Expand All @@ -90,7 +86,6 @@ func newConsumerDelegate(logger *zap.Logger, spanProcessor processor.SpanProcess
}

type consumerDelegate struct {
logger *zap.Logger
batchConsumer batchConsumer
protoFromTraces func(td ptrace.Traces) ([]*model.Batch, error)
}
Expand Down
39 changes: 21 additions & 18 deletions cmd/collector/app/handler/otlp_receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,27 +59,30 @@ func makeTracesOneSpan() ptrace.Traces {
}

func TestConsumerDelegate(t *testing.T) {
logger, _ := testutils.NewLogger()
spanProcessor := &mockSpanProcessor{}
consumer := newConsumerDelegate(logger, spanProcessor)
testCases := []struct {
expectErr error
expectLog string
}{
{}, // no errors
{expectErr: errors.New("test-error"), expectLog: "test-error"},
}
for _, test := range testCases {
t.Run(test.expectLog, func(t *testing.T) {
logger, logBuf := testutils.NewLogger()
spanProcessor := &mockSpanProcessor{expectedError: test.expectErr}
consumer := newConsumerDelegate(logger, spanProcessor)

err := consumer.consume(context.Background(), makeTracesOneSpan())
require.NoError(t, err)
assert.Len(t, spanProcessor.getSpans(), 1)
}
err := consumer.consume(context.Background(), makeTracesOneSpan())

func TestConsumerDelegate_Error(t *testing.T) {
logger, logBuf := testutils.NewLogger()
expectedErr := errors.New("test-error")
spanProcessor := &mockSpanProcessor{
expectedError: expectedErr,
if test.expectErr != nil {
require.Equal(t, test.expectErr, err)
assert.Contains(t, logBuf.String(), test.expectLog)
} else {
require.NoError(t, err)
assert.Len(t, spanProcessor.getSpans(), 1)
}
})
}
consumer := newConsumerDelegate(logger, spanProcessor)

err := consumer.consume(context.Background(), makeTracesOneSpan())
require.Error(t, err)
assert.Equal(t, expectedErr, err)
assert.Contains(t, logBuf.String(), "test-error")
}

func TestStartOtlpReceiver_Error(t *testing.T) {
Expand Down

0 comments on commit b6bb0f8

Please sign in to comment.