Skip to content

Commit 13f2495

Browse files
wildumdjaglowski
authored andcommitted
(batchprocessor): Move single shard batcher creation to the constructor (open-telemetry#11594)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description The single-shard batcher is currently created and started in the start function. If the consume function is called before the start function, sb.single will be nil and it will panic. I'm not sure if that can happen in the Otel collector but it might happen in distributions that have a different runtime (such as Alloy - Grafana's distribution). I think that conceptually, it's better to create the shard in the constructor and start it in the start function. PS: I did not create an entry in the changelog because the initial [PR](open-telemetry#11314) for this change didn't but let me know if I should add one. Credits also to @thampiotr for this fix
1 parent aadefd5 commit 13f2495

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
7+
component: batchprocessor
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Move single shard batcher creation to the constructor
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [11594]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# Optional: The change log or logs in which this entry should be included.
21+
# e.g. '[user]' or '[user, api]'
22+
# Include 'user' if the change is relevant to end users.
23+
# Include 'api' if there is a change to a library API.
24+
# Default: '[user]'
25+
change_logs: []

processor/batchprocessor/batch_processor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ func newBatchProcessor[T any](set processor.Settings, cfg *Config, batchFunc fun
129129
if len(mks) == 0 {
130130
bp.batcher = &singleShardBatcher[T]{
131131
processor: bp,
132+
single: bp.newShard(nil),
132133
}
133134
} else {
134135
bp.batcher = &multiShardBatcher[T]{
@@ -277,7 +278,6 @@ type singleShardBatcher[T any] struct {
277278
}
278279

279280
func (sb *singleShardBatcher[T]) start(context.Context) error {
280-
sb.single = sb.processor.newShard(nil)
281281
sb.single.start()
282282
return nil
283283
}

0 commit comments

Comments
 (0)