mirror of
https://github.com/kubeshark/kubeshark.git
synced 2026-01-29 21:39:41 +00:00
* Fix the OOMKilled error by calling `debug.FreeOSMemory` periodically * Remove `MAX_NUMBER_OF_GOROUTINES` environment variable * Change the line * Increase the default value of `TCP_STREAM_CHANNEL_TIMEOUT_MS` to `10000`
66 lines
1.8 KiB
Go
66 lines
1.8 KiB
Go
package tap
|
|
|
|
import (
|
|
"os"
|
|
"strconv"
|
|
"time"
|
|
)
|
|
|
|
const (
|
|
MemoryProfilingEnabledEnvVarName = "MEMORY_PROFILING_ENABLED"
|
|
MemoryProfilingDumpPath = "MEMORY_PROFILING_DUMP_PATH"
|
|
MemoryProfilingTimeIntervalSeconds = "MEMORY_PROFILING_TIME_INTERVAL"
|
|
MaxBufferedPagesTotalEnvVarName = "MAX_BUFFERED_PAGES_TOTAL"
|
|
MaxBufferedPagesPerConnectionEnvVarName = "MAX_BUFFERED_PAGES_PER_CONNECTION"
|
|
TcpStreamChannelTimeoutMsEnvVarName = "TCP_STREAM_CHANNEL_TIMEOUT_MS"
|
|
MaxBufferedPagesTotalDefaultValue = 5000
|
|
MaxBufferedPagesPerConnectionDefaultValue = 5000
|
|
TcpStreamChannelTimeoutMsDefaultValue = 10000
|
|
)
|
|
|
|
type globalSettings struct {
|
|
filterAuthorities []string
|
|
}
|
|
|
|
var gSettings = &globalSettings{
|
|
filterAuthorities: []string{},
|
|
}
|
|
|
|
func SetFilterAuthorities(ipAddresses []string) {
|
|
gSettings.filterAuthorities = ipAddresses
|
|
}
|
|
|
|
func GetFilterIPs() []string {
|
|
addresses := make([]string, len(gSettings.filterAuthorities))
|
|
copy(addresses, gSettings.filterAuthorities)
|
|
return addresses
|
|
}
|
|
|
|
func GetMaxBufferedPagesTotal() int {
|
|
valueFromEnv, err := strconv.Atoi(os.Getenv(MaxBufferedPagesTotalEnvVarName))
|
|
if err != nil {
|
|
return MaxBufferedPagesTotalDefaultValue
|
|
}
|
|
return valueFromEnv
|
|
}
|
|
|
|
func GetMaxBufferedPagesPerConnection() int {
|
|
valueFromEnv, err := strconv.Atoi(os.Getenv(MaxBufferedPagesPerConnectionEnvVarName))
|
|
if err != nil {
|
|
return MaxBufferedPagesPerConnectionDefaultValue
|
|
}
|
|
return valueFromEnv
|
|
}
|
|
|
|
func GetTcpChannelTimeoutMs() time.Duration {
|
|
valueFromEnv, err := strconv.Atoi(os.Getenv(TcpStreamChannelTimeoutMsEnvVarName))
|
|
if err != nil {
|
|
return TcpStreamChannelTimeoutMsDefaultValue * time.Millisecond
|
|
}
|
|
return time.Duration(valueFromEnv) * time.Millisecond
|
|
}
|
|
|
|
func GetMemoryProfilingEnabled() bool {
|
|
return os.Getenv(MemoryProfilingEnabledEnvVarName) == "1"
|
|
}
|