With at least two endpoints and Traffic Policy, you can run simple A/B tests with using the rand.double() macro.
Basic example
This rule:
- Uses
rand.double() to generate a random double between 0 and 1 when traffic reaches the endpoint
- Checks if the value is less than or equal to 0.5
- If so, it routes the traffic to a different internal agent endpoint.
on_http_request:
- expressions:
- rand.double() <= 0.5
actions:
- type: forward-internal
config:
url: https://a.internal
- actions:
- type: forward-internal
config:
url: https://b.internal
You can change the value the random number is checked against to split the traffic in different ratios. For example,>=0.8 would send 80% of the traffic to one endpoint and 20% to the other.
See the forward-internal Traffic Policy action docs for more information.
Using rewrites
You can also send the traffic to a different route using URL rewrites.
on_http_request:
- expressions:
- rand.double() <= 0.5
actions:
- type: url-rewrite
config:
from: "/path/to/test"
to: "/path/to/test-b"
- actions:
- type: forward-internal
config:
url: https://b.internal
See the URL Rewrite Example for another example using rewrites.