Check UDP-buffer-size

Raise alert if UDP-buffer size is not high enough
This commit is contained in:
Phi 2023-10-30 09:36:15 +00:00
parent 87801b5855
commit a6ae497c02
2 changed files with 59 additions and 0 deletions

View File

@ -90,6 +90,7 @@ const (
// health checks // health checks
CheckFDLimit CheckFDLimit
CheckFvmConcurrency CheckFvmConcurrency
CheckUDPBufferSize
LegacyMarketsEOL LegacyMarketsEOL
// libp2p // libp2p
@ -169,6 +170,7 @@ func defaults() []Option {
Override(CheckFDLimit, modules.CheckFdLimit(build.DefaultFDLimit)), Override(CheckFDLimit, modules.CheckFdLimit(build.DefaultFDLimit)),
Override(CheckFvmConcurrency, modules.CheckFvmConcurrency()), Override(CheckFvmConcurrency, modules.CheckFvmConcurrency()),
Override(CheckUDPBufferSize, modules.CheckUDPBufferSize(2048*1024)),
Override(new(system.MemoryConstraints), modules.MemoryConstraints), Override(new(system.MemoryConstraints), modules.MemoryConstraints),
Override(InitMemoryWatchdog, modules.MemoryWatchdog), Override(InitMemoryWatchdog, modules.MemoryWatchdog),

View File

@ -1,8 +1,10 @@
package modules package modules
import ( import (
"net"
"os" "os"
"strconv" "strconv"
"syscall"
"github.com/filecoin-project/lotus/journal/alerting" "github.com/filecoin-project/lotus/journal/alerting"
"github.com/filecoin-project/lotus/lib/ulimit" "github.com/filecoin-project/lotus/lib/ulimit"
@ -35,6 +37,61 @@ func CheckFdLimit(min uint64) func(al *alerting.Alerting) {
} }
} }
func CheckUDPBufferSize(wanted int) func(al *alerting.Alerting) {
return func(al *alerting.Alerting) {
conn, err := net.Dial("udp", "localhost:0")
if err != nil {
alert := al.AddAlertType("process", "udp-buffer-size")
al.Raise(alert, map[string]string{
"message": "Failed to create UDP connection",
"error": err.Error(),
})
return
}
defer conn.Close()
udpConn, ok := conn.(*net.UDPConn)
if !ok {
alert := al.AddAlertType("process", "udp-buffer-size")
al.Raise(alert, map[string]string{
"message": "Failed to cast connection to UDPConn",
})
return
}
file, err := udpConn.File()
if err != nil {
alert := al.AddAlertType("process", "udp-buffer-size")
al.Raise(alert, map[string]string{
"message": "Failed to get file descriptor from UDPConn",
"error": err.Error(),
})
return
}
defer file.Close()
size, err := syscall.GetsockoptInt(int(file.Fd()), syscall.SOL_SOCKET, syscall.SO_RCVBUF)
if err != nil {
alert := al.AddAlertType("process", "udp-buffer-size")
al.Raise(alert, map[string]string{
"message": "Failed to get UDP buffer size",
"error": err.Error(),
})
return
}
if size < wanted {
alert := al.AddAlertType("process", "udp-buffer-size")
al.Raise(alert, map[string]interface{}{
"message": "UDP buffer size is low",
"current_size": size,
"wanted_size": wanted,
"help": "See https://github.com/quic-go/quic-go/wiki/UDP-Buffer-Sizes for details.",
})
}
}
}
func LegacyMarketsEOL(al *alerting.Alerting) { func LegacyMarketsEOL(al *alerting.Alerting) {
// Add alert if lotus-miner legacy markets subsystem is still in use // Add alert if lotus-miner legacy markets subsystem is still in use
alert := al.AddAlertType("system", "EOL") alert := al.AddAlertType("system", "EOL")