Forum Discussion

Moe_Jartin's avatar
Feb 02, 2011

per URI jsessionid persistence

I am trying to enable persistence on the JSESSIONID cookie but only for a specific URI under the VIP. I altered the CodeShare JSESSIONID persitence example a bit to fit my scenario.


when HTTP_REQUEST {
  switch -glob $header_uri {
          /path1* {
          pool pool1
          }
          /path2* {
          pool pool2
          }
          /path3* {
          pool pool3
          }
          /path4* {
          set persist_jsessionid 1
            if {[HTTP::cookie "JSESSIONID"] ne ""}{
              persist uie [string tolower [HTTP::cookie "JSESSIONID"]] 3600
            }
          pool pool4
          }
  }
}

when HTTP_RESPONSE {
  if {$persist_jsessionid}{
    if {[HTTP::cookie "JSESSIONID"] ne ""} {
      persist add uie [string tolower [HTTP::cookie "JSESSIONID"]] 1800
    }
  }
}

what i am seeing is that EVERYTHING is persisting to the pool4 member rather than following the irule to send it to the appropriate pool. I have a oneconnect profile associated to the VIP and it has a 255.255.255.255 mask.

I set the persist_jsessionid variable trying to have it only persist for that specific URI but, same behavior. Any ideas?

Joe M

8 Replies

  • You should have a default condition as part of your switch statement too.

    default { pool x }

    As part of your "if JSESSIONID isn't null" statement, what do you want to happen if the cookie doesn't exist but the request was /path4*?
  • Chris,

     

     

    Thanks for your help. I do not have a default condition for this irule but, everything works fine if I comment out the HTTP_RESPONSE section. Well, except the persistence does not work of course. I am unclear how a default condition would affect the persistence??

     

     

    On the second question, note that the pool statement is OUTSIDE the nested "if", so traffic will go to pool4 if the uri is /path4 regardless of the existence of the JSESSIONID cookie.

     

     

    Joe M

     

  • Wasn't so much that the default condition would fix anything, it's just always good to have something there. Otherwise, if you don't have a default pool on the VIP, traffic has nowhere to go.

     

     

    I assumed that's where you wanted to go with the /pool4 stuff...just wanted to make sure. I haven't done too much with UIE so need to look at this for a bit.

     

     

  • Stefan - HTTP::uri wouldn't be usable from the response event....also, checking whether the cookie is null essentially checks whether it exists so you shouldn't need both.
  • So i took Stefan's sugestion to add the uri condition to the if statement int he rsponse event. So the iruel now looks like this:

    
    when HTTP_REQUEST {
      switch -glob $header_uri {
              /path1* {
              pool pool1
              }
              /path2* {
              pool pool2
              }
              /path3* {
              pool pool3
              }
              /path4* {
              set persist_jsessionid 1
                if {[HTTP::cookie "JSESSIONID"] ne ""}{
                  persist uie [string tolower [HTTP::cookie "JSESSIONID"]] 3600
                }
              pool pool4
              }
      }
    }
    
    when HTTP_RESPONSE {
      if {$persist_jsessionid}{
        if {[HTTP::cookie "JSESSIONID"] ne "" && $header_uri starts_with "/path4"} {
          persist add uie [string tolower [HTTP::cookie "JSESSIONID"]] 1800
        }
      }
    }
    
    Still no go. What i suspect is happening is that the requests for other paths are being sent to pool4 based on the persistence table rather than following the irule routing them to the appropriate pool. I have tried a oneconnect profile with all 0's with all 255's and with no oneconnect profile, thinking that was what was casuing it to follwo persistence table rather then reading the irule for each request. Still no workie. So why are the requests for other paths not getting sent to the right pools?

    Thanks,

    Joe Martin

  • I would add logging to the iRule for each switch case so you can track what exactly is happening. I believe the persist command will take effect for the duration of the TCP connection once it's called. So if you only want persistence for one specific URI, use 'persist none' before the switch statement. Then only if a match is found for /path4* will persistence be used.

     

     

    Aaron