cmd/stunstamp: cleanup timeout and interval constants (#13393)

Updates #cleanup

Signed-off-by: Jordan Whited <jordan@tailscale.com>
pull/13402/head
Jordan Whited 3 months ago committed by GitHub
parent e7b5e8c8cd
commit 95f0094310
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -53,7 +53,16 @@ var (
) )
const ( const (
minInterval = time.Second // maxTxJitter is the upper bounds for jitter introduced across probes
maxTXJitter = time.Millisecond * 400
// minInterval is the minimum allowed probe interval/step
minInterval = time.Second * 10
// txRxTimeout is the timeout value used for kernel timestamping loopback,
// and packet receive operations
txRxTimeout = time.Second * 2
// maxBufferDuration is the maximum duration (maxBufferDuration /
// *flagInterval steps worth) of buffered data that can be held in memory
// before data loss occurs around prometheus unavailability.
maxBufferDuration = time.Hour maxBufferDuration = time.Hour
) )
@ -322,7 +331,7 @@ func measureSTUNRTT(conn io.ReadWriteCloser, _ string, dst netip.AddrPort) (rtt
if !ok { if !ok {
return 0, fmt.Errorf("unexpected conn type: %T", conn) return 0, fmt.Errorf("unexpected conn type: %T", conn)
} }
err = uconn.SetReadDeadline(time.Now().Add(time.Second * 2)) err = uconn.SetReadDeadline(time.Now().Add(txRxTimeout))
if err != nil { if err != nil {
return 0, fmt.Errorf("error setting read deadline: %w", err) return 0, fmt.Errorf("error setting read deadline: %w", err)
} }
@ -380,7 +389,7 @@ func probe(meta nodeMeta, cf *connAndMeasureFn, dstPort int) (*time.Duration, er
Port: dstPort, Port: dstPort,
} }
time.Sleep(rand.N(400 * time.Millisecond)) // jitter across tx time.Sleep(rand.N(maxTXJitter)) // jitter across tx
rtt, err := cf.fn(cf.conn, meta.hostname, netip.AddrPortFrom(meta.addr, uint16(dstPort))) rtt, err := cf.fn(cf.conn, meta.hostname, netip.AddrPortFrom(meta.addr, uint16(dstPort)))
if err != nil { if err != nil {
if isTemporaryOrTimeoutErr(err) { if isTemporaryOrTimeoutErr(err) {

@ -107,7 +107,7 @@ func measureICMPRTT(source timestampSource, conn io.ReadWriteCloser, _ string, d
} }
if source == timestampSourceKernel { if source == timestampSourceKernel {
txCtx, txCancel := context.WithTimeout(context.Background(), time.Second*2) txCtx, txCancel := context.WithTimeout(context.Background(), txRxTimeout)
defer txCancel() defer txCancel()
buf := make([]byte, 1024) buf := make([]byte, 1024)
@ -142,8 +142,8 @@ func measureICMPRTT(source timestampSource, conn io.ReadWriteCloser, _ string, d
} }
} }
rxCtx, txCancel := context.WithTimeout(context.Background(), time.Second*2) rxCtx, rxCancel := context.WithTimeout(context.Background(), txRxTimeout)
defer txCancel() defer rxCancel()
rxBuf := make([]byte, 1024) rxBuf := make([]byte, 1024)
oob := make([]byte, 1024) oob := make([]byte, 1024)
@ -210,7 +210,7 @@ func measureSTUNRTTKernel(conn io.ReadWriteCloser, _ string, dst netip.AddrPort)
return 0, fmt.Errorf("sendto error: %v", err) // don't wrap return 0, fmt.Errorf("sendto error: %v", err) // don't wrap
} }
txCtx, txCancel := context.WithTimeout(context.Background(), time.Second*2) txCtx, txCancel := context.WithTimeout(context.Background(), txRxTimeout)
defer txCancel() defer txCancel()
buf := make([]byte, 1024) buf := make([]byte, 1024)
@ -236,7 +236,7 @@ func measureSTUNRTTKernel(conn io.ReadWriteCloser, _ string, dst netip.AddrPort)
break break
} }
rxCtx, rxCancel := context.WithTimeout(context.Background(), time.Second*2) rxCtx, rxCancel := context.WithTimeout(context.Background(), txRxTimeout)
defer rxCancel() defer rxCancel()
for { for {

Loading…
Cancel
Save