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
Conversation
Codecov Report
📣 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
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>
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 |
Signed-off-by: Stanislav Bondarenko <stanislav.bondarenko@gmail.com>
Signed-off-by: Stanislav Bondarenko <stanislav.bondarenko@gmail.com>
done |
internal/gatewayapi/route.go
Outdated
} 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)), |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
internal/gatewayapi/route.go
Outdated
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)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is ^
needed ?
There was a problem hiding this comment.
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>
internal/gatewayapi/route.go
Outdated
@@ -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]*)*" |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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
internal/gatewayapi/route.go
Outdated
@@ -26,6 +26,11 @@ type RoutesTranslator interface { | |||
ProcessUDPRoutes(udpRoutes []*v1alpha2.UDPRoute, gateways []*GatewayContext, resources *Resources, xdsIR XdsIRMap) []*UDPRouteContext | |||
} | |||
|
|||
const ( |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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)?
internal/gatewayapi/route.go
Outdated
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)), |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
internal/gatewayapi/route.go
Outdated
@@ -26,6 +26,11 @@ type RoutesTranslator interface { | |||
ProcessUDPRoutes(udpRoutes []*v1alpha2.UDPRoute, gateways []*GatewayContext, resources *Resources, xdsIR XdsIRMap) []*UDPRouteContext | |||
} | |||
|
|||
const ( |
There was a problem hiding this comment.
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>
Signed-off-by: Stanislav Bondarenko <stanislav.bondarenko@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM thanks !
Closes #963