Route n% of traffic based on a path param
Have an interesting task when we don't want to have a full rollout of a new feature.
We'd like to route only the percentage of traffic (based on a path parameter) to the new endpoint.
We'd like to calculate the percentage based on a 'specialPathParam':
ourservice.com/one/'specialPathParam'/something .
So, if we want to route 50% to the new endpoint:
if there're 2 requests
ourservice.com/one/'specialPathParamOne'/something
ourservice.com/one/'specialPathParamTwo'/something ,
one request with 'specialPathParamOne' should go to the new endpoint
and another one with 'specialPathParamTwo' should go to the old one.
Trying to find a way to implement it in VCL somehow...
Any tips and tricks here?
Thanks a lot!
-
Hi Zefr,
Before we go too deep on this, I'd like to recommend you check out A/B Testing at the Edge, as it demonstrates how you could implement this with Fastly without having to modify URLs or have your origins manage routing.
For what you're doing, however, all you really need is a Request Condition attached to each origin to test for those strings in the URLs. Something like:
req.url ~ "specialPathParamOne"
The resulting VCL would be like:
if (req.url ~ "specialPathParamOne") {
set req.backend = F_origin_0;
} else {
set req.backend = F_origin_1;
} -
I just need to calculate the percentage of '${specialPathParam}', this '${specialPathParam}' can be anything...
So I have to randomize the requests around my '${specialPathParams}' which actually looks like randombool with seeded param:Another function,
randombool_seeded()
, takes an additional seed argument.
Results for a given seed will always be the same.https://docs.fastly.com/vcl/randomness/
So looks like I need something like:
if (randombool_seeded(X, 100, std.atoi('${specialPathParam}')) ) { set req.backend = F_origin_0; } else { set req.backend = F_origin_1; }
and no need for headers.
So X percent of traffic will go to the backend 1 and requests with the same '${specialPathParam}' value would go to the same backend.
Love you, Fastly!
Hope I didn't make mistakes on the way...
Please sign in to leave a comment.
Comments
3 comments