mirror of https://github.com/status-im/consul.git
Don’t leak metrics go routines in tests (#8182)
This commit is contained in:
parent
0db4cb305f
commit
e2cfa93f02
|
@ -323,16 +323,25 @@ type Agent struct {
|
|||
}
|
||||
|
||||
type agentOptions struct {
|
||||
logger hclog.InterceptLogger
|
||||
builderOpts config.BuilderOpts
|
||||
ui cli.Ui
|
||||
config *config.RuntimeConfig
|
||||
overrides []config.Source
|
||||
writers []io.Writer
|
||||
logger hclog.InterceptLogger
|
||||
builderOpts config.BuilderOpts
|
||||
ui cli.Ui
|
||||
config *config.RuntimeConfig
|
||||
overrides []config.Source
|
||||
writers []io.Writer
|
||||
initTelemetry bool
|
||||
}
|
||||
|
||||
type AgentOption func(opt *agentOptions)
|
||||
|
||||
// WithTelemetry is used to control whether the agent will
|
||||
// set up metrics.
|
||||
func WithTelemetry(initTelemetry bool) AgentOption {
|
||||
return func(opt *agentOptions) {
|
||||
opt.initTelemetry = initTelemetry
|
||||
}
|
||||
}
|
||||
|
||||
// WithLogger is used to override any automatic logger creation
|
||||
// and provide one already built instead. This is mostly useful
|
||||
// for testing.
|
||||
|
@ -473,11 +482,13 @@ func New(options ...AgentOption) (*Agent, error) {
|
|||
grpclog.SetLoggerV2(logging.NewGRPCLogger(logConf, a.logger))
|
||||
}
|
||||
|
||||
memSink, err := lib.InitTelemetry(config.Telemetry)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Failed to initialize telemetry: %w", err)
|
||||
if flat.initTelemetry {
|
||||
memSink, err := lib.InitTelemetry(config.Telemetry)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Failed to initialize telemetry: %w", err)
|
||||
}
|
||||
a.MemSink = memSink
|
||||
}
|
||||
a.MemSink = memSink
|
||||
|
||||
// TODO (autoconf) figure out how to let this setting be pushed down via autoconf
|
||||
// right now it gets defaulted if unset so this check actually doesn't do much
|
||||
|
|
|
@ -171,6 +171,7 @@ func (c *cmd) run(args []string) int {
|
|||
agent.WithBuilderOpts(c.flagArgs),
|
||||
agent.WithCLI(c.UI),
|
||||
agent.WithLogWriter(&logGate),
|
||||
agent.WithTelemetry(true),
|
||||
}
|
||||
|
||||
agent, err := agent.New(agentOptions...)
|
||||
|
|
Loading…
Reference in New Issue