@@ -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.
@@ -1564,9 +1564,13 @@ func (a *agent) Collect(ctx context.Context, networkStats map[netlogtype.Connect
1564
1564
}
1565
1565
for conn , counts := range networkStats {
1566
1566
stats .ConnectionsByProto [conn .Proto .String ()]++
1567
+ // #nosec G115 - Safe conversions for network statistics which we expect to be within int64 range
1567
1568
stats .RxBytes += int64 (counts .RxBytes )
1569
+ // #nosec G115 - Safe conversions for network statistics which we expect to be within int64 range
1568
1570
stats .RxPackets += int64 (counts .RxPackets )
1571
+ // #nosec G115 - Safe conversions for network statistics which we expect to be within int64 range
1569
1572
stats .TxBytes += int64 (counts .TxBytes )
1573
+ // #nosec G115 - Safe conversions for network statistics which we expect to be within int64 range
1570
1574
stats .TxPackets += int64 (counts .TxPackets )
1571
1575
}
1572
1576
@@ -1619,11 +1623,12 @@ func (a *agent) Collect(ctx context.Context, networkStats map[netlogtype.Connect
1619
1623
wg .Wait ()
1620
1624
sort .Float64s (durations )
1621
1625
durationsLength := len (durations )
1622
- if durationsLength == 0 {
1626
+ switch {
1627
+ case durationsLength == 0 :
1623
1628
stats .ConnectionMedianLatencyMs = - 1
1624
- } else if durationsLength % 2 == 0 {
1629
+ case durationsLength % 2 == 0 :
1625
1630
stats .ConnectionMedianLatencyMs = (durations [durationsLength / 2 - 1 ] + durations [durationsLength / 2 ]) / 2
1626
- } else {
1631
+ default :
1627
1632
stats .ConnectionMedianLatencyMs = durations [durationsLength / 2 ]
1628
1633
}
1629
1634
// Convert from microseconds to milliseconds.
@@ -1730,7 +1735,7 @@ func (a *agent) HTTPDebug() http.Handler {
1730
1735
r .Get ("/debug/magicsock" , a .HandleHTTPDebugMagicsock )
1731
1736
r .Get ("/debug/magicsock/debug-logging/{state}" , a .HandleHTTPMagicsockDebugLoggingState )
1732
1737
r .Get ("/debug/manifest" , a .HandleHTTPDebugManifest )
1733
- r .NotFound (func (w http.ResponseWriter , r * http.Request ) {
1738
+ r .NotFound (func (w http.ResponseWriter , _ * http.Request ) {
1734
1739
w .WriteHeader (http .StatusNotFound )
1735
1740
_ , _ = w .Write ([]byte ("404 not found" ))
1736
1741
})
@@ -2016,7 +2021,7 @@ func (a *apiConnRoutineManager) wait() error {
2016
2021
}
2017
2022
2018
2023
func PrometheusMetricsHandler (prometheusRegistry * prometheus.Registry , logger slog.Logger ) http.Handler {
2019
- return http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
2024
+ return http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
2020
2025
w .Header ().Set ("Content-Type" , "text/plain" )
2021
2026
2022
2027
// Based on: https://github.com/tailscale/tailscale/blob/280255acae604796a1113861f5a84e6fa2dc6121/ipn/localapi/localapi.go#L489
@@ -2052,5 +2057,6 @@ func WorkspaceKeySeed(workspaceID uuid.UUID, agentName string) (int64, error) {
2052
2057
return 42 , err
2053
2058
}
2054
2059
2060
+ // #nosec G115 - Safe conversion to generate int64 hash from Sum64, data loss acceptable
2055
2061
return int64 (h .Sum64 ()), nil
2056
2062
}
0 commit comments