Skip to content
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

Go1.23 timers #11334

Closed
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions processor/batchprocessor/batch_processor.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0


bogdandrutu marked this conversation as resolved.
Show resolved Hide resolved
package batchprocessor // import "go.opentelemetry.io/collector/processor/batchprocessor"

import (
Expand Down Expand Up @@ -118,9 +119,11 @@ type batch interface {
sizeBytes(item any) int
}

var _ consumer.Traces = (*batchProcessor)(nil)
var _ consumer.Metrics = (*batchProcessor)(nil)
var _ consumer.Logs = (*batchProcessor)(nil)
var (
_ consumer.Traces = (*batchProcessor)(nil)
_ consumer.Metrics = (*batchProcessor)(nil)
_ consumer.Logs = (*batchProcessor)(nil)
)

// newBatchProcessor returns a new batch processor component.
func newBatchProcessor(set processor.Settings, cfg *Config, batchFunc func() batch) (*batchProcessor, error) {
Expand Down Expand Up @@ -259,12 +262,6 @@ func (b *shard) hasTimer() bool {
return b.timer != nil
}

func (b *shard) stopTimer() {
if b.hasTimer() && !b.timer.Stop() {
<-b.timer.C
}
}

func (b *shard) resetTimer() {
if b.hasTimer() {
b.timer.Reset(b.processor.timeout)
Expand Down
12 changes: 12 additions & 0 deletions processor/batchprocessor/batch_processor_1_22.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

//go:build !1.23
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be go1.23? At least on https://stackoverflow.com/a/38439941 that is the format used. Has the format changed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For builds using go version 1.23 and above , file tagged with //go:build 1.23 will be used, for go version below 1.23 , file tagged with //go:build !1.23 will be used.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, what I meant is that I expected this to be

Suggested change
//go:build !1.23
//go:build !go1.23

or at least this is how it used to work for Go in older versions, not 1.23


package batchprocessor // import "go.opentelemetry.io/collector/processor/batchprocessor"

func (b *shard) stopTimer() {
if b.hasTimer() && !b.timer.Stop() {
<-b.timer.C

Check warning on line 10 in processor/batchprocessor/batch_processor_1_22.go

View check run for this annotation

Codecov / codecov/patch

processor/batchprocessor/batch_processor_1_22.go#L10

Added line #L10 was not covered by tests
}
}
12 changes: 12 additions & 0 deletions processor/batchprocessor/batch_processor_1_23.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

//go:build 1.23

package batchprocessor // import "go.opentelemetry.io/collector/processor/batchprocessor"

func (b *shard) stopTimer() {
if b.hasTimer() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to add a test to capture the regression this is fixing?

b.timer.Stop()
}
}
Loading