Assertion Latency

The following built-in context variables record the latency:
gateway83
CA API Gateway
can calculate the latency for most assertions in a policy. This latency information may be useful in helping to troubleshoot issues, for example connection issues with the back-end service.
The following built-in context variables record the latency:
  • ${assertion.latency.ms}:
    Stores the assertion latency in milliseconds.
  • ${assertion.latency.ns}:
    Stores the assertion latency in nanoseconds.
Note the following important information about assertion latency:
  • To reduce the system overhead,
    API Gateway
     calculates the latency only when required. You indicate that the latency is required by referencing either the
    ${assertion.latency.ms}
    or $
    {assertion.latency.ns
    } variables in the next assertion.
  • Calculating assertion latency may affect the outcome of the
    At least one assertion must evaluate to true
     composite assertion. Reason: The Add Audit Detail Assertion (required to trigger the capture of assertion latency values) always returns "true." This may affect the outcome of the composite assertion (for example, prior to calculating the latency, the composite assertion could have returned "false"; after calculating the latency, the composite assertion will always return "true"). To avoid this, restructure the policy logic.
  • It is not possible to determine assertion latency for child assertions within the Run All Assertions Concurrently Assertion.
    If the child assertion is one of the "At least one..." or "All assertions..." composite assertions, then its children are eligible for latency calculation.
How to Use the Assertion Latency Variables
The two latency variables are overwritten each time latency is calculated. To preserve the latency values, you can use either of the following strategies:
  • Log the message
  • Save the variable for later use
These are described in more detail below, using the
${assertion.latency.ms}
as an example.
Logging the Message
To log the assertion latency, you can use the Add Audit Detail assertion with the
${assertion.latency.ms}
variable defined in the message body—see the following policy sample :
Latency_Log_Example.png
In this example, the output log contains the assertion latency for the Run All Assertions Concurrently Assertion:
2012-04-26T11:37:38.349-0700 INFO 159com.l7tech.server.policy.assertion.ServerAuditDetailAssertion: -4: LatencyTrace:"Run All Assertion Concurrently": 16
Save the Variable for Later Use
To save the assertion latency, use the Set Context Variable assertion to copy the
${assertion.latency.ms}
value to another variable:
Latency_Save_Example.png
In this example, the
${jdbclatency}
variable contains the latency for the Perform JDBC Query assertion in line 3, while the
${httproutelatency}
variable contains the latency for the Route via HTTP(S) assertion in line 5.
When the Assertion Latency Is Calculated
Consider the following example policy:
Latency_Example.png
In the sample above:
  • Latency is calculated for Perform JDBC Query in line 3, because Set Context Variable is used in line 4 to capture the value from
    ${assertion.latency.ms}.
  • Latency is calculated for Route via HTTP in line 5, because Set Context Variable is used in line 6 to capture the value from
    ${assertion.latency.ms}
    .
  • Latency is calculated for the Run All Assertions Concurrently composite assertion in line 7, because the Add Audit Details assertion is used in line 15 to capture the value from
    ${assertion.latency.ms}
    . (Note that line 15 is used because that is the first line after the composite assertion.)
  • Latency will be calculated for Perform JDBC Query in line 12, because Set Context Variable is used in line 13 to capture the value from
    ${assertion.latency.ms}
    . Note that line 12 is eligible for assertion latency capture because it is the child of the "All assertions..." composite assertion in line 11 and is not affected by the disabling of latency capture from the parent Run All Assertions Concurrently assertion in line 7.
It is equally important to understand when latency is
not
calculated:
  • Latency is not calculated for lines 2, 4, 6, 8, 11, 13, 15, 16 because neither the
    ${assertion.latency.ms}
    nor
    ${assertion.latency.ns}
    variables are referenced in the next assertion.
  • In line 9, the latency is not calculated even though
    ${assertion.latency.ms}
    is used in line 10 because the Set Context Variable assertion appears under the Run All Assertions Concurrently assertion (which disables the capture of assertion latency).
  • In line 14, the latency is not calculated because this line is the last child in the composite assertion (line 7) and the Add Audit Details assertion in line 15 is considered the next assertion for line 7, not line 14.