Skip to content

Commit

Permalink
[7.13](backport #25394) Add support to set gc percentage (#25488)
Browse files Browse the repository at this point in the history
Co-authored-by: Steffen Siering <steffen.siering@elastic.co>
  • Loading branch information
mergify[bot] and Steffen Siering committed May 3, 2021
1 parent a744117 commit b4980c7
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Add kubernetes.pod.ip field in kubernetes metadata. {pull}25037[25037]
- Discover changes in Kubernetes namespace metadata as soon as they happen. {pull}25117[25117]
- Add `decode_xml_wineventlog` processor. {issue}23910[23910] {pull}25115[25115]
- Add new setting `gc_percent` for tuning the garbage collector limits via configuration file. {pull}25394[25394]

*Auditbeat*

Expand Down
14 changes: 11 additions & 3 deletions libbeat/cmd/instance/beat.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"math/rand"
"os"
"runtime"
"runtime/debug"
"strings"
"time"

Expand Down Expand Up @@ -94,9 +95,11 @@ type beatConfig struct {
// instance internal configs

// beat top-level settings
Name string `config:"name"`
MaxProcs int `config:"max_procs"`
Seccomp *common.Config `config:"seccomp"`
Name string `config:"name"`
MaxProcs int `config:"max_procs"`
GCPercent int `config:"gc_percent"`

Seccomp *common.Config `config:"seccomp"`

// beat internal components configurations
HTTP *common.Config `config:"http"`
Expand Down Expand Up @@ -680,8 +683,13 @@ func (b *Beat) configure(settings Settings) error {
}

if maxProcs := b.Config.MaxProcs; maxProcs > 0 {
logp.Info("Set max procs limit: %v", maxProcs)
runtime.GOMAXPROCS(maxProcs)
}
if gcPercent := b.Config.GCPercent; gcPercent > 0 {
logp.Info("Set gc percentage to: %v", gcPercent)
debug.SetGCPercent(gcPercent)
}

b.Beat.BeatConfig, err = b.BeatConfig()
if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions x-pack/elastic-agent/pkg/agent/cmd/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,11 +625,18 @@ func runLegacyAPMServer(streams *cli.IOStreams, path string) (*process.Info, err
args = append(args, arg, v)
}
}
addSettingEnv := func(arg, env string) {
if v := os.Getenv(env); v != "" {
args = append(args, "-E", fmt.Sprintf("%v=%v", arg, v))
}
}

addEnv("--path.home", "HOME_PATH")
addEnv("--path.config", "CONFIG_PATH")
addEnv("--path.data", "DATA_PATH")
addEnv("--path.logs", "LOGS_PATH")
addEnv("--httpprof", "HTTPPROF")
addSettingEnv("gc_percent", "APMSERVER_GOGC")
logInfo(streams, "Starting legacy apm-server daemon as a subprocess.")
return process.Start(log, apmBinary, nil, os.Geteuid(), os.Getegid(), args)
}
Expand Down
2 changes: 1 addition & 1 deletion x-pack/elastic-agent/pkg/agent/program/supported.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion x-pack/elastic-agent/spec/apm-server.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
name: APM-Server
cmd: apm-server
artifact: apm-server
args: ["-E", "management.enabled=true", "-E", "management.mode=x-pack-fleet", "-E", "apm-server.data_streams.enabled=true"]
args: [
"-E", "management.enabled=true",
"-E", "management.mode=x-pack-fleet",
"-E", "apm-server.data_streams.enabled=true",
"-E", "gc_percent=${APMSERVER_GOGC:100}"
]
rules:
- copy_to_list:
item: fleet
Expand Down
9 changes: 8 additions & 1 deletion x-pack/elastic-agent/spec/filebeat.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
name: Filebeat
cmd: filebeat
args: ["-E", "setup.ilm.enabled=false", "-E", "setup.template.enabled=false", "-E", "management.mode=x-pack-fleet", "-E", "management.enabled=true", "-E", "logging.level=debug"]
args: [
"-E", "setup.ilm.enabled=false",
"-E", "setup.template.enabled=false",
"-E", "management.mode=x-pack-fleet",
"-E", "management.enabled=true",
"-E", "logging.level=debug",
"-E", "gc_percent=${FILEBEAT_GOGC:100}"
]
artifact: beats/filebeat
restart_on_output_change: true
rules:
Expand Down
9 changes: 8 additions & 1 deletion x-pack/elastic-agent/spec/metricbeat.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
name: Metricbeat
cmd: metricbeat
args: ["-E", "setup.ilm.enabled=false", "-E", "setup.template.enabled=false", "-E", "management.mode=x-pack-fleet", "-E", "management.enabled=true", "-E", "logging.level=debug"]
args: [
"-E", "setup.ilm.enabled=false",
"-E", "setup.template.enabled=false",
"-E", "management.mode=x-pack-fleet",
"-E", "management.enabled=true",
"-E", "logging.level=debug",
"-E", "gc_percent=${METRICBEAT_GOGC:100}"
]
artifact: beats/metricbeat
restart_on_output_change: true
post_install:
Expand Down

0 comments on commit b4980c7

Please sign in to comment.