-
Notifications
You must be signed in to change notification settings - Fork 208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add memory limiter to gateway collector #1086
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
34440cf
feat: add memory request to gateway collector
blumamir 7a7956b
feat: add memory limiter processor
blumamir 3e818f6
feat: allow to configure memory limiter parameters
blumamir 24b3e93
Merge remote-tracking branch 'upstream/main' into memory-limiter
blumamir bccc49c
fix: add rbac permissions
blumamir b6d2c19
chore: align names
blumamir f855f13
chore: description changes
blumamir a089a35
Merge remote-tracking branch 'upstream/main' into memory-limiter
blumamir 70d9683
Merge branch 'main' into memory-limiter
blumamir File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package gateway | ||
|
||
import odigosv1 "github.com/keyval-dev/odigos/api/odigos/v1alpha1" | ||
|
||
const ( | ||
defaultRequestMemoryMiB = 500 | ||
|
||
// this configures the processor limit_mib, which is the hard limit in MiB, afterwhich garbage collection will be forced. | ||
// as recommended by the processor docs, if not set, this is set to 50MiB less than the memory limit of the collector | ||
defaultMemoryLimiterLimitDiffMib = 50 | ||
|
||
// the soft limit will be set to 80% of the hard limit. | ||
// this value is used to derive the "spike_limit_mib" parameter in the processor configuration if a value is not set | ||
defaultMemoryLimiterSpikePercentage = 20.0 | ||
|
||
// the percentage out of the memory limiter hard limit, at which go runtime will start garbage collection. | ||
// it is used to calculate the GOMEMLIMIT environment variable value. | ||
defaultGoMemLimitPercentage = 80.0 | ||
) | ||
|
||
type memoryConfigurations struct { | ||
memoryRequestMiB int | ||
memoryLimiterLimitMiB int | ||
memoryLimiterSpikeLimitMiB int | ||
gomemlimitMiB int | ||
} | ||
|
||
func getMemoryConfigurations(odigosConfig *odigosv1.OdigosConfiguration) *memoryConfigurations { | ||
|
||
memoryRequestMiB := defaultRequestMemoryMiB | ||
if odigosConfig.Spec.CollectorGateway != nil && odigosConfig.Spec.CollectorGateway.RequestMemoryMiB > 0 { | ||
memoryRequestMiB = odigosConfig.Spec.CollectorGateway.RequestMemoryMiB | ||
} | ||
|
||
// the memory limiter hard limit is set as 50 MiB less than the memory request | ||
memoryLimiterLimitMiB := memoryRequestMiB - defaultMemoryLimiterLimitDiffMib | ||
if odigosConfig.Spec.CollectorGateway != nil && odigosConfig.Spec.CollectorGateway.MemoryLimiterLimitMiB > 0 { | ||
memoryLimiterLimitMiB = odigosConfig.Spec.CollectorGateway.MemoryLimiterLimitMiB | ||
} | ||
|
||
memoryLimiterSpikeLimitMiB := memoryLimiterLimitMiB * defaultMemoryLimiterSpikePercentage / 100.0 | ||
if odigosConfig.Spec.CollectorGateway != nil && odigosConfig.Spec.CollectorGateway.MemoryLimiterSpikeLimitMiB > 0 { | ||
memoryLimiterSpikeLimitMiB = odigosConfig.Spec.CollectorGateway.MemoryLimiterSpikeLimitMiB | ||
} | ||
|
||
gomemlimitMiB := int(memoryLimiterLimitMiB * defaultGoMemLimitPercentage / 100.0) | ||
if odigosConfig.Spec.CollectorGateway != nil && odigosConfig.Spec.CollectorGateway.GoMemLimitMib != 0 { | ||
gomemlimitMiB = odigosConfig.Spec.CollectorGateway.GoMemLimitMib | ||
} | ||
|
||
return &memoryConfigurations{ | ||
memoryRequestMiB: memoryRequestMiB, | ||
memoryLimiterLimitMiB: memoryLimiterLimitMiB, | ||
memoryLimiterSpikeLimitMiB: memoryLimiterSpikeLimitMiB, | ||
gomemlimitMiB: gomemlimitMiB, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how often it might happen, but if our default is to request 500MB, and there is some resource limit preventing us from doing so, we should probably have some handling for it.