Set firelens mem_buf_limit by default #4405
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
awsfirelens
logging driver uses a Fluentbit-based image. Fluentbit supportsmem_buf_limit
configuration parameter which controls the amount of buffer memory that can be used by a log input. This prevents excessive memory usage of the buffer which may lead to container and task OOM kill. (see https://docs.fluentbit.io/manual/administration/backpressure)mem_buf_limit
is not enabled by Fluentbit by default, making buffer unbounded. In this PR we let ECS Agent sets a defaultmem_buf_limit
when generating Fluentbit configuration.Implementation details
The value of the
mem_buf_limit
is determined as follows:memoryReservation
is specified,mem_buf_limit
=memoryReservation
/ 2. We resolvememoryReservation
from container host config property (a json blob).memory
is specified,mem_buf_limit
=memory
/ 2. We resolvememory
from container property directly.(
memoryReservation
andmemory
are optional parameters indicating container soft and hard memory limit respectively. The goal here is to scale themem_buf_limit
in accordance with the memory allocation for the firelens container. The scaling factor is derived from this recommendation)memoryReservation
normemory
is specified, we setmem_buf_limit
to a fixed amount of 25MB (rationale)Main changes are:
NewFirelensResource
method to take in a newcontainerMemoryLimit
argument, and updated caller to pass in this argument after resolving the value from containermemory
andmemoryReservation
container
helper methodGetMemoryReservationFromHostConfig
to retrieve containermemoryReservation
generateConfig
method to writeMem_Buf_Limit
config for the default input, after resolving the value fromresolveMemBufLimit
helper methodTesting
New tests cover the changes: yes
Description for the changelog
Set firelens mem_buf_limit by default
Additional Information
Does this PR include breaking model changes? If so, Have you added transformation functions?
N/A
Does this PR include the addition of new environment variables in the README?
N/A
Licensing
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.