Skip to content

Commit

Permalink
Add Rate-Limit xDS config server related control plane functionality (#…
Browse files Browse the repository at this point in the history
…598)

* Add Rate-Limit xDS config server related control plane functionality
#595

Signed-off-by: Renuka Fernando <renukapiyumal@gmail.com>
  • Loading branch information
renuka-fernando committed Jan 27, 2023
1 parent 26dd058 commit 29a4b73
Show file tree
Hide file tree
Showing 6 changed files with 830 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/cache/types/types.go
Expand Up @@ -48,5 +48,6 @@ const (
Secret
Runtime
ExtensionConfig
RateLimitConfig
UnknownType // token to count the total number of supported types
)
7 changes: 7 additions & 0 deletions pkg/cache/v3/resource.go
Expand Up @@ -30,6 +30,7 @@ import (
runtime "github.com/envoyproxy/go-control-plane/envoy/service/runtime/v3"
"github.com/envoyproxy/go-control-plane/pkg/cache/types"
"github.com/envoyproxy/go-control-plane/pkg/resource/v3"
ratelimit "github.com/envoyproxy/go-control-plane/ratelimit/config/ratelimit/v3"
)

// GetResponseType returns the enumeration for a valid xDS type URL.
Expand All @@ -53,6 +54,8 @@ func GetResponseType(typeURL resource.Type) types.ResponseType {
return types.Runtime
case resource.ExtensionConfigType:
return types.ExtensionConfig
case resource.RateLimitConfigType:
return types.RateLimitConfig
}
return types.UnknownType
}
Expand All @@ -78,6 +81,8 @@ func GetResponseTypeURL(responseType types.ResponseType) (string, error) {
return resource.RuntimeType, nil
case types.ExtensionConfig:
return resource.ExtensionConfigType, nil
case types.RateLimitConfig:
return resource.RateLimitConfigType, nil
default:
return "", fmt.Errorf("couldn't map response type %v to known resource type", responseType)
}
Expand All @@ -104,6 +109,8 @@ func GetResourceName(res types.Resource) string {
return v.GetName()
case *core.TypedExtensionConfig:
return v.GetName()
case *ratelimit.RateLimitConfig:
return v.GetName()
case types.ResourceWithName:
return v.GetName()
default:
Expand Down
3 changes: 3 additions & 0 deletions pkg/resource/v3/resource.go
Expand Up @@ -26,6 +26,9 @@ const (
RuntimeType = APITypePrefix + "envoy.service.runtime.v3.Runtime"
ThriftRouteType = APITypePrefix + "envoy.extensions.filters.network.thrift_proxy.v3.RouteConfiguration"

// Rate Limit service
RateLimitConfigType = APITypePrefix + "ratelimit.config.ratelimit.v3.RateLimitConfig"

// AnyType is used only by ADS
AnyType = ""
)
Expand Down
14 changes: 14 additions & 0 deletions pkg/server/v3/server.go
Expand Up @@ -38,6 +38,7 @@ import (
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/resource/v3"
rlsconfigservice "github.com/envoyproxy/go-control-plane/ratelimit/service/ratelimit/v3"
)

// Server is a collection of handlers for streaming discovery requests.
Expand All @@ -52,6 +53,7 @@ type Server interface {
secretservice.SecretDiscoveryServiceServer
runtimeservice.RuntimeDiscoveryServiceServer
extensionconfigservice.ExtensionConfigDiscoveryServiceServer
rlsconfigservice.RateLimitConfigDiscoveryServiceServer

rest.Server
sotw.Server
Expand Down Expand Up @@ -220,6 +222,10 @@ func (s *server) StreamExtensionConfigs(stream extensionconfigservice.ExtensionC
return s.StreamHandler(stream, resource.ExtensionConfigType)
}

func (s *server) StreamRlsConfigs(stream rlsconfigservice.RateLimitConfigDiscoveryService_StreamRlsConfigsServer) error {
return s.StreamHandler(stream, resource.RateLimitConfigType)
}

// VHDS doesn't support SOTW requests, so no handler for it exists.

// Fetch is the universal fetch method.
Expand Down Expand Up @@ -291,6 +297,14 @@ func (s *server) FetchExtensionConfigs(ctx context.Context, req *discovery.Disco
return s.Fetch(ctx, req)
}

func (s *server) FetchRlsConfigs(ctx context.Context, req *discovery.DiscoveryRequest) (*discovery.DiscoveryResponse, error) {
if req == nil {
return nil, status.Errorf(codes.Unavailable, "empty request")
}
req.TypeUrl = resource.RateLimitConfigType
return s.Fetch(ctx, req)
}

// VHDS doesn't support REST requests, so no handler exists for this.

func (s *server) DeltaStreamHandler(stream stream.DeltaStream, typeURL string) error {
Expand Down

0 comments on commit 29a4b73

Please sign in to comment.