@@ -936,7 +936,7 @@ func (a *agent) run() (retErr error) {
936936 connMan .startAgentAPI ("send logs" , gracefulShutdownBehaviorRemain ,
937937 func (ctx context.Context , aAPI proto.DRPCAgentClient24 ) error {
938938 err := a .logSender .SendLoop (ctx , aAPI )
939- if xerrors .Is (err , agentsdk .LogLimitExceededError ) {
939+ if xerrors .Is (err , agentsdk .ErrLogLimitExceeded ) {
940940 // we don't want this error to tear down the API connection and propagate to the
941941 // other routines that use the API. The LogSender has already dropped a warning
942942 // log, so just return nil here.
@@ -1564,9 +1564,13 @@ func (a *agent) Collect(ctx context.Context, networkStats map[netlogtype.Connect
15641564 }
15651565 for conn , counts := range networkStats {
15661566 stats .ConnectionsByProto [conn .Proto .String ()]++
1567+ // #nosec G115 - Safe conversions for network statistics which we expect to be within int64 range
15671568 stats .RxBytes += int64 (counts .RxBytes )
1569+ // #nosec G115 - Safe conversions for network statistics which we expect to be within int64 range
15681570 stats .RxPackets += int64 (counts .RxPackets )
1571+ // #nosec G115 - Safe conversions for network statistics which we expect to be within int64 range
15691572 stats .TxBytes += int64 (counts .TxBytes )
1573+ // #nosec G115 - Safe conversions for network statistics which we expect to be within int64 range
15701574 stats .TxPackets += int64 (counts .TxPackets )
15711575 }
15721576
@@ -1619,11 +1623,12 @@ func (a *agent) Collect(ctx context.Context, networkStats map[netlogtype.Connect
16191623 wg .Wait ()
16201624 sort .Float64s (durations )
16211625 durationsLength := len (durations )
1622- if durationsLength == 0 {
1626+ switch {
1627+ case durationsLength == 0 :
16231628 stats .ConnectionMedianLatencyMs = - 1
1624- } else if durationsLength % 2 == 0 {
1629+ case durationsLength % 2 == 0 :
16251630 stats .ConnectionMedianLatencyMs = (durations [durationsLength / 2 - 1 ] + durations [durationsLength / 2 ]) / 2
1626- } else {
1631+ default :
16271632 stats .ConnectionMedianLatencyMs = durations [durationsLength / 2 ]
16281633 }
16291634 // Convert from microseconds to milliseconds.
@@ -1730,7 +1735,7 @@ func (a *agent) HTTPDebug() http.Handler {
17301735 r .Get ("/debug/magicsock" , a .HandleHTTPDebugMagicsock )
17311736 r .Get ("/debug/magicsock/debug-logging/{state}" , a .HandleHTTPMagicsockDebugLoggingState )
17321737 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 ) {
17341739 w .WriteHeader (http .StatusNotFound )
17351740 _ , _ = w .Write ([]byte ("404 not found" ))
17361741 })
@@ -2016,7 +2021,7 @@ func (a *apiConnRoutineManager) wait() error {
20162021}
20172022
20182023func 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 ) {
20202025 w .Header ().Set ("Content-Type" , "text/plain" )
20212026
20222027 // 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) {
20522057 return 42 , err
20532058 }
20542059
2060+ // #nosec G115 - Safe conversion to generate int64 hash from Sum64, data loss acceptable
20552061 return int64 (h .Sum64 ()), nil
20562062}
0 commit comments