Search in sources :

Example 11 with RequestTrace

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);
    }
}
Also used : ArrayList(java.util.ArrayList) RequestTrace(fish.payara.notification.requesttracing.RequestTrace) Test(org.junit.Test)

Example 12 with RequestTrace

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;
}
Also used : Instant(java.time.Instant) RequestTraceSpan(fish.payara.notification.requesttracing.RequestTraceSpan) RequestTrace(fish.payara.notification.requesttracing.RequestTrace)

Example 13 with RequestTrace

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);
    }
}
Also used : RequestTrace(fish.payara.notification.requesttracing.RequestTrace) Before(org.junit.Before)

Example 14 with RequestTrace

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);
}
Also used : TraceStorageStrategy(fish.payara.nucleus.requesttracing.store.strategy.TraceStorageStrategy) ReservoirTraceStorageStrategy(fish.payara.nucleus.requesttracing.store.strategy.ReservoirTraceStorageStrategy) LongestTraceStorageStrategy(fish.payara.nucleus.requesttracing.store.strategy.LongestTraceStorageStrategy) ClusteredStore(fish.payara.nucleus.store.ClusteredStore) LongestTraceStorageStrategy(fish.payara.nucleus.requesttracing.store.strategy.LongestTraceStorageStrategy) RequestTrace(fish.payara.notification.requesttracing.RequestTrace) ReservoirTraceStorageStrategy(fish.payara.nucleus.requesttracing.store.strategy.ReservoirTraceStorageStrategy) UUID(java.util.UUID) Map(java.util.Map)

Example 15 with RequestTrace

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;
}
Also used : RequestTrace(fish.payara.notification.requesttracing.RequestTrace)

Aggregations

RequestTrace (fish.payara.notification.requesttracing.RequestTrace)25 Test (org.junit.Test)7 RequestTraceSpan (fish.payara.notification.requesttracing.RequestTraceSpan)6 ArrayList (java.util.ArrayList)4 ClusterMessage (fish.payara.nucleus.eventbus.ClusterMessage)2 LongestTraceStorageStrategy (fish.payara.nucleus.requesttracing.store.strategy.LongestTraceStorageStrategy)2 ReservoirTraceStorageStrategy (fish.payara.nucleus.requesttracing.store.strategy.ReservoirTraceStorageStrategy)2 TraceStorageStrategy (fish.payara.nucleus.requesttracing.store.strategy.TraceStorageStrategy)2 ClusteredStore (fish.payara.nucleus.store.ClusteredStore)2 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 Instant (java.time.Instant)2 UUID (java.util.UUID)2 MultiMap (com.hazelcast.core.MultiMap)1 ColumnFormatter (com.sun.enterprise.util.ColumnFormatter)1 PayaraNotification (fish.payara.internal.notification.PayaraNotification)1 GroupData (fish.payara.monitoring.adapt.GroupData)1 MonitoringData (fish.payara.monitoring.collect.MonitoringData)1 RequestTracingNotificationData (fish.payara.notification.requesttracing.RequestTracingNotificationData)1 LogNotifierExecutionOptions (fish.payara.nucleus.notification.log.LogNotifierExecutionOptions)1 RequestTracingExecutionOptions (fish.payara.nucleus.requesttracing.domain.execoptions.RequestTracingExecutionOptions)1