For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

ingard's avatar
ingard
Icon for Nimbostratus rankNimbostratus
May 02, 2017

Reselect a specific backend based on initial response

Hi I'm trying to select a different backend and retry the same request based on the response from the initially selected backend. Basically the backend will either serve the request itself or respond with a 302 and put the host:port of another pool member (that has the content) in a header (X-TRANSCODE-REDIRECT-HOST). I put the following code together based on a few different examples I found on here, but it doesnt appear to work. At least the retry that I expected to happen never reaches the new pool member.

 

when CLIENT_ACCEPTED { 
    set retries 0
    set debug 5
}

when HTTP_REQUEST { 
  if { $retries == 0 } { 
    set request [HTTP::request]
  }
  if { $debug > 4 } { log local0. "HTTP_REQUEST - Retries : $retries - Request: $request" } 
}

when LB_SELECTED { 
  if { $retries == 0 } { 
     Log LB pool/server selection 
    if { $debug > 0 } { log local0. "Retries : $retries - Server Selected : [LB::server pool] [LB::server addr]:[LB::server port]" } 
  } else { 
     Reselect LB node if retries > 0
    if { $debug > 0 } { log local0. "Retries : $retries. wanted host/port = $wantedhost / $wantedport" }
    LB::reselect pool pool_media_transcoding $wantedhost $wantedport  

     Log LB pool/server selection 
    if { $debug > 0 } { log local0. "Retries : $retries - Server Selected : [LB::server pool] [LB::server addr]:[LB::server port]" } 
  } 
  if { $debug > 4 } { log local0. "LB_SELECTED - Retries : $retries - Request: $request" } 
} 

when HTTP_RESPONSE {
  if { [HTTP::status] eq 302 && $retries == 0 } {
    if {[HTTP::header X-TRANSCODE-REDIRECT-HOST] eq ""}{
      if { $debug > 0 } { log local0. "We got 302 from backend, but no X-TRANSCODE-REDIRECT-HOST header set" }
    } else {
      set wantedhost [lindex [split [HTTP::header X-TRANSCODE-REDIRECT-HOST] ":"] 0]
      set wantedport [lindex [split [HTTP::header X-TRANSCODE-REDIRECT-HOST] ":"] 1]
      if { $debug > 0 } { log local0. "We got 302 from backend. It wants us to redirect to $wantedhost : $wantedport" }
      incr retries
      HTTP::retry "$request" 
    }
  }
}

3 Replies

  • JG's avatar
    JG
    Icon for Cumulonimbus rankCumulonimbus

    The syntax does not seem to be right for this:

    LB::reselect pool pool_media_transcoding $wantedhost $wantedport
    

    . According to the manual, the syntax is:

    LB::reselect pool  member 

    . Perhaps you meant to use the following instead:

    LB::reselect node  

    .

  • ingard's avatar
    ingard
    Icon for Nimbostratus rankNimbostratus

    It works with the change suggested by Jie, but I'm now seeing that the rule logs running through LB_SELECTED twice:

    May  3 13:00:01 big-7 info tmm2[5109]: Rule /Common/irule_transcoder : HTTP_REQUEST - Retries : 0 - Request: GET /segment/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJtZDUiOiJlZWYyMjAyZjg2ZGNjMDM0MmZiMjQ4ODExMTlkZjRlYyIsInVzZXJuYW1lIjoiZmF6ZXJtaW50ODIifQ.rNIkeMsXJfjPh7dlr1XkmY5uhRKuWeEz-4AcjIxRZqo/SD/segment000.ts HTTP/1.1  Host: domain.com  User-Agent: curl/7.46.0  Accept: */*  X-Forwarded-For: 1.2.3.4  jx_scheme: https
    May  3 13:00:01 big-7 info tmm2[5109]: Rule /Common/irule_transcoder : when LB_SELECTED : Retries : 0 - Server Selected : /Common/pool_media_transcoding 10.0.70.110:8105
    May  3 13:00:01 big-7 info tmm2[5109]: Rule /Common/irule_transcoder : Retries : 0 - Server Selected : /Common/pool_media_transcoding 10.0.70.110:8105
    May  3 13:00:01 big-7 info tmm2[5109]: Rule /Common/irule_transcoder : 1.2.3.4:20343: Server IP:port: 10.0.70.110:8105
    May  3 13:00:01 big-7 info tmm2[5109]: Rule /Common/irule_transcoder : We got 302 from backend. It wants us to redirect to 10.0.70.110 : 8106
    May  3 13:00:01 big-7 info tmm2[5109]: Rule /Common/irule_transcoder : HTTP_REQUEST - Retries : 1 - Request: GET /segment/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJtZDUiOiJlZWYyMjAyZjg2ZGNjMDM0MmZiMjQ4ODExMTlkZjRlYyIsInVzZXJuYW1lIjoiZmF6ZXJtaW50ODIifQ.rNIkeMsXJfjPh7dlr1XkmY5uhRKuWeEz-4AcjIxRZqo/SD/segment000.ts HTTP/1.1  Host: domain.com  User-Agent: curl/7.46.0  Accept: */*  X-Forwarded-For: 1.2.3.4  jx_scheme: https
    May  3 13:00:01 big-7 info tmm2[5109]: Rule /Common/irule_transcoder : when LB_SELECTED : Retries : 1 - Server Selected : /Common/pool_media_transcoding 10.0.70.110:8105
    May  3 13:00:01 big-7 info tmm2[5109]: Rule /Common/irule_transcoder : Retries : 1. wanted host/port = 10.0.70.110:8106
    May  3 13:00:01 big-7 info tmm2[5109]: Rule /Common/irule_transcoder : Retries : 1 - Server Selected :  10.0.70.110:8106
    May  3 13:00:01 big-7 info tmm2[5109]: Rule /Common/irule_transcoder : when LB_SELECTED : Retries : 1 - Server Selected :  10.0.70.110:8106
    May  3 13:00:01 big-7 info tmm2[5109]: Rule /Common/irule_transcoder : Retries : 1. wanted host/port = 10.0.70.110:8106
    May  3 13:00:01 big-7 info tmm2[5109]: Rule /Common/irule_transcoder : Retries : 1 - Server Selected :  10.0.70.110:8106
    May  3 13:00:01 big-7 info tmm2[5109]: Rule /Common/irule_transcoder : 1.2.3.4:20343: Server IP:port: 10.0.70.110:8106
    
  • JG's avatar
    JG
    Icon for Cumulonimbus rankCumulonimbus

    OK see two modified events:

    when CLIENT_ACCEPTED {
        set retries 0
        set re-selected 0
        set debug 5
    }
    
    when LB_SELECTED {
        if { $re-selected == 1 } {
            set re-selected 0
            return;
        }
    
        if { $retries == 0 } {
             Log LB pool/server selection
            if { $debug > 0 } { log local0. "Retries : $retries - Server Selected : [LB::server pool] [LB::server addr]:[LB::server port]" }
        } else {
             Reselect LB node if retries > 0
            if { $debug > 0 } { log local0. "Retries : $retries. wanted host/port = $wantedhost / $wantedport" }
            set re-selected 1
            LB::reselect pool pool_media_transcoding $wantedhost $wantedport
    
             Log LB pool/server selection
            if { $debug > 0 } { log local0. "Retries : $retries - Server Selected : [LB::server pool] [LB::server addr]:[LB::server port]" }
        }
        if { $debug > 4 } { log local0. "LB_SELECTED - Retries : $retries - Request: $request" }
    }