Forum Discussion

Christian_15126's avatar
Christian_15126
Icon for Nimbostratus rankNimbostratus
Jan 07, 2013

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

 

}

 

}

 

}

 

}

 

}

 

}

 

6 Replies

  • Hi Christian,

     

     

    Check your other post for a reply:

     

    https://devcentral.f5.com/internal-forums/aft/2165463

     

     

    Aaron
  • Good to know (which I am entering everything lowercase). I suspect one of the following search criteria is the problem, but I don't understand why:

     

     

    [string tolower [HTTP::path]] equals "/" || [string tolower [HTTP::uri]] matches_glob "/$static::b_path"

     

     

    string tolower [HTTP::path]] equals "/" should just match info.blah.edu/, not info.blah.edu/*, and [string tolower [HTTP::uri]] matches_glob "/$static::b_path" should only match nfo.blah.edu/?* (for google marketing search queries). Am I missing something? I've also tried string tolower [HTTP::uri]] equals "/" instead of path, but didn't make a difference. The irule still matches and uri/path past info.blah.edu/asldkjflaskjfsa.
  • Arie's avatar
    Arie
    Icon for Altostratus rankAltostratus

    Have you considered checking the query string separately instead of as part of the URI? (i.e. using URI::query)

     

     

  • I thought that this part took care of the HTTP::query (but i didn't write that part of the code):

     

     

    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\]" }

     

     

    HTTP::respond 301 Location "http://${static::a_sub}.${static::domain}/$new_query"
  • Arie's avatar
    Arie
    Icon for Altostratus rankAltostratus

    I was referring to the line you posted:

     

    [string tolower [HTTP::path]] equals "/" || [string tolower [HTTP::uri]] matches_glob "/$static::b_path"

     

    Which is used in conjunction with:

     

    Path variables.

     

    set static::b_path "\?*"

     

    There are a few other inefficiencies in the code. For instance, it really make sense to convert the path to lower case if you're only checking to see if it equals "/"...

     

    Also, it's a bit curious to use a 301 and then tell the client to not cache it. If I'm not mistaken the RFC specifically states that 301 are to be cached. I'd recommend using a 307 (or even a 302).

     

    Another thing I noticed is that the ratio is not truly a ratio in a load-balancing sense since it sends the first 6 users to one location and the next 4 to another location. In reality this likely works out to a ratio, though (if you have enough traffic).

     

    Lastly, I'm wondering if the ratio is truly 60/40. Granted, I've only glanced at the iRule, but it looks like you're sending an extra request to A every 11th request (when the count is 10).

     

     

     

     

     

     

  • We had to use the no-cache extra stuff due to caching issues in firefox. Every other browser worked fine, but firefox held on to the cookie of session in such a way that if you just ctrl-r to test the ratio's, they would break sporadically in firefox. had to add in "Cache-Control" "no-cache, must-revalidate" to fix it. Obviously users aren't going to be pounding on f5 like an upset five year old but that's what our marketing folks were doing to validate, so we had to add in no-cache. ;)