Christian_15126
Jan 07, 2013Nimbostratus
irule catches info.blah.edu/* instead of specific paths in match criteria
Match subdomain.domain, with a "/", b_path, c_path, d_path; Then A/B load balance 60/40 percent ratio.
Created 12/11/2012 CH
Last edited 12/11/12
when RULE_INIT {
log local0. "initializing ... "
set static::debug 1
Host header variables for sub-domain and domain.
set static::a_sub "degrees"
set static::b_sub "onlinedegrees"
set static::c_sub "info"
set static::domain "blah.edu"
Path variables.
set static::b_path "\?*"
set static::c_path "index.htm"
set static::d_path "degrees"
Current count variable.
set static::current 0
1 in N requests will go to B subdomain - 6 for 60/40 ratio.
set static::ratio 6
Max value to reset count.
set static::max 10
}
when HTTP_REQUEST {
F5 doesn't put the question mark in the query string
if { [HTTP::query] equals "" } { set new_query "" }
else { set new_query "?[HTTP::query]" }
if { $static::debug > 1 } { log local0. "new query string is \[$new_query\]" }
Only catch requests that come in with the proper host header
if { [string tolower [HTTP::host]] equals "$static::c_sub.$static::domain" } {
Only catch clients that come in through the URI path static::a_path, static::b_site, or static::c_path
if { [string tolower [HTTP::path]] equals "/" || [string tolower [HTTP::uri]] matches_glob "/$static::b_path" || [string tolower [HTTP::uri]] starts_with "/$static::c_path" || [string tolower [HTTP::uri]] starts_with "/$static::d_path" } {
Check for < current for 60% of traffic.
if { $static::current < $static::ratio } {
Redirect traffic to A subdomain
if { $static::debug } { log local0. "redirect FROM [HTTP::uri] TO " }
HTTP::respond 301 Location "" "Cache-Control" "no-cache, must-revalidate"
Increment the counter
incr static::current
log local0. "A count is ${static::current} with ratio ${static::ratio}"
} else {
Redirect traffic to B subdomain for 40% requests
if { $static::current < $static::max } {
Redirect traffic to B subdomain
if { $static::debug } { log local0. "redirect FROM [HTTP::uri] TO " }
HTTP::respond 301 Location "" "Cache-Control" "no-cache, must-revalidate"
if { $static::debug > 1 } { log local0. "round robin is $static::round_robin" }
Increment the counter
incr static::current
log local0. "B count is ${static::current} with max ${static::max}"
} else {
If current count is 10, reset count to 0 and redirect traffic to A subdomain
if { $static::current >= $static::max } {
set static::current 0
log local0. "Reset current variable to ${static::current} "
if { $static::debug } { log local0. "redirect FROM [HTTP::uri] TO " }
HTTP::respond 301 Location "" "Cache-Control" "no-cache, must-revalidate"
TCP::close
event HTTP_REQUEST disable
}
}
}
}
}
}