-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Send correct batch stats when SendBatchMaxSize is set #5385
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,7 +59,7 @@ type batchProcessor struct { | |
|
||
type batch interface { | ||
// export the current batch | ||
export(ctx context.Context, sendBatchMaxSize int) error | ||
export(ctx context.Context, sendBatchMaxSize int, returnBytes bool) (sentBatchSize int, sentBatchBytes int, err error) | ||
|
||
// itemCount returns the size of the current batch | ||
itemCount() int | ||
|
@@ -175,15 +175,16 @@ func (bp *batchProcessor) resetTimer() { | |
} | ||
|
||
func (bp *batchProcessor) sendItems(triggerMeasure *stats.Int64Measure) { | ||
// Add that it came form the trace pipeline? | ||
stats.Record(bp.exportCtx, triggerMeasure.M(1), statBatchSendSize.M(int64(bp.batch.itemCount()))) | ||
|
||
if bp.telemetryLevel == configtelemetry.LevelDetailed { | ||
stats.Record(bp.exportCtx, statBatchSendSizeBytes.M(int64(bp.batch.size()))) | ||
} | ||
|
||
if err := bp.batch.export(bp.exportCtx, bp.sendBatchMaxSize); err != nil { | ||
detailed := bp.telemetryLevel == configtelemetry.LevelDetailed | ||
sent, bytes, err := bp.batch.export(bp.exportCtx, bp.sendBatchMaxSize, detailed) | ||
if err != nil { | ||
bp.logger.Warn("Sender failed", zap.Error(err)) | ||
} else { | ||
// Add that it came form the trace pipeline? | ||
stats.Record(bp.exportCtx, triggerMeasure.M(1), statBatchSendSize.M(int64(sent))) | ||
if detailed { | ||
stats.Record(bp.exportCtx, statBatchSendSizeBytes.M(int64(bytes))) | ||
} | ||
} | ||
} | ||
|
||
|
@@ -244,17 +245,24 @@ func (bt *batchTraces) add(item interface{}) { | |
td.ResourceSpans().MoveAndAppendTo(bt.traceData.ResourceSpans()) | ||
} | ||
|
||
func (bt *batchTraces) export(ctx context.Context, sendBatchMaxSize int) error { | ||
func (bt *batchTraces) export(ctx context.Context, sendBatchMaxSize int, returnBytes bool) (int, int, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: should we do the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i can see why that would be annoying because then instead of a single stats record call, you have to make one in each batch processor. What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I'd rather change the signature, especially since it's only used in one place, than duplicate the stats recording code. |
||
var req ptrace.Traces | ||
var sent int | ||
var bytes int | ||
if sendBatchMaxSize > 0 && bt.itemCount() > sendBatchMaxSize { | ||
req = splitTraces(sendBatchMaxSize, bt.traceData) | ||
bt.spanCount -= sendBatchMaxSize | ||
sent = sendBatchMaxSize | ||
} else { | ||
req = bt.traceData | ||
sent = bt.spanCount | ||
bt.traceData = ptrace.NewTraces() | ||
bt.spanCount = 0 | ||
} | ||
return bt.nextConsumer.ConsumeTraces(ctx, req) | ||
if returnBytes { | ||
bytes = bt.sizer.TracesSize(req) | ||
} | ||
return sent, bytes, bt.nextConsumer.ConsumeTraces(ctx, req) | ||
} | ||
|
||
func (bt *batchTraces) itemCount() int { | ||
|
@@ -276,17 +284,24 @@ func newBatchMetrics(nextConsumer consumer.Metrics) *batchMetrics { | |
return &batchMetrics{nextConsumer: nextConsumer, metricData: pmetric.NewMetrics(), sizer: pmetric.NewProtoMarshaler().(pmetric.Sizer)} | ||
} | ||
|
||
func (bm *batchMetrics) export(ctx context.Context, sendBatchMaxSize int) error { | ||
func (bm *batchMetrics) export(ctx context.Context, sendBatchMaxSize int, returnBytes bool) (int, int, error) { | ||
var req pmetric.Metrics | ||
var sent int | ||
var bytes int | ||
if sendBatchMaxSize > 0 && bm.dataPointCount > sendBatchMaxSize { | ||
req = splitMetrics(sendBatchMaxSize, bm.metricData) | ||
bm.dataPointCount -= sendBatchMaxSize | ||
sent = sendBatchMaxSize | ||
} else { | ||
req = bm.metricData | ||
sent = bm.dataPointCount | ||
bm.metricData = pmetric.NewMetrics() | ||
bm.dataPointCount = 0 | ||
} | ||
return bm.nextConsumer.ConsumeMetrics(ctx, req) | ||
if returnBytes { | ||
bytes = bm.sizer.MetricsSize(req) | ||
} | ||
return sent, bytes, bm.nextConsumer.ConsumeMetrics(ctx, req) | ||
} | ||
|
||
func (bm *batchMetrics) itemCount() int { | ||
|
@@ -319,17 +334,24 @@ func newBatchLogs(nextConsumer consumer.Logs) *batchLogs { | |
return &batchLogs{nextConsumer: nextConsumer, logData: plog.NewLogs(), sizer: plog.NewProtoMarshaler().(plog.Sizer)} | ||
} | ||
|
||
func (bl *batchLogs) export(ctx context.Context, sendBatchMaxSize int) error { | ||
func (bl *batchLogs) export(ctx context.Context, sendBatchMaxSize int, returnBytes bool) (int, int, error) { | ||
var req plog.Logs | ||
var sent int | ||
var bytes int | ||
if sendBatchMaxSize > 0 && bl.logCount > sendBatchMaxSize { | ||
req = splitLogs(sendBatchMaxSize, bl.logData) | ||
bl.logCount -= sendBatchMaxSize | ||
sent = sendBatchMaxSize | ||
} else { | ||
req = bl.logData | ||
sent = bl.logCount | ||
bl.logData = plog.NewLogs() | ||
bl.logCount = 0 | ||
} | ||
return bl.nextConsumer.ConsumeLogs(ctx, req) | ||
if returnBytes { | ||
bytes = bl.sizer.LogsSize(req) | ||
} | ||
return sent, bytes, bl.nextConsumer.ConsumeLogs(ctx, req) | ||
} | ||
|
||
func (bl *batchLogs) itemCount() int { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: should we call out that we may want to remove this given it's barely used and almost always desired in a future PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the default for this setting is
LevelBasic
, so eliminating the check here would be a behavior change.