From 647fa843f6ade687a1899847417346a8ebaaebf9 Mon Sep 17 00:00:00 2001 From: Marcus Ramberg Date: Tue, 14 Oct 2025 13:00:19 +0200 Subject: [PATCH] Modernize a couple of loops, fix incorrect function docs (#5637) --- cmd/agent/core/agent.go | 4 ++-- pipeline/rpc/log_entry.go | 2 +- server/grpc/jwt_manager.go | 2 +- server/grpc/rpc.go | 5 ++--- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/cmd/agent/core/agent.go b/cmd/agent/core/agent.go index 1fafc13a16..b3ff2d43f0 100644 --- a/cmd/agent/core/agent.go +++ b/cmd/agent/core/agent.go @@ -283,8 +283,8 @@ func run(ctx context.Context, c *cli.Command, backends []types.Backend) error { } }) - for i := 0; i < maxWorkflows; i++ { - i := i + // https://go.dev/blog/go1.22 fixed scope for goroutines in loops + for i := range maxWorkflows { serviceWaitingGroup.Go(func() error { runner := agent.NewRunner(client, filter, hostname, counter, &backendEngine) log.Debug().Msgf("created new runner %d", i) diff --git a/pipeline/rpc/log_entry.go b/pipeline/rpc/log_entry.go index 23257faaca..e56d08cbb3 100644 --- a/pipeline/rpc/log_entry.go +++ b/pipeline/rpc/log_entry.go @@ -28,7 +28,7 @@ const ( LogEntryProgress ) -// Line is a line of console output. +// LogEntry is a line of console output. type LogEntry struct { StepUUID string `json:"step_uuid,omitempty"` Time int64 `json:"time,omitempty"` diff --git a/server/grpc/jwt_manager.go b/server/grpc/jwt_manager.go index a02014b8b1..8cf7cbc363 100644 --- a/server/grpc/jwt_manager.go +++ b/server/grpc/jwt_manager.go @@ -28,7 +28,7 @@ type JWTManager struct { tokenDuration time.Duration } -// UserClaims is a custom JWT claims that contains some user's information. +// AgentTokenClaims is a custom JWT claims that contains an agent's information. type AgentTokenClaims struct { jwt.RegisteredClaims AgentID int64 `json:"agent_id"` diff --git a/server/grpc/rpc.go b/server/grpc/rpc.go index c70e3edc2a..bef1b7fddc 100644 --- a/server/grpc/rpc.go +++ b/server/grpc/rpc.go @@ -21,6 +21,7 @@ import ( "encoding/json" "errors" "fmt" + "maps" "strconv" "time" @@ -73,9 +74,7 @@ func (s *RPC) Next(c context.Context, agentFilter rpc.Filter) (*rpc.Workflow, er } // enforce labels from server by overwriting agent labels - for k, v := range agentServerLabels { - agentFilter.Labels[k] = v - } + maps.Copy(agentFilter.Labels, agentServerLabels) log.Trace().Msgf("Agent %s[%d] tries to pull task with labels: %v", agent.Name, agent.ID, agentFilter.Labels)