Skip to content

Commit

Permalink
emitBatchOverhead should only be used for splitting spans into batches (
Browse files Browse the repository at this point in the history
#2512)

* emitBatchOverhead should only be used for splitting spans into batches (#2503)

* limit max packet size parameter
  • Loading branch information
ken8203 committed Jan 18, 2022
1 parent 0b03aae commit 0c1f156
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -15,7 +15,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

### Changed

- Jaeger exporter takes into additional 70 bytes overhead into consideration when sending UDP packets (#2489)
- Jaeger exporter takes into additional 70 bytes overhead into consideration when sending UDP packets (#2489, #2512)

### Deprecated

Expand Down
13 changes: 9 additions & 4 deletions exporters/jaeger/agent.go
Expand Up @@ -71,8 +71,8 @@ func newAgentClientUDP(params agentClientUDPParams) (*agentClientUDP, error) {
return nil, err
}

if params.MaxPacketSize <= 0 {
params.MaxPacketSize = udpPacketMaxLength - emitBatchOverhead
if params.MaxPacketSize <= 0 || params.MaxPacketSize > udpPacketMaxLength {
params.MaxPacketSize = udpPacketMaxLength
}

if params.AttemptReconnecting && params.AttemptReconnectInterval <= 0 {
Expand Down Expand Up @@ -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-emitBatchOverhead {
maxPacketSize = udpPacketMaxLength - emitBatchOverhead
}
totalSize := processSize
var spans []*gen.Span
for _, span := range batch.Spans {
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions exporters/jaeger/agent_test.go
Expand Up @@ -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)
Expand All @@ -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)

Expand Down

0 comments on commit 0c1f156

Please sign in to comment.