Skip to content

Commit

Permalink
[connector/datadog] fix start logic to start if tracesConsumer is pre…
Browse files Browse the repository at this point in the history
…sent; make shutdown work even if start was not called
  • Loading branch information
atoulme committed Jan 12, 2024
1 parent 93f7f52 commit 956ca0d
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 3 deletions.
27 changes: 27 additions & 0 deletions .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: []
7 changes: 5 additions & 2 deletions connector/datadogconnector/connector.go
Expand Up @@ -67,15 +67,15 @@ func newConnector(set component.TelemetrySettings, _ component.Config, metricsCo
in: in,
metricsConsumer: metricsConsumer,
tracesConsumer: tracesConsumer,
exit: make(chan struct{}),
}, nil
}

// Start implements the component.Component interface.
func (c *connectorImp) Start(_ context.Context, _ component.Host) error {
c.logger.Info("Starting datadogconnector")
c.agent.Start()
if c.metricsConsumer != nil {
c.exit = make(chan struct{})
if c.metricsConsumer != nil || c.tracesConsumer != nil {
go c.run()
}
return nil
Expand All @@ -84,6 +84,9 @@ func (c *connectorImp) Start(_ context.Context, _ component.Host) error {
// Shutdown implements the component.Component interface.
func (c *connectorImp) Shutdown(context.Context) error {
c.logger.Info("Shutting down datadog connector")
if c.exit == nil {
return nil
}
c.agent.Stop()
c.exit <- struct{}{} // signal exit
<-c.exit // wait for close
Expand Down
93 changes: 93 additions & 0 deletions connector/datadogconnector/generated_component_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion connector/datadogconnector/go.mod
Expand Up @@ -9,6 +9,7 @@ require (
github.com/open-telemetry/opentelemetry-collector-contrib/internal/datadog v0.92.0
github.com/stretchr/testify v1.8.4
go.opentelemetry.io/collector/component v0.92.1-0.20240110091511-bf804d6c4ecc
go.opentelemetry.io/collector/confmap v0.92.1-0.20240110091511-bf804d6c4ecc
go.opentelemetry.io/collector/connector v0.92.1-0.20240110091511-bf804d6c4ecc
go.opentelemetry.io/collector/consumer v0.92.1-0.20240110091511-bf804d6c4ecc
go.opentelemetry.io/collector/pdata v1.0.2-0.20240110091511-bf804d6c4ecc
Expand Down Expand Up @@ -72,7 +73,6 @@ require (
github.com/yusufpapurcu/wmi v1.2.3 // indirect
go.opentelemetry.io/collector v0.92.1-0.20240110091511-bf804d6c4ecc // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.92.1-0.20240110091511-bf804d6c4ecc // indirect
go.opentelemetry.io/collector/confmap v0.92.1-0.20240110091511-bf804d6c4ecc // indirect
go.opentelemetry.io/collector/featuregate v1.0.2-0.20240110091511-bf804d6c4ecc // indirect
go.opentelemetry.io/collector/semconv v0.92.1-0.20240110091511-bf804d6c4ecc // indirect
go.opentelemetry.io/otel v1.21.0 // indirect
Expand Down
3 changes: 3 additions & 0 deletions connector/datadogconnector/metadata.yaml
Expand Up @@ -8,3 +8,6 @@ status:
codeowners:
active: [mx-psi, dineshg13]
emeritus: [gbbr]

tests:
config:

0 comments on commit 956ca0d

Please sign in to comment.