Skip to content

Commit

Permalink
Change pprof setting name to monitoring.pprof.enabled
Browse files Browse the repository at this point in the history
Chagne the setting in elastic agent from agent.monioring.pprof to
agent.monitoring.pprof.enabled so that policy updates (such as the one
that occurs when the agent is starting in fleet mode) do not use the
default false value if the user has injected the ssetting into fleet.yml
  • Loading branch information
michel-laterman committed Dec 14, 2021
1 parent 91140b7 commit 4e6ecbb
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion x-pack/elastic-agent/_meta/config/common.p2.yml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ inputs:
# metrics: true
# # exposes /debug/pprof/ endpoints
# # recommended that these endpoints are only enabled if the monitoring endpoint is set to localhost
# pprof: false
# pprof.enabled: false
# # exposes agent metrics using http, by default sockets and named pipes are used
# http:
# # enables http endpoint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ inputs:
# metrics: false
# # exposes /debug/pprof/ endpoints
# # recommended that these endpoints are only enabled if the monitoring endpoint is set to localhost
# pprof: false
# pprof.enabled: false
# # exposes agent metrics using http, by default sockets and named pipes are used
# http:
# # enables http endpoint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ inputs:
# metrics: false
# # exposes /debug/pprof/ endpoints
# # recommended that these endpoints are only enabled if the monitoring endpoint is set to localhost
# pprof: false
# pprof.enabled: false
# # exposes agent metrics using http, by default sockets and named pipes are used
# http:
# # enables http endpoint
Expand Down
2 changes: 1 addition & 1 deletion x-pack/elastic-agent/elastic-agent.docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ inputs:
# metrics: false
# # exposes /debug/pprof/ endpoints
# # recommended that these endpoints are only enabled if the monitoring endpoint is set to localhost
# pprof: false
# pprof.enabled: false
# # exposes agent metrics using http, by default sockets and named pipes are used
# http:
# # enables http endpoint
Expand Down
2 changes: 1 addition & 1 deletion x-pack/elastic-agent/elastic-agent.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ inputs:
# metrics: false
# # exposes /debug/pprof/ endpoints
# # recommended that these endpoints are only enabled if the monitoring endpoint is set to localhost
# pprof: false
# pprof.enabled: false
# # exposes agent metrics using http, by default sockets and named pipes are used
# http:
# # enables http endpoint
Expand Down
2 changes: 1 addition & 1 deletion x-pack/elastic-agent/elastic-agent.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ inputs:
# metrics: true
# # exposes /debug/pprof/ endpoints
# # recommended that these endpoints are only enabled if the monitoring endpoint is set to localhost
# pprof: false
# pprof.enabled: false
# # exposes agent metrics using http, by default sockets and named pipes are used
# http:
# # enables http endpoint
Expand Down
2 changes: 1 addition & 1 deletion x-pack/elastic-agent/pkg/agent/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ func setupMetrics(agentInfo *info.AgentInfo, logger *logger.Logger, operatingSys
}
s.Start()

if cfg.Pprof {
if cfg.Pprof != nil && cfg.Pprof.Enabled {
s.AttachPprof()
}

Expand Down
2 changes: 1 addition & 1 deletion x-pack/elastic-agent/pkg/agent/control/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func (s *Server) ProcMeta(ctx context.Context, _ *proto.Empty) (*proto.ProcMetaR

// Pprof returns /debug/pprof data for the requested applicaiont-route_key or all running applications.
func (s *Server) Pprof(ctx context.Context, req *proto.PprofRequest) (*proto.PprofResponse, error) {
if s.monitoringCfg == nil || !s.monitoringCfg.Pprof {
if s.monitoringCfg == nil || s.monitoringCfg.Pprof == nil || !s.monitoringCfg.Pprof.Enabled {
return nil, fmt.Errorf("agent.monitoring.pprof disabled")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type Monitor struct {
func NewMonitor(downloadConfig *artifact.Config, monitoringCfg *monitoringConfig.MonitoringConfig, logMetrics bool) *Monitor {
if monitoringCfg == nil {
monitoringCfg = monitoringConfig.DefaultConfig()
monitoringCfg.Pprof = &monitoringConfig.PprofConfig{Enabled: false}
}
monitoringCfg.LogMetrics = logMetrics

Expand All @@ -55,6 +56,9 @@ func (b *Monitor) Reload(rawConfig *config.Config) error {
if cfg == nil || cfg.Settings == nil || cfg.Settings.MonitoringConfig == nil {
b.config = monitoringConfig.DefaultConfig()
} else {
if cfg.Settings.MonitoringConfig.Pprof == nil {
cfg.Settings.MonitoringConfig.Pprof = b.config.Pprof
}
b.config = cfg.Settings.MonitoringConfig
logMetrics := true
if cfg.Settings.LoggingConfig != nil {
Expand Down Expand Up @@ -123,7 +127,7 @@ func (b *Monitor) EnrichArgs(spec program.Spec, pipelineID string, args []string
"-E", "http.enabled=true",
"-E", "http.host="+endpoint,
)
if b.config.Pprof {
if b.config.Pprof != nil && b.config.Pprof.Enabled {
appendix = append(appendix,
"-E", "http.pprof.enabled=true",
)
Expand Down
10 changes: 8 additions & 2 deletions x-pack/elastic-agent/pkg/core/monitoring/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type MonitoringConfig struct {
LogMetrics bool `yaml:"-" config:"-"`
HTTP *MonitoringHTTPConfig `yaml:"http" config:"http"`
Namespace string `yaml:"namespace" config:"namespace"`
Pprof bool `yaml:"pprof" config:"pprof"`
Pprof *PprofConfig `yaml:"pprof" config:"pprof"`
}

// MonitoringHTTPConfig is a config defining HTTP endpoint published by agent
Expand All @@ -27,6 +27,13 @@ type MonitoringHTTPConfig struct {
Port int `yaml:"port" config:"port" validate:"min=0,max=65535,nonzero"`
}

// PprofConfig is a struct for the pprof enablement flag.
// It is a nil struct by default to allow the agent to use the a value that the user has injected into fleet.yml as the source of truth that is passed to beats
// TODO get this value from Kibana?
type PprofConfig struct {
Enabled bool `yaml:"enabled" config:"enabled"`
}

// DefaultConfig creates a config with pre-set default values.
func DefaultConfig() *MonitoringConfig {
return &MonitoringConfig{
Expand All @@ -39,6 +46,5 @@ func DefaultConfig() *MonitoringConfig {
Port: defaultPort,
},
Namespace: defaultNamespace,
Pprof: false,
}
}

0 comments on commit 4e6ecbb

Please sign in to comment.