Adding persistance profiles to pools using Irules

I have 2 persistance profiles that I need to apply

to individual pools namely jupiter_60mins and earth_30mins.

Since I cannot apply the persistance profiles at the pool level

How do I re-write this irule below to incorporate these profiles to the pools ?

Sample :

if { [HTTP::host] starts_with “nexus”} {

if {$uri starts_with “/jupiter/”} {

pool robocop-1

}

elseif {$uri starts_with “/earth/”} {

pool robocop-2

}

}

Assuming you set $uri elsewhere, try:

when HTTP_REQUEST {
  if {[HTTP::host] starts_with "nexus"} {
    if {$uri starts_with "/jupiter/"} {
      PROFILE::persist timeout 3600
      pool robocop-1
    }
    elseif {$uri starts_with "/earth/"} {
      PROFILE::persist timeout 1800
      pool robocop-2
    }
  }
}

Please note, I couldn’t find any docs for this, so this may not work.

Cheers,

Brian

I’m trying to do a similar function, I want to apply persistance to one pool and not the other. This rule is accepted for proper syntax but it did not work in inital testing. I still need to dig into it. I’m not sure if this is actually a valid rule.

when HTTP_REQUEST {

if { [matchclass [HTTP::uri] starts_with $::static_content] }{

use pool content

} else {persist cookie passive

use pool proxy

}

}

Add logging statements to make sure you are getting the results you anticipate. Try findclass instead of matchclass since you are using the starts_with operand

Thanks for the input. After testing today, things are not quite working right. Every other connection attempt to the VIP using that rule causes the server in the proxy pool to generate an error (I have each pool down to using a single server). For those requests that are failing the BIG-IP is generating these error messages.

http_process_state_prepend - Invalid action EV_INGRESS_DATA during ST_HTTP_PREPEND_HEADERS

Some other threads on the board seem to indicate these errors are caused by the http profile, specifically header inserting and not the rule.

For the 50% of initial requests that work, everything works fine after that for that session.

I’ll be opening a ticket in the morning.

Also, don’t forget you can also use “persist none” to disable persist to a particular pool (assuming you have the persistence configured with a profile on the virtual).

Hi,

can i use “persist none” command in content switch irule for disable persistence when i use another irule for jsessionid persistence (i don’t use persistence profile)

Yes, if you include a conditional on when you want to persist and when you don’t, this should work fine. You can see an example here: Weblogic Persistence done right ;=) - Community CodeShare - DevCentral - An F5 Technical Community

Hi Jason,

here is the our rules, app team tested and they say still persisted and “persist none” didn’t work.

i opened case and support does not help us.

Switch_irule

when HTTP_REQUEST {

log local0. “[IP::client_addr]:[TCP::client_port]: [HTTP::method] request to [HTTP::host][HTTP::uri]”

switch -glob [HTTP::uri] {

“/uat/JAVA*” {

pool Persist_Test_Pool_1

HTTP::uri [string map -nocase {“/uat/JAVA” “/JAVA”} [HTTP::uri]]

log local0. “[IP::client_addr]:[TCP::client_port]: matched [HTTP::uri]. Pool: [LB::server]”

}

"/uat/abc/*” {

pool Persist_Test_Pool_2

persist none

HTTP::uri [string map -nocase {"/uat/abc/“ “/test/“} [HTTP::uri]]

log local0. “[IP::client_addr]:[TCP::client_port]: matched [HTTP::uri]. Pool: [LB::server]”

}

“default” {

log local0. “[IP::client_addr]:[TCP::client_port]: matched [HTTP::uri]. Pool: [LB::server]”

log local0. “No match”

}

}

}

Jsessionid_rule

when HTTP_REQUEST {

# Log details for the request

set log_prefix “[IP::client_addr]:[TCP::client_port]”

log local0. “$log_prefix: Request to [HTTP::uri] with cookie: [HTTP::cookie value JSESSIONID]”

# only header cookie control

if { [HTTP::header exists “Cookie”] } {

set jsess [findstr [string tolower [HTTP::header “Cookie”]] “jsessionid=” “11” “.” ]

if { $jsess != “” } {

persist uie $jsess 3600

log local0. “$log_prefix: Used persistence record from path: [persist lookup uie $jsess] $jsess”

}

}

}

when HTTP_RESPONSE {

if { [HTTP::header exists “Set-Cookie”] } {

set jsess [findstr [string tolower [HTTP::header “Set-Cookie”]] “jsessionid=” “11” “.” ]

if { $jsess != “” } {

persist add uie $jsess 3600

log local0. “$log_prefix: Added persistence record from cookie: [persist lookup uie $jsess] $jsess”

}

}

}

order will be important since your irules are separate. You will either want to combine your rules into one and make sure your logic is correctly ordered, or you need to set the order in the GUI or set a priority on each irule to make sure your switch rule comes after your persistence rule.

Given how simple both rules are, however, I highly recommend combining them reduce complexity.