diff --git a/.chloggen/optimize-mdatagen-for-batchprocessor.yaml b/.chloggen/optimize-mdatagen-for-batchprocessor.yaml new file mode 100644 index 00000000000..fd214bf9d73 --- /dev/null +++ b/.chloggen/optimize-mdatagen-for-batchprocessor.yaml @@ -0,0 +1,25 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) +component: cmd/mdatagen + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: optimiz the mdatagen for the case like batchprocessor which use a common struct to implement consumer.Traces, consumer.Metrics, consumer.Logs in the meantime. + +# One or more tracking issues or pull requests related to the change +issues: [9688] + +# (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: + +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [] diff --git a/cmd/mdatagen/templates/component_test.go.tmpl b/cmd/mdatagen/templates/component_test.go.tmpl index 0caf18e8c0f..f4bb1bc8702 100644 --- a/cmd/mdatagen/templates/component_test.go.tmpl +++ b/cmd/mdatagen/templates/component_test.go.tmpl @@ -108,20 +108,26 @@ func TestComponentLifecycle(t *testing.T) { err = c.Start(context.Background(), host) require.NoError(t, err) require.NotPanics(t, func() { - switch e := c.(type) { - case exporter.Logs: + switch test.name { + case "logs": + e, ok := c.(exporter.Logs) + require.True(t, ok) logs := generateLifecycleTestLogs() if !e.Capabilities().MutatesData { logs.MarkReadOnly() } err = e.ConsumeLogs(context.Background(), logs) - case exporter.Metrics: + case "metrics": + e, ok := c.(exporter.Metrics) + require.True(t, ok) metrics := generateLifecycleTestMetrics() if !e.Capabilities().MutatesData { metrics.MarkReadOnly() } err = e.ConsumeMetrics(context.Background(), metrics) - case exporter.Traces: + case "traces": + e, ok := c.(exporter.Traces) + require.True(t, ok) traces := generateLifecycleTestTraces() if !e.Capabilities().MutatesData { traces.MarkReadOnly() @@ -199,20 +205,26 @@ func TestComponentLifecycle(t *testing.T) { err = c.Start(context.Background(), host) require.NoError(t, err) require.NotPanics(t, func() { - switch e := c.(type) { - case processor.Logs: + switch test.name { + case "logs": + e, ok := c.(processor.Logs) + require.True(t, ok) logs := generateLifecycleTestLogs() if !e.Capabilities().MutatesData { logs.MarkReadOnly() } err = e.ConsumeLogs(context.Background(), logs) - case processor.Metrics: + case "metrics": + e, ok := c.(processor.Metrics) + require.True(t, ok) metrics := generateLifecycleTestMetrics() if !e.Capabilities().MutatesData { metrics.MarkReadOnly() } err = e.ConsumeMetrics(context.Background(), metrics) - case processor.Traces: + case "traces": + e, ok := c.(processor.Traces) + require.True(t, ok) traces := generateLifecycleTestTraces() if !e.Capabilities().MutatesData { traces.MarkReadOnly() diff --git a/exporter/debugexporter/generated_component_test.go b/exporter/debugexporter/generated_component_test.go index 7efad327751..34ca9eaedce 100644 --- a/exporter/debugexporter/generated_component_test.go +++ b/exporter/debugexporter/generated_component_test.go @@ -71,20 +71,26 @@ func TestComponentLifecycle(t *testing.T) { err = c.Start(context.Background(), host) require.NoError(t, err) require.NotPanics(t, func() { - switch e := c.(type) { - case exporter.Logs: + switch test.name { + case "logs": + e, ok := c.(exporter.Logs) + require.True(t, ok) logs := generateLifecycleTestLogs() if !e.Capabilities().MutatesData { logs.MarkReadOnly() } err = e.ConsumeLogs(context.Background(), logs) - case exporter.Metrics: + case "metrics": + e, ok := c.(exporter.Metrics) + require.True(t, ok) metrics := generateLifecycleTestMetrics() if !e.Capabilities().MutatesData { metrics.MarkReadOnly() } err = e.ConsumeMetrics(context.Background(), metrics) - case exporter.Traces: + case "traces": + e, ok := c.(exporter.Traces) + require.True(t, ok) traces := generateLifecycleTestTraces() if !e.Capabilities().MutatesData { traces.MarkReadOnly() diff --git a/exporter/loggingexporter/generated_component_test.go b/exporter/loggingexporter/generated_component_test.go index 9f8771a9da0..2ea8edc933a 100644 --- a/exporter/loggingexporter/generated_component_test.go +++ b/exporter/loggingexporter/generated_component_test.go @@ -71,20 +71,26 @@ func TestComponentLifecycle(t *testing.T) { err = c.Start(context.Background(), host) require.NoError(t, err) require.NotPanics(t, func() { - switch e := c.(type) { - case exporter.Logs: + switch test.name { + case "logs": + e, ok := c.(exporter.Logs) + require.True(t, ok) logs := generateLifecycleTestLogs() if !e.Capabilities().MutatesData { logs.MarkReadOnly() } err = e.ConsumeLogs(context.Background(), logs) - case exporter.Metrics: + case "metrics": + e, ok := c.(exporter.Metrics) + require.True(t, ok) metrics := generateLifecycleTestMetrics() if !e.Capabilities().MutatesData { metrics.MarkReadOnly() } err = e.ConsumeMetrics(context.Background(), metrics) - case exporter.Traces: + case "traces": + e, ok := c.(exporter.Traces) + require.True(t, ok) traces := generateLifecycleTestTraces() if !e.Capabilities().MutatesData { traces.MarkReadOnly() diff --git a/exporter/nopexporter/generated_component_test.go b/exporter/nopexporter/generated_component_test.go index 45a556168e4..4c1876140dc 100644 --- a/exporter/nopexporter/generated_component_test.go +++ b/exporter/nopexporter/generated_component_test.go @@ -71,20 +71,26 @@ func TestComponentLifecycle(t *testing.T) { err = c.Start(context.Background(), host) require.NoError(t, err) require.NotPanics(t, func() { - switch e := c.(type) { - case exporter.Logs: + switch test.name { + case "logs": + e, ok := c.(exporter.Logs) + require.True(t, ok) logs := generateLifecycleTestLogs() if !e.Capabilities().MutatesData { logs.MarkReadOnly() } err = e.ConsumeLogs(context.Background(), logs) - case exporter.Metrics: + case "metrics": + e, ok := c.(exporter.Metrics) + require.True(t, ok) metrics := generateLifecycleTestMetrics() if !e.Capabilities().MutatesData { metrics.MarkReadOnly() } err = e.ConsumeMetrics(context.Background(), metrics) - case exporter.Traces: + case "traces": + e, ok := c.(exporter.Traces) + require.True(t, ok) traces := generateLifecycleTestTraces() if !e.Capabilities().MutatesData { traces.MarkReadOnly() diff --git a/exporter/otlpexporter/generated_component_test.go b/exporter/otlpexporter/generated_component_test.go index 85ed788065a..cad24cfa855 100644 --- a/exporter/otlpexporter/generated_component_test.go +++ b/exporter/otlpexporter/generated_component_test.go @@ -71,20 +71,26 @@ func TestComponentLifecycle(t *testing.T) { err = c.Start(context.Background(), host) require.NoError(t, err) require.NotPanics(t, func() { - switch e := c.(type) { - case exporter.Logs: + switch test.name { + case "logs": + e, ok := c.(exporter.Logs) + require.True(t, ok) logs := generateLifecycleTestLogs() if !e.Capabilities().MutatesData { logs.MarkReadOnly() } err = e.ConsumeLogs(context.Background(), logs) - case exporter.Metrics: + case "metrics": + e, ok := c.(exporter.Metrics) + require.True(t, ok) metrics := generateLifecycleTestMetrics() if !e.Capabilities().MutatesData { metrics.MarkReadOnly() } err = e.ConsumeMetrics(context.Background(), metrics) - case exporter.Traces: + case "traces": + e, ok := c.(exporter.Traces) + require.True(t, ok) traces := generateLifecycleTestTraces() if !e.Capabilities().MutatesData { traces.MarkReadOnly() diff --git a/exporter/otlphttpexporter/generated_component_test.go b/exporter/otlphttpexporter/generated_component_test.go index c032505a050..3ed05244be2 100644 --- a/exporter/otlphttpexporter/generated_component_test.go +++ b/exporter/otlphttpexporter/generated_component_test.go @@ -71,20 +71,26 @@ func TestComponentLifecycle(t *testing.T) { err = c.Start(context.Background(), host) require.NoError(t, err) require.NotPanics(t, func() { - switch e := c.(type) { - case exporter.Logs: + switch test.name { + case "logs": + e, ok := c.(exporter.Logs) + require.True(t, ok) logs := generateLifecycleTestLogs() if !e.Capabilities().MutatesData { logs.MarkReadOnly() } err = e.ConsumeLogs(context.Background(), logs) - case exporter.Metrics: + case "metrics": + e, ok := c.(exporter.Metrics) + require.True(t, ok) metrics := generateLifecycleTestMetrics() if !e.Capabilities().MutatesData { metrics.MarkReadOnly() } err = e.ConsumeMetrics(context.Background(), metrics) - case exporter.Traces: + case "traces": + e, ok := c.(exporter.Traces) + require.True(t, ok) traces := generateLifecycleTestTraces() if !e.Capabilities().MutatesData { traces.MarkReadOnly() diff --git a/processor/batchprocessor/generated_component_test.go b/processor/batchprocessor/generated_component_test.go index 3c2313b4115..ac9ea51dea2 100644 --- a/processor/batchprocessor/generated_component_test.go +++ b/processor/batchprocessor/generated_component_test.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/confmap/confmaptest" "go.opentelemetry.io/collector/consumer/consumertest" "go.opentelemetry.io/collector/pdata/pcommon" @@ -64,6 +65,44 @@ func TestComponentLifecycle(t *testing.T) { err = c.Shutdown(context.Background()) require.NoError(t, err) }) + t.Run(test.name+"-lifecycle", func(t *testing.T) { + c, err := test.createFn(context.Background(), processortest.NewNopCreateSettings(), cfg) + require.NoError(t, err) + host := componenttest.NewNopHost() + err = c.Start(context.Background(), host) + require.NoError(t, err) + require.NotPanics(t, func() { + switch test.name { + case "logs": + e, ok := c.(processor.Logs) + require.True(t, ok) + logs := generateLifecycleTestLogs() + if !e.Capabilities().MutatesData { + logs.MarkReadOnly() + } + err = e.ConsumeLogs(context.Background(), logs) + case "metrics": + e, ok := c.(processor.Metrics) + require.True(t, ok) + metrics := generateLifecycleTestMetrics() + if !e.Capabilities().MutatesData { + metrics.MarkReadOnly() + } + err = e.ConsumeMetrics(context.Background(), metrics) + case "traces": + e, ok := c.(processor.Traces) + require.True(t, ok) + traces := generateLifecycleTestTraces() + if !e.Capabilities().MutatesData { + traces.MarkReadOnly() + } + err = e.ConsumeTraces(context.Background(), traces) + } + }) + require.NoError(t, err) + err = c.Shutdown(context.Background()) + require.NoError(t, err) + }) } } diff --git a/processor/batchprocessor/metadata.yaml b/processor/batchprocessor/metadata.yaml index bbb94347c31..d96e0f80d9b 100644 --- a/processor/batchprocessor/metadata.yaml +++ b/processor/batchprocessor/metadata.yaml @@ -7,5 +7,3 @@ status: distributions: [core, contrib] tests: - # TODO: https://github.com/open-telemetry/opentelemetry-collector/issues/9688 - skip_lifecycle: true diff --git a/processor/memorylimiterprocessor/generated_component_test.go b/processor/memorylimiterprocessor/generated_component_test.go index 5c13dde733c..4179b548823 100644 --- a/processor/memorylimiterprocessor/generated_component_test.go +++ b/processor/memorylimiterprocessor/generated_component_test.go @@ -66,20 +66,26 @@ func TestComponentLifecycle(t *testing.T) { err = c.Start(context.Background(), host) require.NoError(t, err) require.NotPanics(t, func() { - switch e := c.(type) { - case processor.Logs: + switch test.name { + case "logs": + e, ok := c.(processor.Logs) + require.True(t, ok) logs := generateLifecycleTestLogs() if !e.Capabilities().MutatesData { logs.MarkReadOnly() } err = e.ConsumeLogs(context.Background(), logs) - case processor.Metrics: + case "metrics": + e, ok := c.(processor.Metrics) + require.True(t, ok) metrics := generateLifecycleTestMetrics() if !e.Capabilities().MutatesData { metrics.MarkReadOnly() } err = e.ConsumeMetrics(context.Background(), metrics) - case processor.Traces: + case "traces": + e, ok := c.(processor.Traces) + require.True(t, ok) traces := generateLifecycleTestTraces() if !e.Capabilities().MutatesData { traces.MarkReadOnly()