Forum Discussion

Chris_103315's avatar
Chris_103315
Icon for Nimbostratus rankNimbostratus
Mar 04, 2008

HTTP_REQUEST event bypassed?

I'm writing an iRule in our production environment to split traffic based on URI. All works fine except there is one request that seemingly doesn't fall into any case and is in turn load-balanced between the enabled nodes in default pool.

 

 

basically for all requests I want:

 

/forums -> node 1-3

 

/account -> node 4-6

 

/api -> "special pool" of 2 nodes

 

Everything else -> node 7-9

 

 

The problem is that I still see a single request (for example /forums/posts.aspx) go to all nodes when it should only go to 1-3. I also have verified that the request is serviced by the default pool of all 9 nodes by disabling all but a couple nodes and seeing that the /forums/posts.aspx only goes to the enabled nodes. The rest of the traffic is correctly segmented via the iRule. If this was a parse error on the URI this request should fall into the else block and only go to 7-9.

 

 

I want to use iRules to control all requests, but it seems there are circumstances "when HTTP_REQUEST" event doesn't fire or isn't caught. Does anyone know what might cause this?

 

 

 

An example of the iRule:

 

 

when HTTP_REQUEST priority 100

 

{

 

if {[string tolower [HTTP::uri]] starts_with "/forums/" }

 

{

 

pool POOL01_03

 

}

 

elseif {[string tolower [HTTP::uri]] starts_with "/account/" }

 

{

 

pool POOL04_06

 

}

 

elseif {[string tolower [HTTP::uri]] starts_with "/api/"}

 

{

 

pool POOLAPI

 

}

 

else

 

{

 

pool POOL07_09

 

}

 

}

2 Replies

  • Hi,

     

     

    With this iRule it should work.

     

     

    Do you have other iRules assigned to this VS that may create some conflict?

     

     

    Can you create some logging and redo your testing and see if it goes in the good part ?

     

     

    ex:

     

     

    when HTTP_REQUEST

     

    {

     

    log local0. "uri is [HTTP::uri]"

     

    if {[string tolower [HTTP::uri]] starts_with "/forums/" }

     

    {

     

    log local0. "Pool 0103 used"

     

    pool POOL01_03

     

    } elseif {[string tolower [HTTP::uri]] starts_with "/account/" }

     

    {

     

    log local0. "POOL_04_06 used"

     

    pool POOL04_06

     

    } elseif {[string tolower [HTTP::uri]] starts_with "/api/"}

     

    {

     

    log local0. "POOLAPI used"

     

    pool POOLAPI

     

    } else {

     

    log local0. "default pool07_09"

     

    pool POOL07_09

     

    }

     

    }

     

     

    Can you show us the output available in /var/log/ltm?
  • Had to chime in. Duplicating "string tolower" on each of the if/elseif's is way too much overhead. I'd go with something like this:

    when HTTP_REQUEST {
      log local0. "uri is [HTTP::uri]"
      switch -glob [string tolower [HTTP::uri]] {
        "/forums/*" {
          log local0. "POOL01_03 used"
          pool POOL01_03
        }
        "/account/*" {
          log local0. "POOL04_06 used"
          pool POOL04_06
        }
        "/api/*" {
          log local0. "POOLAPI used"
          pool POOLAPI
        }
        default {
          log local0. "default pool POOL07_09 used"
          pool POOL07_09
        }
      }
    }

    This uses no local variables an only has one string conversion.

    -Joe