Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix agent connection reuse issue #335

Merged
merged 1 commit into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions server/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
6 changes: 3 additions & 3 deletions server/pkg/agent/agent_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down
8 changes: 6 additions & 2 deletions server/pkg/agent/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)))
Expand All @@ -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 {
Expand Down
Loading