Skip to content

Commit

Permalink
Added cleanup if service errors on Start
Browse files Browse the repository at this point in the history
Signed-off-by: Corbin Phelps <corbin.phelps@bluemedora.com>
  • Loading branch information
Corbin Phelps committed Oct 24, 2022
1 parent ef4d4e2 commit d6b8e68
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
16 changes: 16 additions & 0 deletions .chloggen/service-cleanup-on-start-error.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 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. otlpreceiver)
component: collector

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Fixed collector service not cleaning up if it failed during Start

# One or more tracking issues or pull requests related to the change
issues: []

# (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:
8 changes: 3 additions & 5 deletions service/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ func (col *Collector) setupConfigurationComponents(ctx context.Context) error {
}

if err = col.service.Start(ctx); err != nil {
if shutdownErr := col.service.Shutdown(ctx); shutdownErr != nil {
return multierr.Append(err, fmt.Errorf("failed to shutdown service after error: %w", shutdownErr))
}
return err
}
col.setCollectorState(Running)
Expand Down Expand Up @@ -219,11 +222,6 @@ func (col *Collector) shutdown(ctx context.Context) error {
errs = multierr.Append(errs, fmt.Errorf("failed to shutdown service: %w", err))
}

// TODO: Move this as part of the service shutdown.
if err := col.service.telemetryInitializer.shutdown(); err != nil {
errs = multierr.Append(errs, fmt.Errorf("failed to shutdown collector telemetry: %w", err))
}

col.setCollectorState(Closed)

return errs
Expand Down
4 changes: 4 additions & 0 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func newService(set *settings) (*service, error) {
return srv, nil
}

// Start starts the extensions and pipelines. If Start fails Shutdown should be called to ensure a clean state.
func (srv *service) Start(ctx context.Context) error {
srv.telemetrySettings.Logger.Info("Starting "+srv.buildInfo.Command+"...",
zap.String("Version", srv.buildInfo.Version),
Expand Down Expand Up @@ -131,6 +132,9 @@ func (srv *service) Shutdown(ctx context.Context) error {
errs = multierr.Append(errs, fmt.Errorf("failed to shutdown telemetry: %w", err))
}

if err := srv.telemetryInitializer.shutdown(); err != nil {
errs = multierr.Append(errs, fmt.Errorf("failed to shutdown telemetry initializer: %w", err))
}
// TODO: Shutdown MeterProvider.
return errs
}
Expand Down

0 comments on commit d6b8e68

Please sign in to comment.