|
| 1 | +# GEP-3171: Percentage-based Request Mirroring |
1 | 2 |
|
| 3 | +* Issue: [#3171](https://github.com/kubernetes-sigs/gateway-api/issues/3171) |
| 4 | +* Status: **Provisional** |
| 5 | + |
| 6 | +(See status definitions [here](/geps/overview/#gep-states).) |
| 7 | + |
| 8 | +## TLDR |
| 9 | + |
| 10 | +Enhance the existing [Request Mirroring](https://gateway-api.sigs.k8s.io/guides/http-request-mirroring/) feature by allowing users to specify a percentage of requests they'd like mirrored. |
| 11 | + |
| 12 | +## Goals |
| 13 | + |
| 14 | +Successfully implement the feature. |
| 15 | + |
| 16 | +## Introduction |
| 17 | + |
| 18 | +[Request Mirroring](https://gateway-api.sigs.k8s.io/guides/http-request-mirroring/) is a feature that allows a user to mirror requests going to some backend A along to some other specified backend B. Right now Request Mirroring is an all or nothing feature – either 100% of request are mirrored, or 0% are. Percentage-based Request Mirroring will allow users to specify a percentage of requests they'd like mirrored as opposed to every single request. |
| 19 | + |
| 20 | +This feature is already [supported by Envoy](https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/route/v3/route_components.proto#envoy-v3-api-msg-config-route-v3-routeaction-requestmirrorpolicy), so adding it for the Gateway API would enable better integration between the two products. There's also an existing user desire for this feature on the [HAProxy side](https://www.haproxy.com/blog/haproxy-traffic-mirroring-for-real-world-testing) and [NGINX side](https://alex.dzyoba.com/blog/nginx-mirror/). Since Request Mirroring is already supported by the Gateway API, Percentage-based Request Mirroring would a clear improvement on this pre-existing feature. |
| 21 | + |
| 22 | +## API |
| 23 | + |
| 24 | +This GEP proposes the following API changes: |
| 25 | + |
| 26 | +* Add utility type `Fraction` to [v1/shared_types.go](https://github.com/kubernetes-sigs/gateway-api/blob/cb5bf1541fa70f0692aebde8c64bba434cf331b6/apis/v1/shared_types.go) and include the equivalent type `Percentage`: |
| 27 | + |
| 28 | + |
| 29 | +```go |
| 30 | +type Fraction struct { |
| 31 | + // +optional |
| 32 | + // +kubebuilder:validation:Minimum=0 |
| 33 | + Numerator int32 `json:"numerator,omitempty"` |
| 34 | + |
| 35 | + // +optional |
| 36 | + // +kubebuilder:default=100 |
| 37 | + // +kubebuilder:validation:Minimum=1 |
| 38 | + Denominator int32 `json:"denominator,omitempty"` |
| 39 | +} |
| 40 | + |
| 41 | +type Percentage Fraction |
| 42 | +``` |
| 43 | + |
| 44 | + |
| 45 | +* Update the `HTTPRequestMirrorFilter` struct to include a `MirrorPercent` field of type `Percentage`: |
| 46 | + |
| 47 | + |
| 48 | +```go |
| 49 | +// HTTPRequestMirrorFilter defines configuration for the RequestMirror filter. |
| 50 | +type HTTPRequestMirrorFilter struct { |
| 51 | + // BackendRef references a resource where mirrored requests are sent. |
| 52 | + // |
| 53 | + // Mirrored requests must be sent only to a single destination endpoint |
| 54 | + // within this BackendRef, irrespective of how many endpoints are present |
| 55 | + // within this BackendRef. |
| 56 | + // |
| 57 | + // If the referent cannot be found, this BackendRef is invalid and must be |
| 58 | + // dropped from the Gateway. The controller must ensure the "ResolvedRefs" |
| 59 | + // condition on the Route status is set to `status: False` and not configure |
| 60 | + // this backend in the underlying implementation. |
| 61 | + // |
| 62 | + // If there is a cross-namespace reference to an *existing* object |
| 63 | + // that is not allowed by a ReferenceGrant, the controller must ensure the |
| 64 | + // "ResolvedRefs" condition on the Route is set to `status: False`, |
| 65 | + // with the "RefNotPermitted" reason and not configure this backend in the |
| 66 | + // underlying implementation. |
| 67 | + // |
| 68 | + // In either error case, the Message of the `ResolvedRefs` Condition |
| 69 | + // should be used to provide more detail about the problem. |
| 70 | + // |
| 71 | + // Support: Extended for Kubernetes Service |
| 72 | + // |
| 73 | + // Support: Implementation-specific for any other resource |
| 74 | + BackendRef BackendObjectReference `json:"backendRef"` |
| 75 | + |
| 76 | + // MirrorPercent represents the fraction of requests that should be |
| 77 | + // mirrored to BackendRef. |
| 78 | + // |
| 79 | + // If MirrorPercent is not specified, then 100% of requests will be |
| 80 | + // mirrored. |
| 81 | + // |
| 82 | + // +optional |
| 83 | + MirrorPercent Percentage `json:"mirrorPercent,omitempty"` |
| 84 | +} |
| 85 | +``` |
0 commit comments