use of fish.payara.notification.requesttracing.RequestTrace in project Payara by payara.
the class AbstractStorageStrategyTest method noTracesAreRemovedBelowMaxSize.
@Test
public void noTracesAreRemovedBelowMaxSize() {
int maxSize = 10;
List<RequestTrace> traces = new ArrayList<>();
for (int i = 0; i < maxSize; i++) {
traces.add(createTrace());
assertNull(strategy.getTraceForRemoval(traces, maxSize, null));
for (int j = 0; j < traces.size(); j++) {
RequestTrace traceToRemove = traces.get(j);
assertNull(strategy.getTraceForRemoval(traces, maxSize, traceToRemove));
}
assertTrue(traces.size() <= maxSize);
}
}
use of fish.payara.notification.requesttracing.RequestTrace in project Payara by payara.
the class AbstractStorageStrategyTest method createTrace.
protected static RequestTrace createTrace(long durationNanos) {
RequestTrace trace = new RequestTrace();
RequestTraceSpan span = new RequestTraceSpan(EventType.TRACE_START, "op1");
Instant start = Instant.now().minusNanos(durationNanos);
span.setStartInstant(start);
trace.addEvent(span);
trace.endTrace();
return trace;
}
use of fish.payara.notification.requesttracing.RequestTrace in project Payara by payara.
the class ReservoirTraceStorageStrategyTest method populateTraces.
@Before
public void populateTraces() {
traces = new ArrayList<>();
for (int i = 0; i < 10; i++) {
RequestTrace trace = createTrace();
trace.getTraceSpans().getFirst().setEventName(String.valueOf(i));
traces.add(trace);
}
}
use of fish.payara.notification.requesttracing.RequestTrace in project Payara by payara.
the class RequestTraceStoreFactory method getStore.
/**
* Generates a request trace store.
*
* @param reservoirSamplingEnabled whether the store should remove items
* based on a reservoir sampling algorithm.
* @param historic whether the store is a historic store or not.
* @return a request trace store.
*/
public static RequestTraceStoreInterface getStore(boolean reservoirSamplingEnabled, boolean historic) {
// Get the hazelcast store name for if it's a clustered store.
String storeName;
if (historic) {
storeName = HISTORIC_REQUEST_TRACE_STORE;
} else {
storeName = REQUEST_TRACE_STORE;
}
// Determines a strategy for adding items to the store
TraceStorageStrategy strategy;
if (reservoirSamplingEnabled) {
strategy = new ReservoirTraceStorageStrategy();
} else {
strategy = new LongestTraceStorageStrategy();
}
// Get a clustered store if possible
ClusteredStore clusteredStore = null;
ServiceHandle<ClusteredStore> serviceHandle = Globals.getDefaultHabitat().getServiceHandle(ClusteredStore.class);
if (serviceHandle != null && serviceHandle.isActive()) {
clusteredStore = serviceHandle.getService();
}
if (clusteredStore != null && clusteredStore.isEnabled()) {
Map<UUID, RequestTrace> store = (Map) clusteredStore.getMap(storeName);
return new ClusteredRequestTraceStore(store, strategy);
}
// Otherwise get a local store
return new LocalRequestTraceStore(strategy);
}
use of fish.payara.notification.requesttracing.RequestTrace in project Payara by payara.
the class LongestTraceStorageStrategy method findShortestTrace.
private static RequestTrace findShortestTrace(Collection<RequestTrace> traces) {
Iterator<RequestTrace> iter = traces.iterator();
RequestTrace shortest = iter.next();
while (iter.hasNext()) {
RequestTrace next = iter.next();
if (next.getElapsedTime() < shortest.getElapsedTime() || next.getElapsedTime() == shortest.getElapsedTime() && next.getStartTime().isBefore(shortest.getStartTime())) {
shortest = next;
}
}
return shortest;
}
Aggregations