diff --git a/server/go.mod b/server/go.mod index 61716d0a..31fe61dd 100644 --- a/server/go.mod +++ b/server/go.mod @@ -5,6 +5,7 @@ go 1.21 require ( github.com/gocql/gocql v1.3.1 github.com/google/uuid v1.3.0 + github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.0.1 github.com/intelops/go-common v1.0.20 github.com/kelseyhightower/envconfig v1.4.0 github.com/kube-tarian/kad/agent v0.0.0-20221228201013-ed4f78e4b887 diff --git a/server/go.sum b/server/go.sum index c0a709fe..a6f36e93 100644 --- a/server/go.sum +++ b/server/go.sum @@ -83,6 +83,8 @@ github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeN github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.0.1 h1:HcUWd006luQPljE73d5sk+/VgYPGUReEVz2y1/qylwY= +github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.0.1/go.mod h1:w9Y7gY31krpLmrVU5ZPG9H7l9fZuRu5/3R3S3FMtVQ4= github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed h1:5upAirOpQc1Q53c0bnx2ufif5kANL7bfZWcc6VJWJd8= github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed/go.mod h1:tMWxXQ9wFIaZeTI9F+hmhFiGpFmhOHzyShyFUhRm0H4= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= @@ -195,8 +197,8 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= -github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/testcontainers/testcontainers-go v0.11.1 h1:FiYsB83LSGbiawoV8TpAZGfcCUbtaeeg1SXqEKUxh08= github.com/testcontainers/testcontainers-go v0.11.1/go.mod h1:/V0UVq+1e7NWYoqTPog179clf0Qp9TOyp4EcXaEFQz8= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= diff --git a/server/pkg/agent/agent_handler.go b/server/pkg/agent/agent_handler.go index b660f72e..610f5596 100644 --- a/server/pkg/agent/agent_handler.go +++ b/server/pkg/agent/agent_handler.go @@ -55,10 +55,10 @@ func (s *AgentHandler) UpdateAgent(clusterID string, agentCfg *Config) error { } func (s *AgentHandler) GetAgent(orgId, clusterID string) (*Agent, error) { - /*agent := s.getAgent(clusterID) + agent := s.getAgent(clusterID) if agent != nil { return agent, nil - }*/ + } cfg, err := s.getAgentConfig(orgId, clusterID) if err != nil { @@ -69,7 +69,7 @@ func (s *AgentHandler) GetAgent(orgId, clusterID string) (*Agent, error) { return nil, err } - agent := s.getAgent(clusterID) + agent = s.getAgent(clusterID) if agent != nil { return agent, nil } diff --git a/server/pkg/agent/client.go b/server/pkg/agent/client.go index 826b5568..572369ed 100644 --- a/server/pkg/agent/client.go +++ b/server/pkg/agent/client.go @@ -7,12 +7,14 @@ import ( "fmt" "net/url" "strings" + "time" "github.com/kube-tarian/kad/agent/pkg/logging" "github.com/kube-tarian/kad/server/pkg/pb/agentpb" "github.com/kube-tarian/kad/server/pkg/pb/captenpluginspb" "github.com/pkg/errors" + "github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/timeout" oryclient "github.com/kube-tarian/kad/server/pkg/ory-client" "google.golang.org/grpc" "google.golang.org/grpc/credentials" @@ -74,7 +76,9 @@ func getConnection(cfg *Config, oryClient oryclient.OryClient) (*grpc.ClientConn return nil, err } - dialOptions := []grpc.DialOption{} + dialOptions := []grpc.DialOption{ + grpc.WithUnaryInterceptor(timeout.UnaryClientInterceptor(5 * time.Second)), + } if cfg.AuthEnabled { dialOptions = append(dialOptions, grpc.WithUnaryInterceptor(authInterceptor(oryClient, cfg.ServicName))) @@ -90,7 +94,7 @@ func getConnection(cfg *Config, oryClient oryclient.OryClient) (*grpc.ClientConn dialOptions = append(dialOptions, grpc.WithTransportCredentials(tlsCreds)) } - return grpc.Dial(fmt.Sprintf("%s:%s", address, port), dialOptions...) + return grpc.DialContext(context.Background(), fmt.Sprintf("%s:%s", address, port), dialOptions...) } func (a *Agent) GetClient() agentpb.AgentClient {