From ec4ffc28967f3476c67426b252d7703dbeca731f Mon Sep 17 00:00:00 2001 From: Benedikt Bongartz Date: Sun, 25 Jan 2026 17:45:10 +0100 Subject: [PATCH] add batch processor deprecation warning Signed-off-by: Benedikt Bongartz --- .../batch-processor-deprecation-warning.yaml | 20 +++ apis/v1beta1/config.go | 27 +++- apis/v1beta1/config_test.go | 147 ++++++++++++++++++ 3 files changed, 193 insertions(+), 1 deletion(-) create mode 100644 .chloggen/batch-processor-deprecation-warning.yaml diff --git a/.chloggen/batch-processor-deprecation-warning.yaml b/.chloggen/batch-processor-deprecation-warning.yaml new file mode 100644 index 0000000000..d172004c92 --- /dev/null +++ b/.chloggen/batch-processor-deprecation-warning.yaml @@ -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. diff --git a/apis/v1beta1/config.go b/apis/v1beta1/config.go index ad9e40089b..6f771230a7 100644 --- a/apis/v1beta1/config.go +++ b/apis/v1beta1/config.go @@ -9,6 +9,7 @@ import ( "fmt" "math" "sort" + "strings" "dario.cat/mergo" "github.com/go-logr/logr" @@ -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) + 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 diff --git a/apis/v1beta1/config_test.go b/apis/v1beta1/config_test.go index 7841bc04c0..802e6d914f 100644 --- a/apis/v1beta1/config_test.go +++ b/apis/v1beta1/config_test.go @@ -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") + }) + } +}