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

gatewayapi: adds matching on GRPCRoute method and service #1050

Merged
merged 8 commits into from Feb 23, 2023

Conversation

sbko
Copy link
Contributor

@sbko sbko commented Feb 16, 2023

Closes #963

@sbko sbko requested a review from a team as a code owner February 16, 2023 15:10
@codecov-commenter
Copy link

codecov-commenter commented Feb 16, 2023

Codecov Report

Merging #1050 (d5e3a46) into main (b6e0471) will decrease coverage by 0.61%.
The diff coverage is 73.68%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##             main    #1050      +/-   ##
==========================================
- Coverage   64.82%   64.21%   -0.61%     
==========================================
  Files          67       70       +3     
  Lines        8730     9051     +321     
==========================================
+ Hits         5659     5812     +153     
- Misses       2697     2841     +144     
- Partials      374      398      +24     
Impacted Files Coverage Δ
internal/gatewayapi/helpers.go 75.00% <0.00%> (-1.78%) ⬇️
internal/gatewayapi/route.go 86.31% <100.00%> (+1.18%) ⬆️
internal/provider/kubernetes/helpers.go 81.08% <0.00%> (-1.36%) ⬇️
...rnal/infrastructure/kubernetes/proxy_deployment.go 89.28% <0.00%> (-1.14%) ⬇️
internal/provider/kubernetes/controller.go 50.22% <0.00%> (-1.02%) ⬇️
internal/gatewayapi/contexts.go 76.22% <0.00%> (-0.57%) ⬇️
internal/gatewayapi/translator.go 97.10% <0.00%> (ø)
internal/cmd/egctl/experimental.go 0.00% <0.00%> (ø)
internal/cmd/egctl/translate.go 66.98% <0.00%> (ø)
internal/cmd/egctl/version.go 0.00% <0.00%> (ø)
... and 1 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Signed-off-by: Stanislav Bondarenko <stanislav.bondarenko@gmail.com>
@arkodg
Copy link
Contributor

arkodg commented Feb 16, 2023

hey @sbko thanks for picking this up, can you incorporate one of these matches into the user doc https://github.com/envoyproxy/gateway/blob/main/docs/latest/user/grpc-routing.md, maybe add a service match for yages.Ping

@arkodg arkodg added this to the 0.4.0-rc.1 milestone Feb 16, 2023
Signed-off-by: Stanislav Bondarenko <stanislav.bondarenko@gmail.com>
Signed-off-by: Stanislav Bondarenko <stanislav.bondarenko@gmail.com>
@sbko
Copy link
Contributor Author

sbko commented Feb 17, 2023

hey @sbko thanks for picking this up, can you incorporate one of these matches into the user doc https://github.com/envoyproxy/gateway/blob/main/docs/latest/user/grpc-routing.md, maybe add a service match for yages.Ping

done

} else if match.Method.Method != nil {
// Use regex match if only the method name is specified to match any service
irRoute.PathMatch = &ir.StringMatch{
SafeRegex: StringPtr(fmt.Sprintf("^/(?i)\\.?[a-z_][a-z_0-9]*(\\.[a-z_][a-z_0-9]*)*/%s$", *match.Method.Method)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets make this into a constant, so it can be reused, so will need to spend some cycles to ensure this regex looks right

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made it constant, refactored if else if so no need for nolint:gocritic anymore. please let me know if you prefer previous structure.

case v1alpha2.GRPCMethodMatchRegularExpression:
if match.Method.Service != nil && match.Method.Method != nil {
irRoute.PathMatch = &ir.StringMatch{
SafeRegex: StringPtr(fmt.Sprintf("^/%s/%s", *match.Method.Service, *match.Method.Method)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is ^ needed ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added for consistency between regexes. maybe slightly faster(?) :)

Signed-off-by: Stanislav Bondarenko <stanislav.bondarenko@gmail.com>
Signed-off-by: Stanislav Bondarenko <stanislav.bondarenko@gmail.com>
@@ -26,6 +26,11 @@ type RoutesTranslator interface {
ProcessUDPRoutes(udpRoutes []*v1alpha2.UDPRoute, gateways []*GatewayContext, resources *Resources, xdsIR XdsIRMap) []*UDPRouteContext
}

const (
GRPCServiceRegexPattern = "(?i)\\.?[a-z_][a-z_0-9]*(\\.[a-z_][a-z_0-9]*)*"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are there two different types here, isnt the only use case needed is when we want to match on method but service is empty ?

Copy link
Contributor Author

@sbko sbko Feb 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need GRPMethodRegexPattern to support a use case when service is specified with type: RegularExpression and emtpy method. Envoy's prefix is used when type is empty or type: Exact

@@ -26,6 +26,11 @@ type RoutesTranslator interface {
ProcessUDPRoutes(udpRoutes []*v1alpha2.UDPRoute, gateways []*GatewayContext, resources *Resources, xdsIR XdsIRMap) []*UDPRouteContext
}

const (
Copy link
Contributor

@arkodg arkodg Feb 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lizan is there a smarter way to do path segment matching in envoy rather than relying on regex matching ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From GEP-1016 we can use suffix match (with header matcher)?

case match.Method.Method == nil:
// Use prefix match if only the service name is specified
irRoute.PathMatch = &ir.StringMatch{
Prefix: StringPtr(fmt.Sprintf("/%s", service)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use path_separated_prefix or add / at the end of prefix?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it uses path_separated_prefix

@@ -26,6 +26,11 @@ type RoutesTranslator interface {
ProcessUDPRoutes(udpRoutes []*v1alpha2.UDPRoute, gateways []*GatewayContext, resources *Resources, xdsIR XdsIRMap) []*UDPRouteContext
}

const (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From GEP-1016 we can use suffix match (with header matcher)?

Signed-off-by: Stanislav Bondarenko <stanislav.bondarenko@gmail.com>
Signed-off-by: Stanislav Bondarenko <stanislav.bondarenko@gmail.com>
@sbko sbko requested a review from arkodg February 22, 2023 17:34
Signed-off-by: Stanislav Bondarenko <stanislav.bondarenko@gmail.com>
Copy link
Contributor

@arkodg arkodg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks !

@arkodg arkodg merged commit bf7993c into envoyproxy:main Feb 23, 2023
@sbko sbko deleted the grpcroutematch branch February 23, 2023 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for service method match in GRPCRoute
4 participants