Skip to content

Commit

Permalink
[chore][connector/datadogconnector] Fix connector traceToMetrics life…
Browse files Browse the repository at this point in the history
…cycle (#31811)

**Description:**
Currently, calling `Shutdown` on the `traceToMetricConnector` requires
on `Start` being called before, as the `Shutdown` relies on goroutines
which are spawned during `Start`. This causes the connector to hang if a
call to `Shutdown` is made without a call to `Start`. This PR adds a
`isStarted` field to the `traceToMetricConnector` struct, which tracks
whether `Start` was called. If it was not, it makes the call to
`Shutdown` a no-op.

**Link to tracking Issue:** #30487

**Testing:** <Describe what testing was performed and which tests were
added.>

**Documentation:** <Describe the documentation added.>

---------

Co-authored-by: Antoine Toulme <antoine@toulme.name>
  • Loading branch information
mackjmr and atoulme committed Mar 19, 2024
1 parent d37d7b4 commit fbcf535
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 3 deletions.
9 changes: 9 additions & 0 deletions connector/datadogconnector/connector.go
Expand Up @@ -42,6 +42,9 @@ type traceToMetricConnector struct {

// exit specifies the exit channel, which will be closed upon shutdown.
exit chan struct{}

// isStarted tracks whether Start() has been called.
isStarted bool
}

var _ component.Component = (*traceToMetricConnector)(nil) // testing that the connectorImp properly implements the type Component interface
Expand Down Expand Up @@ -91,11 +94,17 @@ func (c *traceToMetricConnector) Start(_ context.Context, _ component.Host) erro
c.logger.Info("Starting datadogconnector")
c.agent.Start()
go c.run()
c.isStarted = true
return nil
}

// Shutdown implements the component.Component interface.
func (c *traceToMetricConnector) Shutdown(context.Context) error {
if !c.isStarted {
// Note: it is not necessary to manually close c.exit, c.in and c.agent.(*datadog.TraceAgent).exit channels as these are unused.
c.logger.Info("Requested shutdown, but not started, ignoring.")
return nil
}
c.logger.Info("Shutting down datadog connector")
c.logger.Info("Stopping datadog agent")
// stop the agent and wait for the run loop to exit
Expand Down
68 changes: 68 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 @@ -13,6 +13,7 @@ require (
github.com/open-telemetry/opentelemetry-collector-contrib/processor/tailsamplingprocessor v0.96.0
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/collector/component v0.96.1-0.20240315172937-3b5aee0c7a16
go.opentelemetry.io/collector/confmap v0.96.1-0.20240315172937-3b5aee0c7a16
go.opentelemetry.io/collector/connector v0.96.1-0.20240315172937-3b5aee0c7a16
go.opentelemetry.io/collector/consumer v0.96.1-0.20240315172937-3b5aee0c7a16
go.opentelemetry.io/collector/exporter v0.96.1-0.20240315172937-3b5aee0c7a16
Expand Down Expand Up @@ -148,7 +149,6 @@ require (
go.opentelemetry.io/collector/config/configtelemetry v0.96.1-0.20240315172937-3b5aee0c7a16 // indirect
go.opentelemetry.io/collector/config/configtls v0.96.1-0.20240315172937-3b5aee0c7a16 // indirect
go.opentelemetry.io/collector/config/internal v0.96.1-0.20240315172937-3b5aee0c7a16 // indirect
go.opentelemetry.io/collector/confmap v0.96.1-0.20240315172937-3b5aee0c7a16 // indirect
go.opentelemetry.io/collector/confmap/converter/expandconverter v0.96.1-0.20240315172937-3b5aee0c7a16 // indirect
go.opentelemetry.io/collector/confmap/provider/envprovider v0.96.1-0.20240315172937-3b5aee0c7a16 // indirect
go.opentelemetry.io/collector/confmap/provider/fileprovider v0.96.1-0.20240315172937-3b5aee0c7a16 // indirect
Expand Down
2 changes: 0 additions & 2 deletions connector/datadogconnector/metadata.yaml
Expand Up @@ -11,5 +11,3 @@ status:
emeritus: [gbbr]

tests:
skip_lifecycle: true
skip_shutdown: true

0 comments on commit fbcf535

Please sign in to comment.