Get Target Host details when using TargetServer configured

Not applicable

I have configured TargetServer and referring it in Target Endpoint as follows :

    <HTTPTargetConnection>
        <LoadBalancer>
            <Server name="restService"/>
        </LoadBalancer>
        <Path>/v1/product</Path>
    </HTTPTargetConnection>

Is there a way to get the Target Host configured in a flow variable ? Tried using target.host & target.url but they are not getting populated. Only target.basepath seems to be getting populated which doesn't have target host in it.

3 11 3,561
11 REPLIES 11

Hi Swapnil,

target.url gives you the complete request URL send to to target endpoint and its scope is target request. SO you can populate its value in and after target request flow. Similarly, target.host hives you target host value and its scope is target response. So you can use it in and after target response flow.

Hope this helps.

I am trying to fetch the target.url variable in JS policy attached at Target Request flow. I am using TargetServer configuration under LoadBalancer and not <URL> under <HTTPTargetConnection>

@Swapnil Raverkar , See answer below, Hope it clarifies same.

Not applicable

I need to do this as well, has anyone got an answer?

Ok, I think that I'm beginning to see why this can't be done... assuming that the load balancing decision is made outside of the flow process, there would be no way to know in advance which host would be picked. There are "loadbalancing" variables that we can read, but these are only in scope after the target server has responded. Can anyone confirm this, or point me towards architectural discussion for load balancing?

@stewartritchie , You can retrieve same in target response pipeline, but not in request pipeline. Where exactly you would like to retrieve same ?

Below javascript in target response works fine & i can able to retrieve both target server name & hostname,

 print(context.getVariable("loadbalancing.targetserver"))
 print(context.getVariable("target.host"))

@stewartritchie , Yes, You are right. Load balancing decision is made by the MP just before it initiates the call to the backend. That's the reason these variables are not available in target request pipeline. Let's say, if some logic like serving the request from cache in target request or a conditional step which raises fault on target request and terminates the request then ideally it doesn't make sense to do this computation of selecting the target server before target request policies execute.

And also, For example, Let's say you have selected round robin, First request target1 has been selected. For some reason, there is a fault in policy & request has been terminated in target request. If target servers are selected before policy execution then next pick will be target2 even though you haven't hit the target server. That's the reason MP executes the load balancing logic just before it hits the target after the target request pipeline has been processed. Same reason why these variables are not available in target request.

Hope it helps.

Good answer, very clear!

Thank you @Dino . Glad it's helpful.

Thank You @Anil Sagar @ Google for your clarification,

however I noticed that the target_url is not populated in the analytics database which is supposed to be executed after the respond already send back to the client ( in the PostClientfFow).

Best Regards

Not applicable

What if we have targetServer Configuration in Service Callout and need to fetch targetServer name in request pipeline. Can we do so.