Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
20 changes: 20 additions & 0 deletions .chloggen/batch-processor-deprecation-warning.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: deprecation

# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action)
component: collector

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add deprecation warning for OpenTelemetryCollector resources using the batch processor

# One or more tracking issues related to the change
issues: [4648]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext: |
The batch processor is being deprecated in the OpenTelemetry Collector project.
A warning event is now emitted when an OpenTelemetryCollector CR uses the batch processor,
directing users to migrate to alternative batching solutions.
See https://github.com/open-telemetry/opentelemetry-collector/issues/12022 for more details.
27 changes: 26 additions & 1 deletion apis/v1beta1/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"math"
"sort"
"strings"

"dario.cat/mergo"
"github.com/go-logr/logr"
Expand Down Expand Up @@ -355,7 +356,31 @@ func (c *Config) GetAllRbacRules(logger logr.Logger) ([]rbacv1.PolicyRule, error
}

func (c *Config) ApplyDefaults(logger logr.Logger) ([]EventInfo, error) {
return c.applyDefaultForComponentKinds(logger, KindReceiver, KindExtension)
events, err := c.applyDefaultForComponentKinds(logger, KindReceiver, KindExtension)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is the defaulter the best place to put this logic? I'd have expected it to live in the Validate methods and return an admission warning instead of an Event.

if err != nil {
return events, err
}

// Check for deprecated batch processor
enabledComponents := c.GetEnabledComponents()
for processorName := range enabledComponents[KindProcessor] {
if processorName == "batch" || strings.HasPrefix(processorName, "batch/") {
const issueID = "https://github.com/open-telemetry/opentelemetry-collector/issues/12022"
warnStr := fmt.Sprintf(
"The batch processor is deprecated and will be removed in a future release. "+
"Please consider migrating to alternative batching solutions. See: %s",
issueID,
)
events = append(events, EventInfo{
Type: corev1.EventTypeWarning,
Reason: "BatchProcessorDeprecated",
Message: warnStr,
})
break
}
}

return events, nil
}

// GetLivenessProbe gets the first enabled liveness probe. There should only ever be one extension enabled
Expand Down
147 changes: 147 additions & 0 deletions apis/v1beta1/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1482,3 +1482,150 @@ func TestTelemetryIncompleteConfigAppliesDefaults(t *testing.T) {
require.Equal(t, "0.0.0.0", *telemetry.Metrics.Readers[0].Pull.Exporter.Prometheus.Host)
require.Equal(t, 8888, *telemetry.Metrics.Readers[0].Pull.Exporter.Prometheus.Port)
}

func TestBatchProcessorDeprecationWarning(t *testing.T) {
tests := []struct {
name string
config *Config
wantWarning bool
wantEventType string
}{
{
name: "batch processor enabled should emit deprecation warning",
config: &Config{
Receivers: AnyConfig{
Object: map[string]interface{}{
"otlp": map[string]interface{}{},
},
},
Exporters: AnyConfig{
Object: map[string]interface{}{
"otlp": map[string]interface{}{},
},
},
Processors: &AnyConfig{
Object: map[string]interface{}{
"batch": map[string]interface{}{},
},
},
Service: Service{
Pipelines: map[string]*Pipeline{
"traces": {
Receivers: []string{"otlp"},
Processors: []string{"batch"},
Exporters: []string{"otlp"},
},
},
},
},
wantWarning: true,
wantEventType: v1.EventTypeWarning,
},
{
name: "batch processor with instance name should emit deprecation warning",
config: &Config{
Receivers: AnyConfig{
Object: map[string]interface{}{
"otlp": map[string]interface{}{},
},
},
Exporters: AnyConfig{
Object: map[string]interface{}{
"otlp": map[string]interface{}{},
},
},
Processors: &AnyConfig{
Object: map[string]interface{}{
"batch/custom": map[string]interface{}{},
},
},
Service: Service{
Pipelines: map[string]*Pipeline{
"traces": {
Receivers: []string{"otlp"},
Processors: []string{"batch/custom"},
Exporters: []string{"otlp"},
},
},
},
},
wantWarning: true,
wantEventType: v1.EventTypeWarning,
},
{
name: "no batch processor should not emit warning",
config: &Config{
Receivers: AnyConfig{
Object: map[string]interface{}{
"otlp": map[string]interface{}{},
},
},
Exporters: AnyConfig{
Object: map[string]interface{}{
"otlp": map[string]interface{}{},
},
},
Processors: &AnyConfig{
Object: map[string]interface{}{
"memory_limiter": map[string]interface{}{},
},
},
Service: Service{
Pipelines: map[string]*Pipeline{
"traces": {
Receivers: []string{"otlp"},
Processors: []string{"memory_limiter"},
Exporters: []string{"otlp"},
},
},
},
},
wantWarning: false,
},
{
name: "nil processors should not emit warning",
config: &Config{
Receivers: AnyConfig{
Object: map[string]interface{}{
"otlp": map[string]interface{}{},
},
},
Exporters: AnyConfig{
Object: map[string]interface{}{
"otlp": map[string]interface{}{},
},
},
Processors: nil,
Service: Service{
Pipelines: map[string]*Pipeline{
"traces": {
Receivers: []string{"otlp"},
Exporters: []string{"otlp"},
},
},
},
},
wantWarning: false,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
events, err := tt.config.ApplyDefaults(logr.Discard())
require.NoError(t, err)

var foundWarning bool
for _, event := range events {
if event.Reason == "BatchProcessorDeprecated" {
foundWarning = true
assert.Equal(t, tt.wantEventType, event.Type)
assert.Contains(t, event.Message, "batch processor is deprecated")
assert.Contains(t, event.Message, "https://github.com/open-telemetry/opentelemetry-collector/issues/12022")
break
}
}

assert.Equal(t, tt.wantWarning, foundWarning, "batch processor deprecation warning presence mismatch")
})
}
}
Loading