Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions service/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ type Collector struct {
// signalsChannel is used to receive termination signals from the OS.
signalsChannel chan os.Signal

allowGracefulShutodwn bool

// asyncErrorChannel is used to signal a fatal error from any component.
asyncErrorChannel chan error
}
Expand All @@ -89,6 +91,9 @@ func New(set CollectorSettings) (*Collector, error) {
info: set.BuildInfo,
factories: set.Factories,
stateChannel: make(chan State, Closed+1),
// We use a negative in the settings not to break the existing
// behavior. Internally, allowGracefulShutodwn is more readable.
allowGracefulShutodwn: !set.DisableGracefulShutdown,
}

rootCmd := &cobra.Command{
Expand Down Expand Up @@ -181,9 +186,11 @@ func (col *Collector) setupTelemetry(ballastSizeBytes uint64) error {
func (col *Collector) runAndWaitForShutdownEvent() {
col.logger.Info("Everything is ready. Begin running and processing data.")

// plug SIGTERM signal into a channel.
col.signalsChannel = make(chan os.Signal, 1)
signal.Notify(col.signalsChannel, os.Interrupt, syscall.SIGTERM)
// Only notify with SIGTERM and SIGINT if graceful shutdown is enabled.
if col.allowGracefulShutodwn {
signal.Notify(col.signalsChannel, os.Interrupt, syscall.SIGTERM)
}

col.shutdownChan = make(chan struct{})
col.stateChannel <- Running
Expand All @@ -193,7 +200,7 @@ func (col *Collector) runAndWaitForShutdownEvent() {
case s := <-col.signalsChannel:
col.logger.Info("Received signal from OS", zap.String("signal", s.String()))
case <-col.shutdownChan:
col.logger.Info("Received stop test request")
col.logger.Info("Received shutdown request")
}
col.stateChannel <- Closing
}
Expand Down
6 changes: 6 additions & 0 deletions service/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ type CollectorSettings struct {
// BuildInfo provides collector start information.
BuildInfo component.BuildInfo

// DisableGracefulShutdown disables the automatic graceful shutdown
// of the collector on SIGINT or SIGTERM.
// Users who want to handle signals themselves can disable this behavior
// and manually handle the signals to shutdown the collector.
DisableGracefulShutdown bool

// ParserProvider provides the configuration's Parser.
// If it is not provided a default provider is used. The default provider loads the configuration
// from a config file define by the --config command line flag and overrides component's configuration
Expand Down