Skip to content

Commit

Permalink
NETOBSERV-1107: Add GoMemLimit env setting to prevent ebpf agent OOM (#…
Browse files Browse the repository at this point in the history
…382)

Signed-off-by: msherif1234 <mmahmoud@redhat.com>
  • Loading branch information
msherif1234 committed Jul 13, 2023
1 parent 651249e commit a4a3c26
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions controllers/ebpf/agent_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const (
dedupeDefault = "firstCome"
envDedupeJustMark = "DEDUPER_JUST_MARK"
dedupeJustMarkDefault = "true"
envGoMemLimit = "GOMEMLIMIT"

envListSeparator = ","
)
Expand Down Expand Up @@ -245,6 +246,18 @@ func (c *AgentController) envConfig(ctx context.Context, coll *flowslatest.FlowC
Value: strconv.Itoa(int(*sampling)),
})
}

// set GOMEMLIMIT which allows specifying a soft memory cap to force GC when resource limit is reached
// to prevent OOM
if coll.Spec.Agent.EBPF.Resources.Limits.Memory() != nil {
if memLimit, ok := coll.Spec.Agent.EBPF.Resources.Limits.Memory().AsInt64(); ok {
// we will set the GOMEMLIMIT to current memlimit - 10% as a headroom to account for
// memory sources the Go runtime is unaware of
memLimit -= int64(float64(memLimit) * 0.1)
config = append(config, corev1.EnvVar{Name: envGoMemLimit, Value: fmt.Sprint(memLimit)})
}
}

dedup := dedupeDefault
dedupJustMark := dedupeJustMarkDefault
// we need to sort env map to keep idempotency,
Expand Down

0 comments on commit a4a3c26

Please sign in to comment.