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

Remove unused context from arguments to internal/example/server. #634

Merged
merged 1 commit into from
Jan 30, 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
2 changes: 1 addition & 1 deletion internal/example/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,5 @@ func main() {
ctx := context.Background()
cb := &test.Callbacks{Debug: l.Debug}
srv := server.NewServer(ctx, cache, cb)
example.RunServer(ctx, srv, port)
example.RunServer(srv, port)
}
56 changes: 55 additions & 1 deletion internal/example/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ import (
routeservice "github.com/envoyproxy/go-control-plane/envoy/service/route/v3"
runtimeservice "github.com/envoyproxy/go-control-plane/envoy/service/runtime/v3"
secretservice "github.com/envoyproxy/go-control-plane/envoy/service/secret/v3"
"github.com/envoyproxy/go-control-plane/pkg/cache/v3"
"github.com/envoyproxy/go-control-plane/pkg/server/v3"
"github.com/envoyproxy/go-control-plane/pkg/test/v3"
)

const (
Expand All @@ -41,6 +43,58 @@ const (
grpcMaxConcurrentStreams = 1000000
)

type Server struct {
xdsserver server.Server
}

func NewServer(ctx context.Context, cache cache.Cache, cb *test.Callbacks) *Server {
srv := server.NewServer(ctx, cache, cb)
return &Server{srv}
}

func (s *Server) registerServer(grpcServer *grpc.Server) {
// register services
discoverygrpc.RegisterAggregatedDiscoveryServiceServer(grpcServer, s.xdsserver)
endpointservice.RegisterEndpointDiscoveryServiceServer(grpcServer, s.xdsserver)
clusterservice.RegisterClusterDiscoveryServiceServer(grpcServer, s.xdsserver)
routeservice.RegisterRouteDiscoveryServiceServer(grpcServer, s.xdsserver)
listenerservice.RegisterListenerDiscoveryServiceServer(grpcServer, s.xdsserver)
secretservice.RegisterSecretDiscoveryServiceServer(grpcServer, s.xdsserver)
runtimeservice.RegisterRuntimeDiscoveryServiceServer(grpcServer, s.xdsserver)
}

func (s *Server) Run(port uint) {
// gRPC golang library sets a very small upper bound for the number gRPC/h2
// streams over a single TCP connection. If a proxy multiplexes requests over
// a single connection to the management server, then it might lead to
// availability problems. Keepalive timeouts based on connection_keepalive parameter https://www.envoyproxy.io/docs/envoy/latest/configuration/overview/examples#dynamic
var grpcOptions []grpc.ServerOption
grpcOptions = append(grpcOptions,
grpc.MaxConcurrentStreams(grpcMaxConcurrentStreams),
grpc.KeepaliveParams(keepalive.ServerParameters{
Time: grpcKeepaliveTime,
Timeout: grpcKeepaliveTimeout,
}),
grpc.KeepaliveEnforcementPolicy(keepalive.EnforcementPolicy{
MinTime: grpcKeepaliveMinTime,
PermitWithoutStream: true,
}),
)
grpcServer := grpc.NewServer(grpcOptions...)

lis, err := net.Listen("tcp", fmt.Sprintf(":%d", port))
if err != nil {
log.Fatal(err)
}

s.registerServer(grpcServer)

log.Printf("management server listening on %d\n", port)
if err = grpcServer.Serve(lis); err != nil {
log.Println(err)
}
}

func registerServer(grpcServer *grpc.Server, server server.Server) {
// register services
discoverygrpc.RegisterAggregatedDiscoveryServiceServer(grpcServer, server)
Expand All @@ -53,7 +107,7 @@ func registerServer(grpcServer *grpc.Server, server server.Server) {
}

// RunServer starts an xDS server at the given port.
func RunServer(ctx context.Context, srv server.Server, port uint) {
func RunServer(srv server.Server, port uint) {
// gRPC golang library sets a very small upper bound for the number gRPC/h2
// streams over a single TCP connection. If a proxy multiplexes requests over
// a single connection to the management server, then it might lead to
Expand Down