Skip to content

Commit

Permalink
hoststats: cancel host collector when base deps Close is called
Browse files Browse the repository at this point in the history
  • Loading branch information
nickethier committed May 30, 2023
1 parent 369619b commit b7f5032
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions agent/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type BaseDeps struct {
WatchedFiles []string

deregisterBalancer, deregisterResolver func()
stopHostCollector func()
}

type ConfigLoader func(source config.Source) (config.LoadResult, error)
Expand Down Expand Up @@ -119,8 +120,10 @@ func NewBaseDeps(configLoader ConfigLoader, logOut io.Writer, providedLogger hcl
if err != nil {
return d, fmt.Errorf("failed to initialize telemetry: %w", err)
}
if !cfg.Telemetry.DisableHostMetrics {
hoststats.NewCollector(context.Background(), d.Logger, cfg.DataDir)
if !cfg.Telemetry.Disable && !cfg.Telemetry.DisableHostMetrics {
ctx, cancel := context.WithCancel(context.Background())
hoststats.NewCollector(ctx, d.Logger, cfg.DataDir)
d.stopHostCollector = cancel
}

d.TLSConfigurator, err = tlsutil.NewConfigurator(cfg.TLS, d.Logger)
Expand Down Expand Up @@ -219,11 +222,10 @@ func (bd BaseDeps) Close() {
bd.AutoConfig.Stop()
bd.MetricsConfig.Cancel()

if fn := bd.deregisterBalancer; fn != nil {
fn()
}
if fn := bd.deregisterResolver; fn != nil {
fn()
for _, fn := range []func(){bd.deregisterBalancer, bd.deregisterResolver, bd.stopHostCollector} {
if fn != nil {
fn()
}
}
}

Expand Down

0 comments on commit b7f5032

Please sign in to comment.