Search in sources :

Example 6 with TimingKey

use of com.linkedin.r2.message.timing.TimingKey in project rest.li by linkedin.

the class TestLatencyInstrumentation method checkTimingKeyConsistency.

/**
 * Ensures that the set of recorded timing keys is "consistent", meaning that for any code path (denoted by key "A")
 * which is a subset of another code path (denoted by key "B"), the duration of key A must be less than that of key B.
 */
private void checkTimingKeyConsistency() {
    ArrayList<Map.Entry<TimingKey, TimingContextUtil.TimingContext>> entrySet = new ArrayList<>(_resultMap.entrySet());
    int size = entrySet.size();
    // (e.g. duration of "fwk/server/response" > duration of "fwk/server/response/restli")
    for (int i = 0; i < size; i++) {
        TimingKey keyA = entrySet.get(i).getKey();
        if (!keyA.getName().contains(FrameworkTimingKeys.KEY_PREFIX)) {
            continue;
        }
        for (int j = 0; j < size; j++) {
            TimingKey keyB = entrySet.get(j).getKey();
            if (i == j || !keyB.getName().contains(FrameworkTimingKeys.KEY_PREFIX)) {
                continue;
            }
            if (keyA.getName().contains(keyB.getName())) {
                TimingContextUtil.TimingContext contextA = entrySet.get(i).getValue();
                TimingContextUtil.TimingContext contextB = entrySet.get(j).getValue();
                String message = String.format("Expected %s (%.2fms) < %s (%.2fms)", keyA, contextA.getDurationNano() * NANOS_TO_MILLIS, keyB, contextB.getDurationNano() * NANOS_TO_MILLIS);
                Assert.assertTrue(contextA.getDurationNano() < contextB.getDurationNano(), message);
            }
        }
    }
}
Also used : TimingContextUtil(com.linkedin.r2.message.timing.TimingContextUtil) TimingKey(com.linkedin.r2.message.timing.TimingKey) ArrayList(java.util.ArrayList)

Aggregations

RequestContext (com.linkedin.r2.message.RequestContext)5 TimingKey (com.linkedin.r2.message.timing.TimingKey)4 Test (org.testng.annotations.Test)4 Callback (com.linkedin.common.callback.Callback)2 RemoteInvocationException (com.linkedin.r2.RemoteInvocationException)2 TimingContextUtil (com.linkedin.r2.message.timing.TimingContextUtil)2 InstrumentationControl (com.linkedin.restli.examples.instrumentation.api.InstrumentationControl)2 LatencyInstrumentationBuilders (com.linkedin.restli.examples.instrumentation.client.LatencyInstrumentationBuilders)2 RestLiServiceException (com.linkedin.restli.server.RestLiServiceException)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 FutureCallback (com.linkedin.common.callback.FutureCallback)1 FilterChain (com.linkedin.r2.filter.FilterChain)1 FilterChains (com.linkedin.r2.filter.FilterChains)1 NextFilter (com.linkedin.r2.filter.NextFilter)1 RestFilter (com.linkedin.r2.filter.message.rest.RestFilter)1 StreamFilter (com.linkedin.r2.filter.message.stream.StreamFilter)1 Request (com.linkedin.r2.message.Request)1 Response (com.linkedin.r2.message.Response)1 RestRequest (com.linkedin.r2.message.rest.RestRequest)1