Adds udp6 support for ingest servers (#1134)

with flag -enableUDP6  https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1131
This commit is contained in:
Nikolay 2021-03-17 01:03:06 +03:00 committed by GitHub
parent 0ce557951f
commit 18cfc4be7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 3 deletions

View File

@ -44,7 +44,7 @@ func MustStart(addr string, insertHandler func(r io.Reader) error) *Server {
} }
logger.Infof("starting UDP Graphite server at %q", addr) logger.Infof("starting UDP Graphite server at %q", addr)
lnUDP, err := net.ListenPacket("udp4", addr) lnUDP, err := net.ListenPacket(netutil.GetUDPNetwork(), addr)
if err != nil { if err != nil {
logger.Fatalf("cannot start UDP Graphite server at %q: %s", addr, err) logger.Fatalf("cannot start UDP Graphite server at %q: %s", addr, err)
} }

View File

@ -44,7 +44,7 @@ func MustStart(addr string, insertHandler func(r io.Reader) error) *Server {
} }
logger.Infof("starting UDP Influx server at %q", addr) logger.Infof("starting UDP Influx server at %q", addr)
lnUDP, err := net.ListenPacket("udp4", addr) lnUDP, err := net.ListenPacket(netutil.GetUDPNetwork(), addr)
if err != nil { if err != nil {
logger.Fatalf("cannot start UDP Influx server at %q: %s", addr, err) logger.Fatalf("cannot start UDP Influx server at %q: %s", addr, err)
} }

View File

@ -51,7 +51,7 @@ func MustStart(addr string, telnetInsertHandler func(r io.Reader) error, httpIns
httpServer := opentsdbhttp.MustServe(lnHTTP, httpInsertHandler) httpServer := opentsdbhttp.MustServe(lnHTTP, httpInsertHandler)
logger.Infof("starting UDP OpenTSDB collector at %q", addr) logger.Infof("starting UDP OpenTSDB collector at %q", addr)
lnUDP, err := net.ListenPacket("udp4", addr) lnUDP, err := net.ListenPacket(netutil.GetUDPNetwork(), addr)
if err != nil { if err != nil {
logger.Fatalf("cannot start UDP OpenTSDB collector at %q: %s", addr, err) logger.Fatalf("cannot start UDP OpenTSDB collector at %q: %s", addr, err)
} }

14
lib/netutil/udp.go Normal file
View File

@ -0,0 +1,14 @@
package netutil
import "flag"
var enableUDP6 = flag.Bool("enableUDP6", false, "Whether to enable IPv6 for listening. By default only IPv4 UDP is used")
// GetUDPNetwork returns current udp network.
func GetUDPNetwork() string {
if *enableUDP6 {
// Enable both udp4 and udp6
return "udp"
}
return "udp4"
}