From bca7d6f816e995831bce12b2c972923efacd6e3b Mon Sep 17 00:00:00 2001 From: Jay Chung Date: Fri, 14 Jan 2022 17:50:36 +0800 Subject: [PATCH] emitBatchOverhead should only be used for splitting spans into batches --- exporters/jaeger/agent.go | 11 ++++++++--- exporters/jaeger/agent_test.go | 4 ++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/exporters/jaeger/agent.go b/exporters/jaeger/agent.go index ce53e4386b2..c4fadb506f5 100644 --- a/exporters/jaeger/agent.go +++ b/exporters/jaeger/agent.go @@ -72,7 +72,7 @@ func newAgentClientUDP(params agentClientUDPParams) (*agentClientUDP, error) { } if params.MaxPacketSize <= 0 { - params.MaxPacketSize = udpPacketMaxLength - emitBatchOverhead + params.MaxPacketSize = udpPacketMaxLength } if params.AttemptReconnecting && params.AttemptReconnectInterval <= 0 { @@ -126,6 +126,11 @@ func (a *agentClientUDP) EmitBatch(ctx context.Context, batch *gen.Batch) error // drop the batch if serialization of process fails. return err } + + maxPacketSize := a.maxPacketSize + if maxPacketSize == udpPacketMaxLength { + maxPacketSize -= emitBatchOverhead + } totalSize := processSize var spans []*gen.Span for _, span := range batch.Spans { @@ -134,12 +139,12 @@ func (a *agentClientUDP) EmitBatch(ctx context.Context, batch *gen.Batch) error errs = append(errs, fmt.Errorf("thrift serialization failed: %v", span)) continue } - if spanSize+processSize >= a.maxPacketSize { + if spanSize+processSize >= maxPacketSize { // drop the span that exceeds the limit. errs = append(errs, fmt.Errorf("span too large to send: %v", span)) continue } - if totalSize+spanSize >= a.maxPacketSize { + if totalSize+spanSize >= maxPacketSize { if err := a.flush(ctx, &gen.Batch{ Process: batch.Process, Spans: spans, diff --git a/exporters/jaeger/agent_test.go b/exporters/jaeger/agent_test.go index 933d364e3df..62de111dae5 100644 --- a/exporters/jaeger/agent_test.go +++ b/exporters/jaeger/agent_test.go @@ -73,7 +73,7 @@ func TestNewAgentClientUDPWithParamsDefaults(t *testing.T) { }) assert.NoError(t, err) assert.NotNil(t, agentClient) - assert.Equal(t, udpPacketMaxLength-emitBatchOverhead, agentClient.maxPacketSize) + assert.Equal(t, udpPacketMaxLength, agentClient.maxPacketSize) if assert.IsType(t, &reconnectingUDPConn{}, agentClient.connUDP) { assert.Equal(t, (*log.Logger)(nil), agentClient.connUDP.(*reconnectingUDPConn).logger) @@ -97,7 +97,7 @@ func TestNewAgentClientUDPWithParamsReconnectingDisabled(t *testing.T) { }) assert.NoError(t, err) assert.NotNil(t, agentClient) - assert.Equal(t, udpPacketMaxLength-emitBatchOverhead, agentClient.maxPacketSize) + assert.Equal(t, udpPacketMaxLength, agentClient.maxPacketSize) assert.IsType(t, &net.UDPConn{}, agentClient.connUDP)