Search in sources :

Example 1 with RequestTrace

use of fish.payara.notification.requesttracing.RequestTrace in project Payara by payara.

the class RequestTracingService method endTrace.

/**
 */
public void endTrace() {
    if (!isRequestTracingEnabled() || !isTraceInProgress()) {
        return;
    }
    requestEventStore.endTrace();
    Long thresholdValueInNanos = getThresholdValueInNanos();
    long elapsedTime = requestEventStore.getElapsedTime();
    long elapsedTimeInNanos = TimeUnit.NANOSECONDS.convert(elapsedTime, TimeUnit.MILLISECONDS);
    if (elapsedTimeInNanos - thresholdValueInNanos > 0) {
        // Determine whether to sample the request, if sampleRateFirstEnabled is false
        if (!executionOptions.getSampleRateFirstEnabled()) {
            if (!sampleFilter.sample()) {
                requestEventStore.flushStore();
                return;
            }
        }
        RequestTrace requestTrace = requestEventStore.getTrace();
        Runnable addTask = () -> {
            RequestTrace removedTrace = requestTraceStore.addTrace(requestTrace);
            // Store the trace in the historic trace store if it's enabled, avoiding recalculation
            if (executionOptions.isHistoricTraceStoreEnabled()) {
                historicRequestTraceStore.addTrace(requestTrace, removedTrace);
            }
            if (removedTrace != null) {
                if (hazelcast.isEnabled()) {
                    eventBus.publish(EVENT_BUS_LISTENER_NAME, new ClusterMessage(RequestTracingEvents.STORE_FULL.toString()));
                } else {
                    events.send(new EventListener.Event(RequestTracingEvents.STORE_FULL));
                }
            }
        };
        payaraExecutorService.submit(addTask);
        for (NotifierExecutionOptions notifierExecutionOptions : executionOptions.getNotifierExecutionOptionsList().values()) {
            if (notifierExecutionOptions.isEnabled()) {
                NotificationEventFactory notificationEventFactory = eventFactoryStore.get(notifierExecutionOptions.getNotifierType());
                String subject = "Request execution time: " + elapsedTime + "(ms) exceeded the acceptable threshold";
                NotificationEvent notificationEvent = notificationEventFactory.buildNotificationEvent(subject, requestTrace);
                notificationService.notify(EventSource.REQUESTTRACING, notificationEvent);
            }
        }
    }
    requestEventStore.flushStore();
}
Also used : LogNotifierExecutionOptions(fish.payara.nucleus.notification.log.LogNotifierExecutionOptions) PropertyChangeEvent(java.beans.PropertyChangeEvent) RequestTrace(fish.payara.notification.requesttracing.RequestTrace) ClusterMessage(fish.payara.nucleus.eventbus.ClusterMessage)

Example 2 with RequestTrace

use of fish.payara.notification.requesttracing.RequestTrace in project Payara by payara.

the class ClusteredRequestTraceStore method addTrace.

@Override
public RequestTrace addTrace(RequestTrace trace) {
    store.put(instanceId, trace);
    RequestTrace traceToRemove = strategy.getTraceForRemoval(getTraces(), maxStoreSize);
    if (traceToRemove == null) {
        return null;
    }
    store.remove(traceToRemove);
    return traceToRemove;
}
Also used : RequestTrace(fish.payara.notification.requesttracing.RequestTrace)

Example 3 with RequestTrace

use of fish.payara.notification.requesttracing.RequestTrace in project Payara by payara.

the class LocalRequestTraceStore method addTrace.

@Override
public RequestTrace addTrace(RequestTrace trace) {
    store.add(trace);
    RequestTrace traceToRemove = strategy.getTraceForRemoval(getTraces(), maxStoreSize);
    if (traceToRemove == null) {
        return null;
    }
    store.remove(traceToRemove);
    return traceToRemove;
}
Also used : RequestTrace(fish.payara.notification.requesttracing.RequestTrace)

Example 4 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(Events events, 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 = Globals.getDefaultHabitat().getService(ClusteredStore.class);
    if (clusteredStore != null && clusteredStore.isEnabled()) {
        MultiMap<String, RequestTrace> store = (MultiMap) clusteredStore.getMultiMap(storeName);
        return new ClusteredRequestTraceStore(store, clusteredStore.getInstanceId(), strategy);
    }
    // Otherwise get a local store
    return new LocalRequestTraceStore(strategy);
}
Also used : MultiMap(com.hazelcast.core.MultiMap) 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)

Example 5 with RequestTrace

use of fish.payara.notification.requesttracing.RequestTrace in project Payara by payara.

the class RequestTraceTest method testGetElapsedTimeInitial.

/**
 * Test of getElapsedTime method, of class RequestTrace.
 */
@Test
public void testGetElapsedTimeInitial() {
    trace = new RequestTrace();
    assertEquals(0, trace.getElapsedTime());
}
Also used : RequestTrace(fish.payara.notification.requesttracing.RequestTrace) Test(org.junit.Test)

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