Skip to content

Commit 57c6c15

Browse files
authored
[chore] Nit-fix exporter.request.MergeSplit() (#12016)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description This PR fixes how `capacityLimit` is updated in `exporter.request.MergeSplit()`. Before ``` if srcReq.ld.LogRecordCount() <= capacityLeft { if destReq == nil { destReq = srcReq } else { srcReq.ld.ResourceLogs().MoveAndAppendTo(destReq.ld.ResourceLogs()) } capacityLeft -= destReq.ld.LogRecordCount() continue } ``` After ``` srcCount := srcReq.ld.LogRecordCount() if srcCount <= capacityLeft { if destReq == nil { destReq = srcReq } else { srcReq.ld.ResourceLogs().MoveAndAppendTo(destReq.ld.ResourceLogs()) } capacityLeft -= srcCount continue } ``` With that said, the original implementation does not cause any bug because "the larger for loop" loops through only two items. In the first loop, `destReq` is guaranteed to be `nil`, so `capacityLeft` is updated properly. In the second loop, we jump out of the loop immediately so the accuracy of `capacityLeft` does not matter any more. <!-- Issue number if applicable --> #### Link to tracking issue NA <!--Describe what testing was performed and which tests were added.--> #### Testing NA <!--Describe the documentation added.--> #### Documentation NA <!--Please delete paragraphs that you did not use before submitting.-->
1 parent e5e12bf commit 57c6c15

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

exporter/exporterhelper/logs_batch.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,15 @@ func (req *logsRequest) MergeSplit(_ context.Context, cfg exporterbatcher.MaxSiz
3737
if srcReq == nil {
3838
continue
3939
}
40-
if srcReq.ld.LogRecordCount() <= capacityLeft {
40+
41+
srcCount := srcReq.ld.LogRecordCount()
42+
if srcCount <= capacityLeft {
4143
if destReq == nil {
4244
destReq = srcReq
4345
} else {
4446
srcReq.ld.ResourceLogs().MoveAndAppendTo(destReq.ld.ResourceLogs())
4547
}
46-
capacityLeft -= destReq.ld.LogRecordCount()
48+
capacityLeft -= srcCount
4749
continue
4850
}
4951

exporter/exporterhelper/metrics_batch.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,15 @@ func (req *metricsRequest) MergeSplit(_ context.Context, cfg exporterbatcher.Max
3737
if srcReq == nil {
3838
continue
3939
}
40-
if srcReq.md.DataPointCount() <= capacityLeft {
40+
41+
srcCount := srcReq.md.DataPointCount()
42+
if srcCount <= capacityLeft {
4143
if destReq == nil {
4244
destReq = srcReq
4345
} else {
4446
srcReq.md.ResourceMetrics().MoveAndAppendTo(destReq.md.ResourceMetrics())
4547
}
46-
capacityLeft -= destReq.md.DataPointCount()
48+
capacityLeft -= srcCount
4749
continue
4850
}
4951

exporter/exporterhelper/traces_batch.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,15 @@ func (req *tracesRequest) MergeSplit(_ context.Context, cfg exporterbatcher.MaxS
3737
if srcReq == nil {
3838
continue
3939
}
40-
if srcReq.td.SpanCount() <= capacityLeft {
40+
41+
srcCount := srcReq.td.SpanCount()
42+
if srcCount <= capacityLeft {
4143
if destReq == nil {
4244
destReq = srcReq
4345
} else {
4446
srcReq.td.ResourceSpans().MoveAndAppendTo(destReq.td.ResourceSpans())
4547
}
46-
capacityLeft -= destReq.td.SpanCount()
48+
capacityLeft -= srcCount
4749
continue
4850
}
4951

exporter/exporterhelper/xexporterhelper/profiles_batch.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,15 @@ func (req *profilesRequest) MergeSplit(_ context.Context, cfg exporterbatcher.Ma
3737
if srcReq == nil {
3838
continue
3939
}
40-
if srcReq.pd.SampleCount() <= capacityLeft {
40+
41+
srcCount := srcReq.pd.SampleCount()
42+
if srcCount <= capacityLeft {
4143
if destReq == nil {
4244
destReq = srcReq
4345
} else {
4446
srcReq.pd.ResourceProfiles().MoveAndAppendTo(destReq.pd.ResourceProfiles())
4547
}
46-
capacityLeft -= destReq.pd.SampleCount()
48+
capacityLeft -= srcCount
4749
continue
4850
}
4951

0 commit comments

Comments
 (0)