Documentation ¶
Index ¶
Constants ¶
View Source
const ( MemoryLimitEnvFieldName = "GOMEMLIMIT" ProcessLimitEnvFieldName = "GOMAXPROC" MemoryLimitHumanReadableFieldName = "quota.memory.limit" CpuSecondsLimitHumanReadableFieldName = "quota.cpu.limit" EnabledMemoryLimitFieldName = "quota.memory.enabled" EnabledCpuLimitFieldName = "quota.cpu.enabled" EnabledMemoryLimitDefault = false EnabledCpuLimitDefault = false )
Variables ¶
View Source
var ( MemoryLimitHumanReadableDefault = os.Getenv(MemoryLimitEnvFieldName) CpuSecondsLimitHumanReadable = os.Getenv(ProcessLimitEnvFieldName) )
View Source
var Component = &app.Component{ Dependencies: app.Components{ logger.Component, configurator.Component, re_configuration.Component, info.Component, }, Constructor: func(container container.Container) error { return container.Provides( NewConfig, NewReConfigurationWithConfigurator, func(reConfiguration *ReConfiguration) Quota { return reConfiguration }, ) }, BindFlags: func(flagSet *pflag.FlagSet, container container.Container) error { return container.Invoke(func(config *Config) { flagSet.StringVar(&config.MemoryLimitHumanReadable, MemoryLimitHumanReadableFieldName, MemoryLimitHumanReadableDefault, "memory limit") flagSet.StringVar(&config.CpuSecondsLimitHumanReadable, CpuSecondsLimitHumanReadableFieldName, CpuSecondsLimitHumanReadable, "cpu limit") flagSet.BoolVar(&config.MemoryLimitEnabled, EnabledMemoryLimitFieldName, EnabledMemoryLimitDefault, "enabling memory quotas") flagSet.BoolVar(&config.CpuLimitEnabled, EnabledCpuLimitFieldName, EnabledCpuLimitDefault, "enabling cpu quotas") }) }, Run: func(c container.Container) error { logger, err := container.Get[logger.Logger](c) if err != nil { return err } quota, err := container.Get[*ReConfiguration](c) if err != nil { logger.Error(err) return err } reConfiguration, err := container.Get[configurator.ReConfiguration](c) if err != nil { return err } reConfiguration.Registration(quota) logger.Info("quota: registration in the reConfigurator") if quota.Memory() > 0 { logger.Infof("quota: set memory limit %s", size.FormatBinary(quota.Memory())) debug.SetMemoryLimit(int64(quota.Memory())) } else { logger.Info("quota: memory quota tracking, at runtime, disabled") } if quota.Processes() > 0 { logger.Infof("quota: set the total number of processes %d", quota.Processes()) runtime.GOMAXPROCS(int(quota.Processes())) } else { logger.Info("quota: cpu quota tracking, at runtime, disabled") } info, err := container.Get[info.Info](c) if err != nil { return err } config, err := container.Get[*Config](c) if err != nil { return err } info.Registration("quota", config) return nil }, }
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { MemoryLimitEnabled bool MemoryLimitHumanReadable string MemoryLimit uint64 CpuLimitEnabled bool CpuSecondsLimitHumanReadable string CpuSecondsLimit uint32 }
func Configuration ¶
func Configuration(config *Config, configurator configurator.Configurator, appConfig *app.Config, getQuotas GetQuotas) (*Config, error)
type Quota ¶
func NewWithConfigurator ¶
func NewWithConfigurator(config *Config, configurator configurator.Configurator, appConfig *app.Config) (Quota, error)
type ReConfiguration ¶
type ReConfiguration struct {
// contains filtered or unexported fields
}
func NewReConfiguration ¶
func NewReConfigurationWithConfigurator ¶
func NewReConfigurationWithConfigurator(config *Config, configurator configurator.Configurator, appConfig *app.Config, informer logger.Informer) (*ReConfiguration, error)
func (*ReConfiguration) Memory ¶
func (reConfiguration *ReConfiguration) Memory() uint64
func (*ReConfiguration) Processes ¶
func (reConfiguration *ReConfiguration) Processes() uint8
func (*ReConfiguration) Quota ¶
func (reConfiguration *ReConfiguration) Quota() Quota
func (*ReConfiguration) ReConfiguration ¶
func (reConfiguration *ReConfiguration) ReConfiguration(configurator configurator.Configurator) error
Source Files ¶
Click to show internal directories.
Click to hide internal directories.