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
|
@ -329,10 +329,19 @@ type agentOptions struct {
|
||||||
config *config.RuntimeConfig
|
config *config.RuntimeConfig
|
||||||
overrides []config.Source
|
overrides []config.Source
|
||||||
writers []io.Writer
|
writers []io.Writer
|
||||||
|
initTelemetry bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type AgentOption func(opt *agentOptions)
|
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
|
// WithLogger is used to override any automatic logger creation
|
||||||
// and provide one already built instead. This is mostly useful
|
// and provide one already built instead. This is mostly useful
|
||||||
// for testing.
|
// for testing.
|
||||||
|
@ -473,11 +482,13 @@ func New(options ...AgentOption) (*Agent, error) {
|
||||||
grpclog.SetLoggerV2(logging.NewGRPCLogger(logConf, a.logger))
|
grpclog.SetLoggerV2(logging.NewGRPCLogger(logConf, a.logger))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if flat.initTelemetry {
|
||||||
memSink, err := lib.InitTelemetry(config.Telemetry)
|
memSink, err := lib.InitTelemetry(config.Telemetry)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Failed to initialize telemetry: %w", err)
|
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
|
// 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
|
// 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.WithBuilderOpts(c.flagArgs),
|
||||||
agent.WithCLI(c.UI),
|
agent.WithCLI(c.UI),
|
||||||
agent.WithLogWriter(&logGate),
|
agent.WithLogWriter(&logGate),
|
||||||
|
agent.WithTelemetry(true),
|
||||||
}
|
}
|
||||||
|
|
||||||
agent, err := agent.New(agentOptions...)
|
agent, err := agent.New(agentOptions...)
|
||||||
|
|
Loading…
Reference in New Issue