Craig_Serritell
Sep 10, 2010Nimbostratus
Pool member preference based on header
Has anybody had any experience with reading a http header and directing to a specific pool member based on some data in the header?
In the example below, I'm reading a http header called "NodePre" (node preference) and trying to send to a pool member. The NodePre will be an IP:port combination X.X.X.X:YYY.
Eventually, I'd like to set some connection limits in the iRule and not honor the preference if there are already X connections to the pool member. But, I gotta get this working first.
when LB_SELECTED {
set nodeport [LB::server port]
if {[HTTP::header exists "NodePre"]} {
set preference [string tolower [HTTP::header "NodePre"]]
set preference_array [split $preference ":"]
set Pool_IP "[lindex $preference_array 0]"
set Pool_Port "[lindex $preference_array 1]"
log local0. "Client has a Node Preference of $preference. We parsed as $Pool_IP:$Pool_Port. Nodeport is $nodeport"
if { [IP::addr [LB::server addr] equals $Pool_IP] and [$nodeport == $Pool_Port] } {
log local0. "Client wanted $Pool_IP:$Pool_Port. We were already load balanced to [LB::server addr]:$nodeport. No further action needed"
} else {
log local0. "Client wanted $Pool_IP:$Pool_Port. We were already load balanced to [LB::server addr]:$nodeport. Do something about it."
node $Pool_IP $Pool_Port
log local0. "Client wanted $Pool_IP:$Pool_Port. We were already load balanced to [LB::server addr]:$nodeport. We sent client to $Pool_IP $Pool_Port"
}
}
}
In my logs, I see this:
Client has a Node Preference of 10.1.150.171:28080. We parsed as 10.1.150.171:28080
Client wanted 10.1.150.171:28080. We were already load balanced to 10.1.150.174:28082. Do something about it.
Client wanted 10.1.150.171:28080. We were already load balanced to 10.1.150.174:28082. We sent client to 10.1.150.1 71 28080
Client has a Node Preference of 10.1.150.171:28080. We parsed as 10.1.150.171:28080
TCL error: invalid command name "28080" while executing "$nodeport equals $Pool_Port"