Skip to content

Commit

Permalink
[exporter/loadbalancer] close exporters on shutdown (#36024)
Browse files Browse the repository at this point in the history
#### Description

I noticed that we don't close the exporters during shutdown. This PR
iterates through the exporters and closes them in a graceful manner.
  • Loading branch information
VihasMakwana authored Nov 18, 2024
1 parent bf5cd1c commit 830ffbf
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 20 deletions.
27 changes: 27 additions & 0 deletions .chloggen/loadbalancer-exporter-shutdown.yaml
Original file line number Diff line number Diff line change
@@ -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: exporter/loadbalancing

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Shutdown exporters during collector shutdown. This fixes a memory leak.

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [36024]

# (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: []
4 changes: 4 additions & 0 deletions exporter/loadbalancingexporter/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ func endpointFound(endpoint string, endpoints []string) bool {
func (lb *loadBalancer) Shutdown(ctx context.Context) error {
err := lb.res.shutdown(ctx)
lb.stopped = true

for _, e := range lb.exporters {
err = errors.Join(err, e.Shutdown(ctx))
}
return err
}

Expand Down
14 changes: 7 additions & 7 deletions exporter/loadbalancingexporter/log_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,14 +302,14 @@ func TestConsumeLogs_ConcurrentResolverChange(t *testing.T) {
consumeStarted := make(chan struct{})
consumeDone := make(chan struct{})

// imitate a slow exporter
te := &mockLogsExporter{Component: mockComponent{}}
te.consumelogsfn = func(_ context.Context, _ plog.Logs) error {
close(consumeStarted)
time.Sleep(50 * time.Millisecond)
return te.consumeErr
}
componentFactory := func(_ context.Context, _ string) (component.Component, error) {
// imitate a slow exporter
te := &mockLogsExporter{Component: mockComponent{}}
te.consumelogsfn = func(_ context.Context, _ plog.Logs) error {
close(consumeStarted)
time.Sleep(50 * time.Millisecond)
return te.consumeErr
}
return te, nil
}
lb, err := newLoadBalancer(ts.Logger, simpleConfig(), componentFactory, tb)
Expand Down
14 changes: 7 additions & 7 deletions exporter/loadbalancingexporter/metrics_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,14 +553,14 @@ func TestConsumeMetrics_ConcurrentResolverChange(t *testing.T) {
consumeStarted := make(chan struct{})
consumeDone := make(chan struct{})

// imitate a slow exporter
te := &mockMetricsExporter{Component: mockComponent{}}
te.ConsumeMetricsFn = func(_ context.Context, _ pmetric.Metrics) error {
close(consumeStarted)
time.Sleep(50 * time.Millisecond)
return te.consumeErr
}
componentFactory := func(_ context.Context, _ string) (component.Component, error) {
// imitate a slow exporter
te := &mockMetricsExporter{Component: mockComponent{}}
te.ConsumeMetricsFn = func(_ context.Context, _ pmetric.Metrics) error {
close(consumeStarted)
time.Sleep(50 * time.Millisecond)
return te.consumeErr
}
return te, nil
}
lb, err := newLoadBalancer(ts.Logger, simpleConfig(), componentFactory, tb)
Expand Down
12 changes: 6 additions & 6 deletions exporter/loadbalancingexporter/trace_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,13 @@ func TestConsumeTraces_ConcurrentResolverChange(t *testing.T) {
consumeDone := make(chan struct{})

// imitate a slow exporter
te := &mockTracesExporter{Component: mockComponent{}}
te.ConsumeTracesFn = func(_ context.Context, _ ptrace.Traces) error {
close(consumeStarted)
time.Sleep(50 * time.Millisecond)
return te.consumeErr
}
componentFactory := func(_ context.Context, _ string) (component.Component, error) {
te := &mockTracesExporter{Component: mockComponent{}}
te.ConsumeTracesFn = func(_ context.Context, _ ptrace.Traces) error {
close(consumeStarted)
time.Sleep(50 * time.Millisecond)
return te.consumeErr
}
return te, nil
}
lb, err := newLoadBalancer(ts.Logger, simpleConfig(), componentFactory, tb)
Expand Down

0 comments on commit 830ffbf

Please sign in to comment.