Mirror a fraction of requests to another destination
Route only requests carrying the mirror-this-request: true header, and copy 30% of them to a second destination with a RequestMirror filter while the originals continue to backend. Other requests from this client to backend match no rule and receive a 404.
Configuration
apiVersion: kuma.io/v1alpha1
kind: MeshHTTPRoute
metadata:
name: backend-mirror
namespace: kong-mesh-demo
labels:
kuma.io/mesh: default
spec:
targetRef:
kind: Dataplane
labels:
app: frontend
to:
- targetRef:
kind: MeshService
labels:
kuma.io/display-name: backend
rules:
- matches:
- headers:
- type: Exact
name: mirror-this-request
value: 'true'
default:
filters:
- type: RequestMirror
requestMirror:
percentage: 30
backendRef:
kind: MeshService
labels:
kuma.io/display-name: backend-shadow
port: 8080
backendRefs:
- kind: MeshService
labels:
kuma.io/display-name: backend
port: 8080Copied!
type: MeshHTTPRoute
name: backend-mirror
mesh: default
spec:
targetRef:
kind: Dataplane
labels:
app: frontend
to:
- targetRef:
kind: MeshService
labels:
kuma.io/display-name: backend
rules:
- matches:
- headers:
- type: Exact
name: mirror-this-request
value: 'true'
default:
filters:
- type: RequestMirror
requestMirror:
percentage: 30
backendRef:
kind: MeshService
labels:
kuma.io/display-name: backend-shadow
port: 8080
backendRefs:
- kind: MeshService
labels:
kuma.io/display-name: backend
port: 8080Copied!
Adjust konnect_mesh_control_plane.my_meshcontrolplane.id and konnect_mesh.my_mesh.name according to your current configuration.
resource "konnect_mesh_http_route" "backend_mirror" {
provider = konnect-beta
type = "MeshHTTPRoute"
name = "backend-mirror"
spec = {
target_ref = {
kind = "Dataplane"
labels = {
app = "frontend"
}
}
to = [
{
target_ref = {
kind = "MeshService"
labels = {
"kuma.io/display-name" = "backend"
}
}
rules = [
{
matches = [
{
headers = [
{
type = "Exact"
name = "mirror-this-request"
value = "true"
}
]
}
]
default = {
filters = [
{
type = "RequestMirror"
request_mirror = {
percentage = { integer = 30 }
backend_ref = {
kind = "MeshService"
labels = {
"kuma.io/display-name" = "backend-shadow"
}
port = 8080
}
}
}
]
backend_refs = [
{
kind = "MeshService"
labels = {
"kuma.io/display-name" = "backend"
}
port = 8080
}
]
}
}
]
}
]
}
labels = {
"kuma.io/mesh" = konnect_mesh.my_mesh.name
}
cp_id = konnect_mesh_control_plane.my_meshcontrolplane.id
mesh = konnect_mesh.my_mesh.name
}
Copied!