Skip to content

Commit 5725897

Browse files
added memory limit config (#2514)
* added memory limit config * added changelog * updated changelog * removed changelog * Update changelog/fragments/1681906741-memory_limit.yaml Co-authored-by: Michel Laterman <82832767+michel-laterman@users.noreply.github.com> * added comment to MemoryLimit --------- Co-authored-by: Michel Laterman <82832767+michel-laterman@users.noreply.github.com>
1 parent c02548f commit 5725897

File tree

5 files changed

+48
-1
lines changed

5 files changed

+48
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Kind can be one of:
2+
# - breaking-change: a change to previously-documented behavior
3+
# - deprecation: functionality that is being removed in a later release
4+
# - bug-fix: fixes a problem in a previous version
5+
# - enhancement: extends functionality but does not break or fix existing behavior
6+
# - feature: new functionality
7+
# - known-issue: problems that we are aware of in a given version
8+
# - security: impacts on the security of a product or a user’s deployment.
9+
# - upgrade: important information for someone upgrading from a prior version
10+
# - other: does not fit into any of the other categories
11+
kind: enhancement
12+
13+
# Change summary; a 80ish characters long description of the change.
14+
summary: Added memory_limit to server.runtime config.
15+
16+
# Long description; in case the summary is not enough to describe the change
17+
# this field accommodate a description without length limits.
18+
# NOTE: This field will be rendered only for breaking-change and known-issue kinds at the moment.
19+
#description:
20+
21+
# Affected component; a word indicating the component this changeset affects.
22+
component:
23+
24+
# PR URL; optional; the PR number that added the changeset.
25+
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added.
26+
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number.
27+
# Please provide it if you are adding a fragment for a different PR.
28+
pr: 2514
29+
30+
# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of).
31+
# If not present is automatically filled by the tooling with the issue linked to the PR number.
32+
# issue: https://github.com/owner/repo/1234

dev-tools/cloud/docker/build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ REPO_ROOT=$(cd $(dirname $(readlink -f "$0"))/../../.. && pwd)
1111
USER_NAME=${USER}
1212
CI_ELASTIC_AGENT_DOCKER_IMAGE=docker.elastic.co/observability-ci/elastic-agent
1313

14-
DEFAULT_IMAGE_TAG=8.8.0-681a23b0-SNAPSHOT
14+
DEFAULT_IMAGE_TAG=8.8.0-94522507-SNAPSHOT
1515
BASE_IMAGE="${BASE_IMAGE:-docker.elastic.co/cloud-release/elastic-agent-cloud:$DEFAULT_IMAGE_TAG}"
1616
GOARCH="${GOARCH:-$(go env GOARCH)}"
1717

example/fleet-server-100.yml

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ inputs:
4343
flush_interval: 100ms # Flush ES bulk queues on this interval.
4444
runtime:
4545
gc_percent: 20 # Force the GC to execute more frequently: see https://golang.org/pkg/runtime/debug/#SetGCPercent
46+
memory_limit: 4000000000 # Set a soft memory limit to prevent OOM: see https://pkg.go.dev/runtime/debug#SetMemoryLimit
47+
4648

4749

4850
http:

internal/pkg/config/runtime.go

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ package config
66

77
type Runtime struct {
88
GCPercent int `config:"gc_percent"`
9+
// set to math.MaxInt64 by default, setting to too low might result in the GC running almost continuously
10+
// see https://pkg.go.dev/runtime/debug#SetMemoryLimit
11+
MemoryLimit int64 `config:"memory_limit"`
912
}
1013

1114
func (r Runtime) InitDefaults() {

internal/pkg/server/fleet.go

+10
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,16 @@ func initRuntime(cfg *config.Config) {
307307
Int("new", gcPercent).
308308
Msg("SetGCPercent")
309309
}
310+
memoryLimit := cfg.Inputs[0].Server.Runtime.MemoryLimit
311+
if memoryLimit != 0 {
312+
old := debug.SetMemoryLimit(memoryLimit)
313+
314+
log.Info().
315+
Int64("old", old).
316+
Int64("new", memoryLimit).
317+
Msg("SetMemoryLimit")
318+
}
319+
310320
}
311321

312322
func (f *Fleet) initBulker(ctx context.Context, tracer *apm.Tracer, cfg *config.Config) (*bulk.Bulker, error) {

0 commit comments

Comments
 (0)