Skip to content

Commit

Permalink
feat: make HTTP2 optional (#33)
Browse files Browse the repository at this point in the history
Implementation of the API change here: #32

Also added a runner so that the cache is loaded from Blueprint at
bootup.
  • Loading branch information
jgkawell authored Aug 9, 2024
1 parent de44fd9 commit 160dea6
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 16 deletions.
49 changes: 36 additions & 13 deletions services/core/fuse/control_plane/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type (
ControlPlane interface {
cache.SnapshotCache

LoadCache()
UpdateCacheWithNewRoute(route *ntv1.Route) error
Increment() string
}
Expand Down Expand Up @@ -106,6 +107,18 @@ func NewControlPlane(logger chassis.Logger) *controlPlane {
}
}

func (cp *controlPlane) LoadCache() {
var (
ctx = context.Background()
client = kvv1Connect.NewKeyValueServiceClient(http.DefaultClient, chassis.GetConfig().Entrypoint())
)

err := cp.apply(ctx, client)
if err != nil {
cp.logger.WithError(err).Error("failed to load cache")
}
}

func (cp *controlPlane) UpdateCacheWithNewRoute(route *ntv1.Route) error {
var (
ctx = context.Background()
Expand All @@ -130,6 +143,11 @@ func (cp *controlPlane) UpdateCacheWithNewRoute(route *ntv1.Route) error {
return ErrUnableToSaveRoute
}

return cp.apply(ctx, client)
}

func (cp *controlPlane) apply(ctx context.Context, client kvv1Connect.KeyValueServiceClient) error {

routeModel, err := anypb.New(&ntv1.Route{})
if err != nil {
cp.logger.Error(err.Error())
Expand Down Expand Up @@ -247,27 +265,32 @@ func (cp *controlPlane) increment() string {
}

func makeCluster(r *ntv1.Route, loadAssignment *endpoint.ClusterLoadAssignment) *cluster.Cluster {
// enables grpc routing
a, _ := anypb.New(&upstreams.HttpProtocolOptions{
UpstreamProtocolOptions: &upstreams.HttpProtocolOptions_ExplicitHttpConfig_{
ExplicitHttpConfig: &upstreams.HttpProtocolOptions_ExplicitHttpConfig{
ProtocolConfig: &upstreams.HttpProtocolOptions_ExplicitHttpConfig_Http2ProtocolOptions{
Http2ProtocolOptions: &core.Http2ProtocolOptions{},
},
},
},
})
return &cluster.Cluster{
c := &cluster.Cluster{
Name: clusterName(r),
ConnectTimeout: durationpb.New(5 * time.Second),
ClusterDiscoveryType: &cluster.Cluster_Type{Type: cluster.Cluster_LOGICAL_DNS},
LbPolicy: cluster.Cluster_ROUND_ROBIN,
LoadAssignment: loadAssignment,
DnsLookupFamily: cluster.Cluster_V4_ONLY,
TypedExtensionProtocolOptions: map[string]*anypb.Any{
}

// enabling HTTP2 supports gRPC but can cause servers without HTTP2 support to fail the connection with a protocol error
if r.EnableHttp2 {
a, _ := anypb.New(&upstreams.HttpProtocolOptions{
UpstreamProtocolOptions: &upstreams.HttpProtocolOptions_ExplicitHttpConfig_{
ExplicitHttpConfig: &upstreams.HttpProtocolOptions_ExplicitHttpConfig{
ProtocolConfig: &upstreams.HttpProtocolOptions_ExplicitHttpConfig_Http2ProtocolOptions{
Http2ProtocolOptions: &core.Http2ProtocolOptions{},
},
},
},
})
c.TypedExtensionProtocolOptions = map[string]*anypb.Any{
"envoy.extensions.upstreams.http.v3.HttpProtocolOptions": a,
},
}
}

return c
}

// `makeRoute` creates a route for the given cluster, and a virtual host for the process that is attempting to add the route.
Expand Down
2 changes: 1 addition & 1 deletion services/core/fuse/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
connectrpc.com/connect v1.16.2
github.com/envoyproxy/go-control-plane v0.12.0
github.com/google/uuid v1.6.0
github.com/steady-bytes/draft/api v0.3.1
github.com/steady-bytes/draft/api v0.3.2
github.com/steady-bytes/draft/pkg/chassis v0.3.0
github.com/steady-bytes/draft/pkg/loggers v0.2.0
google.golang.org/protobuf v1.34.2
Expand Down
4 changes: 2 additions & 2 deletions services/core/fuse/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.18.2 h1:LUXCnvUvSM6FXAsj6nnfc8Q2tp1dIgUfY9Kc8GsSOiQ=
github.com/spf13/viper v1.18.2/go.mod h1:EKmWIqdnk5lOcmR72yw6hS+8OPYcwD0jteitLMVB+yk=
github.com/steady-bytes/draft/api v0.3.1 h1:dv4EoLefhqfCFDEukjZlwqVl9GffLWLCQC7ZlAgY9ZU=
github.com/steady-bytes/draft/api v0.3.1/go.mod h1:mlwxjvRiqvwySGdzVmF8voFhMffWq2F7dyd+xt6kENA=
github.com/steady-bytes/draft/api v0.3.2 h1:JvRiiKqND27UedJavObspNcVyuGv55sd3j2s1i7akCE=
github.com/steady-bytes/draft/api v0.3.2/go.mod h1:mlwxjvRiqvwySGdzVmF8voFhMffWq2F7dyd+xt6kENA=
github.com/steady-bytes/draft/pkg/chassis v0.3.0 h1:9uk+RRuSec2Sl7wy5ZSNv3IcqRqbU6vYiVSLj5Bo9co=
github.com/steady-bytes/draft/pkg/chassis v0.3.0/go.mod h1:5TQfgltb/008bcuLe6vAQva0Kzrq1zEDCFoCfQjzzLo=
github.com/steady-bytes/draft/pkg/loggers v0.2.0 h1:d1a3l6HMfa8g9+o+roeT5BoA7aeDBIh6UMLeOddsNsk=
Expand Down
2 changes: 2 additions & 0 deletions services/core/fuse/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@ func main() {
}).
WithRPCHandler(xdsServer).
WithRPCHandler(controlPlaneRPC).
// make sure to load the cache on boot
WithRunner(controlPlane.LoadCache).
Start()
}

0 comments on commit 160dea6

Please sign in to comment.