Skip to content

Commit

Permalink
config: config for profiling the server
Browse files Browse the repository at this point in the history
  • Loading branch information
axw committed Nov 21, 2019
1 parent 29ae16b commit 8a8bfd8
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 5 deletions.
14 changes: 14 additions & 0 deletions _meta/beat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ apm-server:
# secret_token for the remote apm-servers.
#secret_token:

# Enable profiling of the server, recording profile samples as events.
#
# This feature is experimental.
#profiling:
#cpu:
# Set to true to enable CPU profiling.
#enabled: false
#interval: 60s
#duration: 10s
#heap:
# Set to true to enable heap profiling.
#enabled: false
#interval: 60s

# A pipeline is a definition of processors applied to documents when ingesting them to Elasticsearch.
# Using pipelines involves two steps:
# (1) registering a pipeline
Expand Down
14 changes: 14 additions & 0 deletions apm-server.docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ apm-server:
# secret_token for the remote apm-servers.
#secret_token:

# Enable profiling of the server, recording profile samples as events.
#
# This feature is experimental.
#profiling:
#cpu:
# Set to true to enable CPU profiling.
#enabled: false
#interval: 60s
#duration: 10s
#heap:
# Set to true to enable heap profiling.
#enabled: false
#interval: 60s

# A pipeline is a definition of processors applied to documents when ingesting them to Elasticsearch.
# Using pipelines involves two steps:
# (1) registering a pipeline
Expand Down
14 changes: 14 additions & 0 deletions apm-server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ apm-server:
# secret_token for the remote apm-servers.
#secret_token:

# Enable profiling of the server, recording profile samples as events.
#
# This feature is experimental.
#profiling:
#cpu:
# Set to true to enable CPU profiling.
#enabled: false
#interval: 60s
#duration: 10s
#heap:
# Set to true to enable heap profiling.
#enabled: false
#interval: 60s

# A pipeline is a definition of processors applied to documents when ingesting them to Elasticsearch.
# Using pipelines involves two steps:
# (1) registering a pipeline
Expand Down
54 changes: 49 additions & 5 deletions beater/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ const (
DefaultAPMPipeline = "apm"

msgInvalidConfigAgentCfg = "invalid value for `apm-server.agent.config.cache.expiration`, only accepting full seconds"

defaultCPUProfilingInterval = 1 * time.Minute
defaultCPUProfilingDuration = 10 * time.Second
defaultHeapProfilingInterval = 1 * time.Minute
)

// Config holds configuration information nested under the key `apm-server`
Expand Down Expand Up @@ -130,10 +134,36 @@ type Cache struct {

// InstrumentationConfig holds config information about self instrumenting the APM Server
type InstrumentationConfig struct {
Enabled *bool `config:"enabled"`
Environment *string `config:"environment"`
Hosts urls `config:"hosts" validate:"nonzero"`
SecretToken string `config:"secret_token"`
Enabled *bool `config:"enabled"`
Environment *string `config:"environment"`
Hosts urls `config:"hosts" validate:"nonzero"`
Profiling ProfilingConfig `config:"profiling"`
SecretToken string `config:"secret_token"`
}

// ProfilingConfig holds config information about self profiling the APM Server
type ProfilingConfig struct {
CPU *CPUProfiling `config:"cpu"`
Heap *HeapProfiling `config:"heap"`
}

type CPUProfiling struct {
Enabled bool `config:"enabled"`
Interval time.Duration `config:"interval" validate:"positive"`
Duration time.Duration `config:"duration" validate:"positive"`
}

func (p *CPUProfiling) IsEnabled() bool {
return p != nil && p.Enabled
}

type HeapProfiling struct {
Enabled bool `config:"enabled"`
Interval time.Duration `config:"interval" validate:"positive"`
}

func (p *HeapProfiling) IsEnabled() bool {
return p != nil && p.Enabled
}

//Mode enumerates the APM Server env
Expand Down Expand Up @@ -189,7 +219,21 @@ func NewConfig(version string, ucfg *common.Config) (*Config, error) {
return nil, errors.New(fmt.Sprintf("Invalid regex for `exclude_from_grouping`: %v", err.Error()))
}
}

if c.SelfInstrumentation.IsEnabled() {
if c.SelfInstrumentation.Profiling.CPU.IsEnabled() {
if c.SelfInstrumentation.Profiling.CPU.Interval <= 0 {
c.SelfInstrumentation.Profiling.CPU.Interval = defaultCPUProfilingInterval
}
if c.SelfInstrumentation.Profiling.CPU.Duration <= 0 {
c.SelfInstrumentation.Profiling.CPU.Duration = defaultCPUProfilingDuration
}
}
if c.SelfInstrumentation.Profiling.Heap.IsEnabled() {
if c.SelfInstrumentation.Profiling.Heap.Interval <= 0 {
c.SelfInstrumentation.Profiling.Heap.Interval = defaultHeapProfilingInterval
}
}
}
return c, nil
}

Expand Down

0 comments on commit 8a8bfd8

Please sign in to comment.