From 5b544f066a91bd584eee88dab305ff86fbf11142 Mon Sep 17 00:00:00 2001 From: Antoine Toulme Date: Thu, 11 Jan 2024 23:16:43 -0800 Subject: [PATCH 1/3] [connector/datadog] fix start logic to start if tracesConsumer is present; make shutdown work even if start was not called --- .chloggen/fix_datadogconnector_start.yaml | 27 ++++++ connector/datadogconnector/connector.go | 2 +- .../generated_component_test.go | 93 +++++++++++++++++++ connector/datadogconnector/go.mod | 2 +- connector/datadogconnector/metadata.yaml | 3 + 5 files changed, 125 insertions(+), 2 deletions(-) create mode 100755 .chloggen/fix_datadogconnector_start.yaml create mode 100644 connector/datadogconnector/generated_component_test.go diff --git a/.chloggen/fix_datadogconnector_start.yaml b/.chloggen/fix_datadogconnector_start.yaml new file mode 100755 index 000000000000..89aed7b79bcf --- /dev/null +++ b/.chloggen/fix_datadogconnector_start.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: bug_fix + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: datadogconnector + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Start the datadog connector when used for traces only. Support shutdown without start first. + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [30472] + +# (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: + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# 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/connector/datadogconnector/connector.go b/connector/datadogconnector/connector.go index 51df15427d6f..0d2352d8d247 100644 --- a/connector/datadogconnector/connector.go +++ b/connector/datadogconnector/connector.go @@ -65,7 +65,7 @@ func newTraceToMetricConnector(set component.TelemetrySettings, cfg component.Co translator: trans, in: in, metricsConsumer: metricsConsumer, - exit: make(chan struct{}), + tracesConsumer: tracesConsumer, }, nil } diff --git a/connector/datadogconnector/generated_component_test.go b/connector/datadogconnector/generated_component_test.go new file mode 100644 index 000000000000..105efdb4c774 --- /dev/null +++ b/connector/datadogconnector/generated_component_test.go @@ -0,0 +1,93 @@ +// Code generated by mdatagen. DO NOT EDIT. + +package datadogconnector + +import ( + "context" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/component/componenttest" + + "go.opentelemetry.io/collector/connector" + "go.opentelemetry.io/collector/connector/connectortest" + "go.opentelemetry.io/collector/consumer/consumertest" + + "go.opentelemetry.io/collector/confmap/confmaptest" +) + +// assertNoErrorHost implements a component.Host that asserts that there were no errors. +type assertNoErrorHost struct { + component.Host + *testing.T +} + +var _ component.Host = (*assertNoErrorHost)(nil) + +// newAssertNoErrorHost returns a new instance of assertNoErrorHost. +func newAssertNoErrorHost(t *testing.T) component.Host { + return &assertNoErrorHost{ + componenttest.NewNopHost(), + t, + } +} + +func (aneh *assertNoErrorHost) ReportFatalError(err error) { + assert.NoError(aneh, err) +} + +func TestComponentLifecycle(t *testing.T) { + factory := NewFactory() + + tests := []struct { + name string + createFn func(ctx context.Context, set connector.CreateSettings, cfg component.Config) (component.Component, error) + }{ + + { + name: "traces_to_metrics", + createFn: func(ctx context.Context, set connector.CreateSettings, cfg component.Config) (component.Component, error) { + return factory.CreateTracesToMetrics(ctx, set, cfg, consumertest.NewNop()) + }, + }, + + { + name: "traces_to_traces", + createFn: func(ctx context.Context, set connector.CreateSettings, cfg component.Config) (component.Component, error) { + return factory.CreateTracesToTraces(ctx, set, cfg, consumertest.NewNop()) + }, + }, + } + + cm, err := confmaptest.LoadConf("metadata.yaml") + require.NoError(t, err) + cfg := factory.CreateDefaultConfig() + sub, err := cm.Sub("tests::config") + require.NoError(t, err) + require.NoError(t, component.UnmarshalConfig(sub, cfg)) + + for _, test := range tests { + t.Run(test.name+"-shutdown", func(t *testing.T) { + c, err := test.createFn(context.Background(), connectortest.NewNopCreateSettings(), cfg) + require.NoError(t, err) + err = c.Shutdown(context.Background()) + require.NoError(t, err) + }) + + t.Run(test.name+"-lifecycle", func(t *testing.T) { + + firstConnector, err := test.createFn(context.Background(), connectortest.NewNopCreateSettings(), cfg) + require.NoError(t, err) + host := newAssertNoErrorHost(t) + require.NoError(t, err) + require.NoError(t, firstConnector.Start(context.Background(), host)) + require.NoError(t, firstConnector.Shutdown(context.Background())) + secondConnector, err := test.createFn(context.Background(), connectortest.NewNopCreateSettings(), cfg) + require.NoError(t, err) + require.NoError(t, secondConnector.Start(context.Background(), host)) + require.NoError(t, secondConnector.Shutdown(context.Background())) + }) + } +} diff --git a/connector/datadogconnector/go.mod b/connector/datadogconnector/go.mod index 9713c573c70c..a045ccdd59cd 100644 --- a/connector/datadogconnector/go.mod +++ b/connector/datadogconnector/go.mod @@ -12,6 +12,7 @@ require ( github.com/open-telemetry/opentelemetry-collector-contrib/processor/tailsamplingprocessor v0.95.0 github.com/stretchr/testify v1.8.4 go.opentelemetry.io/collector/component v0.95.0 + go.opentelemetry.io/collector/confmap v0.95.0 go.opentelemetry.io/collector/connector v0.95.0 go.opentelemetry.io/collector/consumer v0.95.0 go.opentelemetry.io/collector/exporter v0.95.0 @@ -149,7 +150,6 @@ require ( go.opentelemetry.io/collector/config/configtelemetry v0.95.0 // indirect go.opentelemetry.io/collector/config/configtls v0.95.0 // indirect go.opentelemetry.io/collector/config/internal v0.95.0 // indirect - go.opentelemetry.io/collector/confmap v0.95.0 // indirect go.opentelemetry.io/collector/confmap/converter/expandconverter v0.95.0 // indirect go.opentelemetry.io/collector/confmap/provider/envprovider v0.95.0 // indirect go.opentelemetry.io/collector/confmap/provider/fileprovider v0.95.0 // indirect diff --git a/connector/datadogconnector/metadata.yaml b/connector/datadogconnector/metadata.yaml index 907ef0b3c104..66bac9e10f8b 100644 --- a/connector/datadogconnector/metadata.yaml +++ b/connector/datadogconnector/metadata.yaml @@ -8,3 +8,6 @@ status: codeowners: active: [mx-psi, dineshg13] emeritus: [gbbr] + +tests: + config: From 9abd5daa646ca99e44ae5067a02a0f3d39a45dd3 Mon Sep 17 00:00:00 2001 From: Antoine Toulme Date: Fri, 12 Jan 2024 11:55:48 -0800 Subject: [PATCH 2/3] code review changes --- connector/datadogconnector/connector.go | 1 - 1 file changed, 1 deletion(-) diff --git a/connector/datadogconnector/connector.go b/connector/datadogconnector/connector.go index 0d2352d8d247..64942c7f2b31 100644 --- a/connector/datadogconnector/connector.go +++ b/connector/datadogconnector/connector.go @@ -65,7 +65,6 @@ func newTraceToMetricConnector(set component.TelemetrySettings, cfg component.Co translator: trans, in: in, metricsConsumer: metricsConsumer, - tracesConsumer: tracesConsumer, }, nil } From e5777585e0bf4391440c4eeb8c2c9b472b4e03c3 Mon Sep 17 00:00:00 2001 From: Antoine Toulme Date: Fri, 12 Jan 2024 11:56:39 -0800 Subject: [PATCH 3/3] update issue in changelog --- .chloggen/fix_datadogconnector_start.yaml | 27 ----------------------- connector/datadogconnector/connector.go | 1 + 2 files changed, 1 insertion(+), 27 deletions(-) delete mode 100755 .chloggen/fix_datadogconnector_start.yaml diff --git a/.chloggen/fix_datadogconnector_start.yaml b/.chloggen/fix_datadogconnector_start.yaml deleted file mode 100755 index 89aed7b79bcf..000000000000 --- a/.chloggen/fix_datadogconnector_start.yaml +++ /dev/null @@ -1,27 +0,0 @@ -# Use this changelog template to create an entry for release notes. - -# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' -change_type: bug_fix - -# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) -component: datadogconnector - -# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). -note: Start the datadog connector when used for traces only. Support shutdown without start first. - -# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. -issues: [30472] - -# (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: - -# If your change doesn't affect end users or the exported elements of any package, -# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. -# 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/connector/datadogconnector/connector.go b/connector/datadogconnector/connector.go index 64942c7f2b31..51df15427d6f 100644 --- a/connector/datadogconnector/connector.go +++ b/connector/datadogconnector/connector.go @@ -65,6 +65,7 @@ func newTraceToMetricConnector(set component.TelemetrySettings, cfg component.Co translator: trans, in: in, metricsConsumer: metricsConsumer, + exit: make(chan struct{}), }, nil }