Skip to content

Commit

Permalink
[chore] manage jmx receiver lifecycle (open-telemetry#17554)
Browse files Browse the repository at this point in the history
Handle the shutdown of the jmx receiver properly, providing a valid config so it can be created
  • Loading branch information
atoulme committed Jan 13, 2023
1 parent 01a1e03 commit dc7d849
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions internal/components/receivers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/carbonreceiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/chronyreceiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/filelogreceiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jmxreceiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/mongodbatlasreceiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/otlpjsonfilereceiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver"
Expand Down Expand Up @@ -198,6 +199,12 @@ func TestDefaultReceivers(t *testing.T) {
{
receiver: "jmx",
skipLifecyle: true, // Requires a running instance with JMX
getConfigFn: func() component.Config {
cfg := jmxreceiver.NewFactory().CreateDefaultConfig().(*jmxreceiver.Config)
cfg.Endpoint = "localhost:1234"
cfg.TargetSystem = "jvm"
return cfg
},
},
{
receiver: "journald",
Expand Down
3 changes: 3 additions & 0 deletions receiver/jmxreceiver/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ func (jmx *jmxMetricReceiver) Start(ctx context.Context, host component.Host) er
}

func (jmx *jmxMetricReceiver) Shutdown(ctx context.Context) error {
if jmx.subprocess == nil {
return nil
}
jmx.logger.Debug("Shutting down JMX Receiver")
subprocessErr := jmx.subprocess.Shutdown(ctx)
otlpErr := jmx.otlpReceiver.Shutdown(ctx)
Expand Down

0 comments on commit dc7d849

Please sign in to comment.