Skip to content

Commit

Permalink
Gateway API - support percentage-based-request-mirroring (#5212)
Browse files Browse the repository at this point in the history
* initial implementation of perecentage-based-request-mirroring

Signed-off-by: Lior Lieberman <[email protected]>

* add tests

Signed-off-by: Lior Lieberman <[email protected]>

* add and fix tests

Signed-off-by: Lior Lieberman <[email protected]>

---------

Signed-off-by: Lior Lieberman <[email protected]>
  • Loading branch information
LiorLieberman authored Feb 7, 2025
1 parent 291da0f commit 581dc42
Show file tree
Hide file tree
Showing 26 changed files with 725 additions and 84 deletions.
14 changes: 11 additions & 3 deletions internal/gatewayapi/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type HTTPFilterIR struct {
AddResponseHeaders []ir.AddHeader
RemoveResponseHeaders []string

Mirrors []*ir.RouteDestination
Mirrors []*ir.MirrorPolicy

ExtensionRefs []*ir.UnstructuredRef
}
Expand Down Expand Up @@ -1003,11 +1003,19 @@ func (t *Translator) processRequestMirrorFilter(
return err
}

newMirror := &ir.RouteDestination{
routeDst := &ir.RouteDestination{
Name: fmt.Sprintf("%s-mirror-%d", irRouteDestinationName(filterContext.Route, filterContext.RuleIdx), filterIdx),
Settings: []*ir.DestinationSetting{ds},
}
filterContext.Mirrors = append(filterContext.Mirrors, newMirror)

var percent *float32
if f := mirrorFilter.Fraction; f != nil {
percent = ptr.To(100 * float32(f.Numerator) / float32(ptr.Deref(f.Denominator, int32(100))))
} else if p := mirrorFilter.Percent; p != nil {
percent = ptr.To(float32(*p))
}

filterContext.Mirrors = append(filterContext.Mirrors, &ir.MirrorPolicy{Destination: routeDst, Percentage: percent})
return nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,22 +145,24 @@ xdsIR:
name: httproute-1
namespace: default
mirrors:
- name: httproute/default/httproute-1/rule/0-mirror-0
settings:
- addressType: IP
endpoints:
- host: 7.7.7.7
port: 8080
protocol: HTTP
weight: 1
- name: httproute/default/httproute-1/rule/0-mirror-1
settings:
- addressType: IP
endpoints:
- host: 7.7.7.7
port: 8080
protocol: HTTP
weight: 1
- destination:
name: httproute/default/httproute-1/rule/0-mirror-0
settings:
- addressType: IP
endpoints:
- host: 7.7.7.7
port: 8080
protocol: HTTP
weight: 1
- destination:
name: httproute/default/httproute-1/rule/0-mirror-1
settings:
- addressType: IP
endpoints:
- host: 7.7.7.7
port: 8080
protocol: HTTP
weight: 1
name: httproute/default/httproute-1/rule/0/match/0/gateway_envoyproxy_io
pathMatch:
distinct: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,22 +170,24 @@ xdsIR:
name: httproute-1
namespace: default
mirrors:
- name: httproute/default/httproute-1/rule/0-mirror-1
settings:
- addressType: IP
endpoints:
- host: 7.7.7.7
port: 8080
protocol: HTTP
weight: 1
- name: httproute/default/httproute-1/rule/0-mirror-2
settings:
- addressType: IP
endpoints:
- host: 7.6.5.4
port: 8080
protocol: HTTP
weight: 1
- destination:
name: httproute/default/httproute-1/rule/0-mirror-1
settings:
- addressType: IP
endpoints:
- host: 7.7.7.7
port: 8080
protocol: HTTP
weight: 1
- destination:
name: httproute/default/httproute-1/rule/0-mirror-2
settings:
- addressType: IP
endpoints:
- host: 7.6.5.4
port: 8080
protocol: HTTP
weight: 1
name: httproute/default/httproute-1/rule/0/match/0/gateway_envoyproxy_io
pathMatch:
distinct: false
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
gateways:
- apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
namespace: envoy-gateway
name: gateway-1
spec:
gatewayClassName: envoy-gateway-class
listeners:
- name: http
protocol: HTTP
port: 80
hostname: "*.envoyproxy.io"
allowedRoutes:
namespaces:
from: All
httpRoutes:
- apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
namespace: default
name: httproute-1
spec:
hostnames:
- gateway.envoyproxy.io
parentRefs:
- namespace: envoy-gateway
name: gateway-1
sectionName: http
rules:
- matches:
- path:
value: "/"
backendRefs:
- name: service-1
port: 8080
filters:
- type: RequestMirror
requestMirror:
backendRef:
kind: Service
name: service-1
port: 8080
percent: 20
- type: RequestMirror
requestMirror:
backendRef:
kind: Service
name: mirror-service
port: 8080
fraction:
denominator: 50
numerator: 25
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
gateways:
- apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
creationTimestamp: null
name: gateway-1
namespace: envoy-gateway
spec:
gatewayClassName: envoy-gateway-class
listeners:
- allowedRoutes:
namespaces:
from: All
hostname: '*.envoyproxy.io'
name: http
port: 80
protocol: HTTP
status:
listeners:
- attachedRoutes: 1
conditions:
- lastTransitionTime: null
message: Sending translated listener configuration to the data plane
reason: Programmed
status: "True"
type: Programmed
- lastTransitionTime: null
message: Listener has been successfully translated
reason: Accepted
status: "True"
type: Accepted
- lastTransitionTime: null
message: Listener references have been resolved
reason: ResolvedRefs
status: "True"
type: ResolvedRefs
name: http
supportedKinds:
- group: gateway.networking.k8s.io
kind: HTTPRoute
- group: gateway.networking.k8s.io
kind: GRPCRoute
httpRoutes:
- apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
creationTimestamp: null
name: httproute-1
namespace: default
spec:
hostnames:
- gateway.envoyproxy.io
parentRefs:
- name: gateway-1
namespace: envoy-gateway
sectionName: http
rules:
- backendRefs:
- name: service-1
port: 8080
filters:
- requestMirror:
backendRef:
kind: Service
name: service-1
port: 8080
percent: 20
type: RequestMirror
- requestMirror:
backendRef:
kind: Service
name: mirror-service
port: 8080
fraction:
denominator: 50
numerator: 25
type: RequestMirror
matches:
- path:
value: /
status:
parents:
- conditions:
- lastTransitionTime: null
message: Route is accepted
reason: Accepted
status: "True"
type: Accepted
- lastTransitionTime: null
message: Resolved all the Object references for the Route
reason: ResolvedRefs
status: "True"
type: ResolvedRefs
controllerName: gateway.envoyproxy.io/gatewayclass-controller
parentRef:
name: gateway-1
namespace: envoy-gateway
sectionName: http
infraIR:
envoy-gateway/gateway-1:
proxy:
listeners:
- address: null
name: envoy-gateway/gateway-1/http
ports:
- containerPort: 10080
name: http-80
protocol: HTTP
servicePort: 80
metadata:
labels:
gateway.envoyproxy.io/owning-gateway-name: gateway-1
gateway.envoyproxy.io/owning-gateway-namespace: envoy-gateway
name: envoy-gateway/gateway-1
xdsIR:
envoy-gateway/gateway-1:
accessLog:
text:
- path: /dev/stdout
http:
- address: 0.0.0.0
hostnames:
- '*.envoyproxy.io'
isHTTP2: false
metadata:
kind: Gateway
name: gateway-1
namespace: envoy-gateway
sectionName: http
name: envoy-gateway/gateway-1/http
path:
escapedSlashesAction: UnescapeAndRedirect
mergeSlashes: true
port: 10080
routes:
- destination:
name: httproute/default/httproute-1/rule/0
settings:
- addressType: IP
endpoints:
- host: 7.7.7.7
port: 8080
protocol: HTTP
weight: 1
hostname: gateway.envoyproxy.io
isHTTP2: false
metadata:
kind: HTTPRoute
name: httproute-1
namespace: default
mirrors:
- destination:
name: httproute/default/httproute-1/rule/0-mirror-0
settings:
- addressType: IP
endpoints:
- host: 7.7.7.7
port: 8080
protocol: HTTP
weight: 1
percentage: 20
- destination:
name: httproute/default/httproute-1/rule/0-mirror-1
settings:
- addressType: IP
endpoints:
- host: 7.6.5.4
port: 8080
protocol: HTTP
weight: 1
percentage: 50
name: httproute/default/httproute-1/rule/0/match/0/gateway_envoyproxy_io
pathMatch:
distinct: false
name: ""
prefix: /
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,15 @@ xdsIR:
name: httproute-1
namespace: default
mirrors:
- name: httproute/default/httproute-1/rule/0-mirror-0
settings:
- addressType: IP
endpoints:
- host: 7.7.7.7
port: 8080
protocol: HTTP
weight: 1
- destination:
name: httproute/default/httproute-1/rule/0-mirror-0
settings:
- addressType: IP
endpoints:
- host: 7.7.7.7
port: 8080
protocol: HTTP
weight: 1
name: httproute/default/httproute-1/rule/0/match/0/gateway_envoyproxy_io
pathMatch:
distinct: false
Expand Down
Loading

0 comments on commit 581dc42

Please sign in to comment.