time.interval_elapsed_ratio
Available inall subroutines.
Returns the proportion of time between start and end that has elapsed at the reference time, as a number between 0 and 1.
Example
sub vcl_miss { declare local var.ratio FLOAT; set var.ratio = time.interval_elapsed_ratio(now, std.time("2025-01-01 00:00:00", now), std.time("2026-01-01 00:00:00", now));
if (var.ratio >= req.digest.ratio) { // Request is eligible for A/B test }}
Note that req.digest.ratio
is not meaningful in vcl_recv
since the digest is not yet computed, but you can use fastly.hash
to acheive similar results.
sub vcl_recv { declare local var.ratio FLOAT; set var.ratio = time.interval_elapsed_ratio(now, std.time("2025-01-01 00:00:00", now), std.time("2026-01-01 00:00:00", now));
declare local var.current_ratio FLOAT = fastly.hash(req.url, 0, 0, 1024); set var.current_ratio /= 1024.0;
if (var.ratio >= var.current_ratio) { // Request is eligible for A/B test }}