Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

agent: disable metrics server by default #161

Merged
merged 1 commit into from
Sep 4, 2024
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
16 changes: 16 additions & 0 deletions agent/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,18 +219,34 @@ reconnect.`,
}

type ServerConfig struct {
// Enabled indicates whether to enable the agent metrics server.
Enabled bool `json:"enabled" yaml:"enabled"`

// BindAddr is the address to bind to listen for incoming HTTP connections.
BindAddr string `json:"bind_addr" yaml:"bind_addr"`
}

func (c *ServerConfig) Validate() error {
if !c.Enabled {
return nil
}
if c.BindAddr == "" {
return fmt.Errorf("missing bind addr")
}
return nil
}

func (c *ServerConfig) RegisterFlags(fs *pflag.FlagSet) {
fs.BoolVar(
&c.Enabled,
"server.enabled",
c.Enabled,
`
Whether to enable the agent metrics server.

Disabled by default.`,
)

fs.StringVar(
&c.BindAddr,
"server.bind-addr",
Expand Down
40 changes: 21 additions & 19 deletions cli/agent/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,27 +174,29 @@ func runAgent(conf *config.Config, logger log.Logger) error {
}

// Agent server.
serverLn, err := net.Listen("tcp", conf.Server.BindAddr)
if err != nil {
return fmt.Errorf("server listen: %s: %w", conf.Server.BindAddr, err)
}
server := server.NewServer(registry, logger)

group.Add(func() error {
if err := server.Serve(serverLn); err != nil {
return fmt.Errorf("agent server: %w", err)
if conf.Server.Enabled {
serverLn, err := net.Listen("tcp", conf.Server.BindAddr)
if err != nil {
return fmt.Errorf("server listen: %s: %w", conf.Server.BindAddr, err)
}
return nil
}, func(error) {
shutdownCtx, cancel := context.WithTimeout(
context.Background(), conf.GracePeriod,
)
defer cancel()
server := server.NewServer(registry, logger)

if err := server.Shutdown(shutdownCtx); err != nil {
logger.Warn("failed to gracefully shutdown agent server", zap.Error(err))
}
})
group.Add(func() error {
if err := server.Serve(serverLn); err != nil {
return fmt.Errorf("agent server: %w", err)
}
return nil
}, func(error) {
shutdownCtx, cancel := context.WithTimeout(
context.Background(), conf.GracePeriod,
)
defer cancel()

if err := server.Shutdown(shutdownCtx); err != nil {
logger.Warn("failed to gracefully shutdown agent server", zap.Error(err))
}
})
}

// Termination handler.
signalCtx, signalCancel := context.WithCancel(context.Background())
Expand Down
Loading