Skip to content

Commit

Permalink
cast uuid to agent's int64 id
Browse files Browse the repository at this point in the history
  • Loading branch information
floreks committed Oct 24, 2023
1 parent 21e9623 commit 7ba3444
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ require (
github.com/go-logr/zapr v1.2.4
github.com/golang-jwt/jwt/v5 v5.0.0
github.com/google/go-cmp v0.6.0
github.com/google/uuid v1.3.1
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.0
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.0.1
github.com/pluralsh/console-client-go v0.0.21
github.com/prometheus/client_golang v1.17.0
github.com/redis/rueidis v1.0.20
github.com/satori/go.uuid v1.2.0
github.com/spf13/cobra v1.7.0
github.com/stretchr/testify v1.8.4
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.45.0
Expand Down Expand Up @@ -139,6 +139,7 @@ require (
github.com/google/gnostic-models v0.6.9-0.20230804172637-c7be7c783f49 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/gordonklaus/ineffassign v0.0.0-20230610083614-0e73809eb601 // indirect
github.com/gostaticanalysis/analysisutil v0.7.1 // indirect
github.com/gostaticanalysis/comment v1.4.2 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,8 @@ github.com/sashamelentyev/interfacebloat v1.1.0 h1:xdRdJp0irL086OyW1H/RTZTr1h/tM
github.com/sashamelentyev/interfacebloat v1.1.0/go.mod h1:+Y9yU5YdTkrNvoX0xHc84dxiN1iBi9+G8zZIhPVoNjQ=
github.com/sashamelentyev/usestdlibvars v1.24.0 h1:MKNzmXtGh5N0y74Z/CIaJh4GlB364l0K1RUT08WSWAc=
github.com/sashamelentyev/usestdlibvars v1.24.0/go.mod h1:9cYkq+gYJ+a5W2RPdhfaSCnTVUC1OQP/bSiiBhq3OZE=
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/schollz/progressbar/v3 v3.13.1 h1:o8rySDYiQ59Mwzy2FELeHY5ZARXZTVJC7iHD6PEFUiE=
github.com/schollz/progressbar/v3 v3.13.1/go.mod h1:xvrbki8kfT1fzWzBT/UZd9L6GA+jdL7HAgq2RFnO6fQ=
github.com/securego/gosec/v2 v2.18.1 h1:xnnehWg7dIW8qrRPGm8ykY21zp2MueKyC99Vlcuj96I=
Expand Down
8 changes: 4 additions & 4 deletions pkg/module/agent_tracker/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ type RedisTracker struct {
gcPeriod time.Duration

// mu protects fields below
mu sync.Mutex
connectionsByAgentId redistool.ExpiringHash[int64, int64] // agentId -> connectionId -> info
connectedAgents redistool.ExpiringHash[int64, int64] // hash name -> agentId -> ""
mu sync.Mutex
connectionsByAgentId redistool.ExpiringHash[int64, int64] // agentId -> connectionId -> info
connectedAgents redistool.ExpiringHash[int64, int64] // hash name -> agentId -> ""
}

func NewRedisTracker(log *zap.Logger, errRep errz.ErrReporter, client rueidis.Client, agentKeyPrefix string, ttl, refreshPeriod, gcPeriod time.Duration) *RedisTracker {
Expand All @@ -62,7 +62,7 @@ func NewRedisTracker(log *zap.Logger, errRep errz.ErrReporter, client rueidis.Cl
refreshPeriod: refreshPeriod,
gcPeriod: gcPeriod,
connectionsByAgentId: redistool.NewRedisExpiringHash(client, connectionsByAgentIdHashKey(agentKeyPrefix), int64ToStr, ttl),
connectedAgents: redistool.NewRedisExpiringHash(client, connectedAgentsHashKey(agentKeyPrefix), int64ToStr, ttl),
connectedAgents: redistool.NewRedisExpiringHash(client, connectedAgentsHashKey(agentKeyPrefix), int64ToStr, ttl),
}
}

Expand Down
17 changes: 16 additions & 1 deletion pkg/plural/get_agent_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package plural

import (
"context"
"encoding/binary"

uuid "github.com/satori/go.uuid"

"github.com/pluralsh/kuberentes-agent/pkg/api"
)
Expand All @@ -13,9 +16,21 @@ func GetAgentInfo(ctx context.Context, agentToken api.AgentToken, pluralURL stri
return nil, err
}

u, err := uuidToInt64(cluster.MyCluster.ID)
if err != nil {
return nil, err
}

return &api.AgentInfo{
Id: 123456,
Id: u,
ClusterId: cluster.MyCluster.ID,
Name: cluster.MyCluster.Name,
}, nil
}

func uuidToInt64(id string) (int64, error) {
u, err := uuid.FromString(id)
// TODO: Figure out if we can do it better.
// uint can end up overflowing int and end up with a negative value
return int64(binary.BigEndian.Uint64(u[:8])), err
}

0 comments on commit 7ba3444

Please sign in to comment.