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

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

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

* limit max packet size parameter
This commit is contained in:
jaychung 2022-01-19 00:42:24 +08:00 committed by GitHub
parent 0b03aae0da
commit 0c1f156b5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 7 deletions

View File

@ -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

View File

@ -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 {
@ -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 {
@ -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,

View File

@ -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)