1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2024-12-10 09:50:58 +02:00

Use mock server as jaeger agent listener. (#1930)

Co-authored-by: Anthony Mirabella <a9@aneurysm9.com>
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
This commit is contained in:
Alex 2021-06-09 00:33:57 +08:00 committed by GitHub
parent 208860127a
commit 0827aa6265
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -111,12 +111,18 @@ func (eh errorHandler) Handle(err error) { assert.NoError(eh.t, err) }
func TestJaegerAgentUDPLimitBatching(t *testing.T) {
otel.SetErrorHandler(errorHandler{t})
mockServer, err := newUDPListener()
require.NoError(t, err)
defer mockServer.Close()
host, port, err := net.SplitHostPort(mockServer.LocalAddr().String())
assert.NoError(t, err)
// 1500 spans, size 79559, does not fit within one UDP packet with the default size of 65000.
n := 1500
s := make(tracetest.SpanStubs, n).Snapshots()
exp, err := NewRawExporter(
WithAgentEndpoint(WithAgentHost("localhost"), WithAgentPort("6831")),
WithAgentEndpoint(WithAgentHost(host), WithAgentPort(port)),
)
require.NoError(t, err)
@ -135,6 +141,12 @@ func generateALargeSpan() tracetest.SpanStub {
func TestSpanExceedsMaxPacketLimit(t *testing.T) {
otel.SetErrorHandler(errorHandler{t})
mockServer, err := newUDPListener()
require.NoError(t, err)
defer mockServer.Close()
host, port, err := net.SplitHostPort(mockServer.LocalAddr().String())
assert.NoError(t, err)
// 106 is the serialized size of a span with default values.
maxSize := 106
@ -142,7 +154,7 @@ func TestSpanExceedsMaxPacketLimit(t *testing.T) {
normalSpans := tracetest.SpanStubs{{}, {}}.Snapshots()
exp, err := NewRawExporter(
WithAgentEndpoint(WithAgentHost("localhost"), WithAgentPort("6831"), WithMaxPacketSize(maxSize+1)),
WithAgentEndpoint(WithAgentHost(host), WithAgentPort(port), WithMaxPacketSize(maxSize+1)),
)
require.NoError(t, err)
@ -155,12 +167,18 @@ func TestSpanExceedsMaxPacketLimit(t *testing.T) {
func TestEmitBatchWithMultipleErrors(t *testing.T) {
otel.SetErrorHandler(errorHandler{t})
mockServer, err := newUDPListener()
require.NoError(t, err)
defer mockServer.Close()
host, port, err := net.SplitHostPort(mockServer.LocalAddr().String())
assert.NoError(t, err)
span := generateALargeSpan()
largeSpans := tracetest.SpanStubs{span, span}.Snapshots()
// make max packet size smaller than span
maxSize := len(span.Name)
exp, err := NewRawExporter(
WithAgentEndpoint(WithAgentHost("localhost"), WithAgentPort("6831"), WithMaxPacketSize(maxSize)),
WithAgentEndpoint(WithAgentHost(host), WithAgentPort(port), WithMaxPacketSize(maxSize)),
)
require.NoError(t, err)