Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Route rule condition based on kvm flag

@dchiesa1/Team, i am trying to add a condition under route rule wherein I am routing it to a target if the kvm flag value is enable. Can i put the below condition

<Condition>(private.kvm_ref.value==“enable”)</condition>

if not what is the correct way of mentioning

Thanks!

3 4 266
4 REPLIES 4

YES but

  1. You didn't provide all the context around the RouteRule. Can you show the full RouteRule element and all children?
  2. Your fragment has incorrect casing . You cannot close a <Condition> with </condition>. The latter must be capitalized .

That was a typing error.

1 of 100 requests to the proxy endpoint has to be routed to target 2 if kvm value is enable

kvm value is “Enable”

<RoutRule name=“Target2”>
 <TargetEndpoint>Target2</TargetEndpoint>
<Condition>(private.kvm_ref.value==“enable”)</Condition>

so wanted to check if i can do this.

@dchiesa1 Let me know if any other information is needed for this.

1 of 100 requests to the proxy endpoint has to be routed to target 2 if kvm value is enable

Under some condition, you want to route 99 of 100 requests to target1, and 1 of 100 inbound requests to target2. 

The way I would do this:

  • Use KVM Get policy to retrieve the setting from the KVM
  • Use a JS policy that computes a number, randomly distributed between 1-100 (inclusive)
  • In your RouteRule, examine the number and route accordingly

the RouteRule logic would be like this: 

<RouteRule name="conditional-route">
  <Condition>kvm_retrieved_value != null AND route_sample = 100</Condition>
  <TargetEndpoint>target2</TargetEndpoint> 
</RouteRule> 

<RouteRule name='default'>
  <TargetEndpoint>target1</TargetEndpoint> 
</RouteRule>

And the JS to compute the route_sample number is: 

<JavaScript name='JS-Compute-Route-Metric'>
  <Source>
function getRandomNumber(min, max) {
  return Math.floor(Math.random() * (max - min + 1)) + min;
}
var randomNumber = getRandomNumber(1, 100);
context.setVariable('route_sample', randomNumber);
  </Source>
</JavaScript>

And of course if you wanted to change the weighting on the routes, you could modify the condition to reference the kvm_retrieved_value. 

<RouteRule name="conditional-route">
  <Condition>kvm_retrieved_value != null AND route_sample > kvm_retrieved_value</Condition>
  <TargetEndpoint>target2</TargetEndpoint> 
</RouteRule> 

<RouteRule name='default'>
  <TargetEndpoint>target1</TargetEndpoint> 
</RouteRule>