Forum Discussion

Craig_Serritell's avatar
Craig_Serritell
Icon for Nimbostratus rankNimbostratus
Sep 10, 2010

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"

4 Replies

  • Seems like your log statement is stopping after the "." Why don't we see "Nodeport is $nodeport" in the logs?

     

     

    I've done something similar to this but am using a cookie instead of header.

     

     

    Can you give us a breakdown of your pool setup?
  • I think I accidentally cut that part out while removing superfluous log file entries: Client has a Node Preference of 10.1.150.171:28080. We parsed as 10.1.150.171:28080. Nodeport is 28080 Client wanted 10.1.150.171:28080. We were already load balanced to 10.1.150.186:28080. Do something about it. Client wanted 10.1.150.171:28080. We were already load balanced to 10.1.150.186:28080. We sent client to 10.1.150.171 28080 Client has a Node Preference of 10.1.150.171:28080. We parsed as 10.1.150.171:28080. Nodeport is 28080 TCL error: - invalid command name "28080" while executing "$nodeport == $Pool_Port" The pool is set up with 12 members. The load balancing method is "least connections (member)." There's no ratio or priority group set up. The health check is a simple tcp health check.
  • Hi Craig, Matt here. Here's some sample code that logs what you want correctly. Note that I'm using HTTP_REQUEST, since I'm not sure that it matters if you've already got a pool member selected. It may matter, I just don't know.

     

    
    when HTTP_REQUEST {
    
    if { [HTTP::header exists "NodePre"] }{
    
      set preference_array [split [string tolower [HTTP::header "NodePre"]] ":"]
          set Pool_IP [lindex $preference_array 0]
          set Pool_Port [lindex $preference_array 1]
    
      log local0. "IP is: $Pool_IP"
      log local0. "Port is: $Pool_Port"  
      log local0. "Sending to: $Pool_IP:$Pool_Port"  
      node $Pool_IP $Pool_Port
    
             The entry below is just for my dummy tests.
    HTTP::respond 200 content 'hello'
    }
    }
    

     

    Please post back or contact me if you think this is off base.

     

    -Matt