mirror of
https://github.com/kubeshark/kubeshark.git
synced 2026-04-06 10:47:49 +00:00
* Close the hanging TCP message channels after a dynamically aligned timeout (base `10000` milliseconds) * Bring back `source.Lazy` * Add a one more `sync.Map.Delete` call * Improve the formula by taking base Goroutine count into account * Reduce duplication * Include the dropped TCP streams count into the stats tracker and print a debug log whenever it happens * Add `superIdentifier` field to `tcpStream` to check if it has identified Also stop the other protocol dissectors if a TCP stream identified by a protocol. * Take one step forward in fixing the channel closing issue (WIP) Add `sync.Mutex` to `tcpReader` and make the loops reference based. * Fix the channel closing issue * Improve the accuracy of the formula, log better and multiply `baseStreamChannelTimeoutMs` by 100 * Remove `fmt.Printf` * Replace `runtime.Gosched()` with `time.Sleep(1 * time.Millisecond)` * Close the channels of other protocols in case of an identification * Simplify the logic * Replace the formula with hard timeout 5000 milliseconds and 4000 maximum number of Goroutines
76 lines
2.1 KiB
Go
76 lines
2.1 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"
|
|
MaxNumberOfGoroutinesEnvVarName = "MAX_NUMBER_OF_GOROUTINES"
|
|
MaxBufferedPagesTotalDefaultValue = 5000
|
|
MaxBufferedPagesPerConnectionDefaultValue = 5000
|
|
TcpStreamChannelTimeoutMsDefaultValue = 5000
|
|
MaxNumberOfGoroutinesDefaultValue = 4000
|
|
)
|
|
|
|
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 GetMaxNumberOfGoroutines() int {
|
|
valueFromEnv, err := strconv.Atoi(os.Getenv(MaxNumberOfGoroutinesEnvVarName))
|
|
if err != nil {
|
|
return MaxNumberOfGoroutinesDefaultValue
|
|
}
|
|
return valueFromEnv
|
|
}
|
|
|
|
func GetMemoryProfilingEnabled() bool {
|
|
return os.Getenv(MemoryProfilingEnabledEnvVarName) == "1"
|
|
}
|