@@ -936,7 +936,7 @@ func (a *agent) run() (retErr error) {
936
936
connMan .startAgentAPI ("send logs" , gracefulShutdownBehaviorRemain ,
937
937
func (ctx context.Context , aAPI proto.DRPCAgentClient24 ) error {
938
938
err := a .logSender .SendLoop (ctx , aAPI )
939
- if xerrors .Is (err , agentsdk .LogLimitExceededError ) {
939
+ if xerrors .Is (err , agentsdk .ErrLogLimitExceeded ) {
940
940
// we don't want this error to tear down the API connection and propagate to the
941
941
// other routines that use the API. The LogSender has already dropped a warning
942
942
// log, so just return nil here.
@@ -1583,9 +1583,13 @@ func (a *agent) Collect(ctx context.Context, networkStats map[netlogtype.Connect
1583
1583
}
1584
1584
for conn , counts := range networkStats {
1585
1585
stats .ConnectionsByProto [conn .Proto .String ()]++
1586
+ // #nosec G115 - Safe conversions for network statistics which we expect to be within int64 range
1586
1587
stats .RxBytes += int64 (counts .RxBytes )
1588
+ // #nosec G115 - Safe conversions for network statistics which we expect to be within int64 range
1587
1589
stats .RxPackets += int64 (counts .RxPackets )
1590
+ // #nosec G115 - Safe conversions for network statistics which we expect to be within int64 range
1588
1591
stats .TxBytes += int64 (counts .TxBytes )
1592
+ // #nosec G115 - Safe conversions for network statistics which we expect to be within int64 range
1589
1593
stats .TxPackets += int64 (counts .TxPackets )
1590
1594
}
1591
1595
@@ -1638,11 +1642,12 @@ func (a *agent) Collect(ctx context.Context, networkStats map[netlogtype.Connect
1638
1642
wg .Wait ()
1639
1643
sort .Float64s (durations )
1640
1644
durationsLength := len (durations )
1641
- if durationsLength == 0 {
1645
+ switch {
1646
+ case durationsLength == 0 :
1642
1647
stats .ConnectionMedianLatencyMs = - 1
1643
- } else if durationsLength % 2 == 0 {
1648
+ case durationsLength % 2 == 0 :
1644
1649
stats .ConnectionMedianLatencyMs = (durations [durationsLength / 2 - 1 ] + durations [durationsLength / 2 ]) / 2
1645
- } else {
1650
+ default :
1646
1651
stats .ConnectionMedianLatencyMs = durations [durationsLength / 2 ]
1647
1652
}
1648
1653
// Convert from microseconds to milliseconds.
@@ -1749,7 +1754,7 @@ func (a *agent) HTTPDebug() http.Handler {
1749
1754
r .Get ("/debug/magicsock" , a .HandleHTTPDebugMagicsock )
1750
1755
r .Get ("/debug/magicsock/debug-logging/{state}" , a .HandleHTTPMagicsockDebugLoggingState )
1751
1756
r .Get ("/debug/manifest" , a .HandleHTTPDebugManifest )
1752
- r .NotFound (func (w http.ResponseWriter , r * http.Request ) {
1757
+ r .NotFound (func (w http.ResponseWriter , _ * http.Request ) {
1753
1758
w .WriteHeader (http .StatusNotFound )
1754
1759
_ , _ = w .Write ([]byte ("404 not found" ))
1755
1760
})
@@ -2034,7 +2039,7 @@ func (a *apiConnRoutineManager) wait() error {
2034
2039
}
2035
2040
2036
2041
func PrometheusMetricsHandler (prometheusRegistry * prometheus.Registry , logger slog.Logger ) http.Handler {
2037
- return http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
2042
+ return http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
2038
2043
w .Header ().Set ("Content-Type" , "text/plain" )
2039
2044
2040
2045
// Based on: https://github.com/tailscale/tailscale/blob/280255acae604796a1113861f5a84e6fa2dc6121/ipn/localapi/localapi.go#L489
@@ -2070,5 +2075,6 @@ func WorkspaceKeySeed(workspaceID uuid.UUID, agentName string) (int64, error) {
2070
2075
return 42 , err
2071
2076
}
2072
2077
2078
+ // #nosec G115 - Safe conversion to generate int64 hash from Sum64, data loss acceptable
2073
2079
return int64 (h .Sum64 ()), nil
2074
2080
}
0 commit comments