Search in sources :

Example 1 with AfterOperationFailedEvent

use of kieker.common.record.flow.trace.operation.AfterOperationFailedEvent in project iobserve-analysis by research-iobserve.

the class SessionAndTraceRegistrationFilter method doFilter.

/**
 * Register thread-local session and trace information, executes the given {@link FilterChain}
 * and unregisters the session/trace information. If configured, the execution of this filter is
 * also logged to the {@link IMonitoringController}. This method returns immediately if
 * monitoring is not enabled.
 *
 * @param request
 *            The request.
 * @param response
 *            The response.
 * @param chain
 *            The filter chain to be used.
 *
 * @throws IOException
 *             on io errors
 * @throws ServletException
 *             on servlet errors
 */
@Override
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
    if (SessionAndTraceRegistrationFilter.CTRLINST.isMonitoringEnabled()) {
        // if (CTRLINST.isProbeActivated(this.filterOperationSignatureString)) {
        final String operationSignature;
        final String componentSignature;
        final String method;
        final String path;
        final String sessionId;
        String query;
        if (request instanceof HttpServletRequest) {
            final HttpServletRequest httpRequest = (HttpServletRequest) request;
            method = httpRequest.getMethod();
            path = httpRequest.getRequestURI().replace('/', '.').substring(1);
            sessionId = httpRequest.getSession().getId();
            query = httpRequest.getQueryString();
            if (query == null) {
                query = "";
            }
        } else {
            method = "POST";
            path = request.getServletContext().getContextPath().replace('/', '.').substring(1);
            sessionId = "<no session>";
            query = "";
        }
        componentSignature = path.replaceAll("\\.[A-Za-z0-9]*$", "");
        TraceMetadata trace = SessionAndTraceRegistrationFilter.TRACEREGISTRY.getTrace();
        final boolean newTrace = trace == null;
        if (newTrace) {
            SessionRegistry.INSTANCE.storeThreadLocalSessionId(sessionId);
            trace = SessionAndTraceRegistrationFilter.TRACEREGISTRY.registerTrace();
            SessionAndTraceRegistrationFilter.CTRLINST.newMonitoringRecord(trace);
        }
        if ("GET".equals(method)) {
            operationSignature = path + "(" + query.replace(';', ':') + ")";
        } else if ("POST".equals(method)) {
            operationSignature = path + "()";
        } else {
            chain.doFilter(request, response);
            return;
        }
        final long traceId = trace.getTraceId();
        try {
            SessionAndTraceRegistrationFilter.CTRLINST.newMonitoringRecord(new BeforeOperationEvent(SessionAndTraceRegistrationFilter.TIMESOURCE.getTime(), traceId, trace.getNextOrderId(), operationSignature, componentSignature));
            chain.doFilter(request, response);
            SessionAndTraceRegistrationFilter.CTRLINST.newMonitoringRecord(new AfterOperationEvent(SessionAndTraceRegistrationFilter.TIMESOURCE.getTime(), traceId, trace.getNextOrderId(), operationSignature, componentSignature));
        } catch (final Throwable th) {
            // NOPMD NOCS (catch throw is ok here)
            SessionAndTraceRegistrationFilter.CTRLINST.newMonitoringRecord(new AfterOperationFailedEvent(SessionAndTraceRegistrationFilter.TIMESOURCE.getTime(), traceId, trace.getNextOrderId(), operationSignature, componentSignature, th.toString()));
            throw new ServletException(th);
        } finally {
            // is this correct?
            SessionAndTraceRegistrationFilter.SESSION_REGISTRY.unsetThreadLocalSessionId();
            // Reset the thread-local trace information
            if (newTrace) {
                // close the trace
                SessionAndTraceRegistrationFilter.TRACEREGISTRY.unregisterTrace();
            }
        }
    // } else {
    // chain.doFilter(request, response);
    // return;
    // }
    } else {
        chain.doFilter(request, response);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) AfterOperationFailedEvent(kieker.common.record.flow.trace.operation.AfterOperationFailedEvent) AfterOperationEvent(kieker.common.record.flow.trace.operation.AfterOperationEvent) TraceMetadata(kieker.common.record.flow.trace.TraceMetadata) BeforeOperationEvent(kieker.common.record.flow.trace.operation.BeforeOperationEvent)

Example 2 with AfterOperationFailedEvent

use of kieker.common.record.flow.trace.operation.AfterOperationFailedEvent in project iobserve-analysis by research-iobserve.

the class SessionAndTraceRegistrationFilterForJPetstore method doFilter.

/**
 * Register thread-local session and trace information, executes the given {@link FilterChain}
 * and unregisters the session/trace information. If configured, the execution of this filter is
 * also logged to the {@link IMonitoringController}. This method returns immediately if
 * monitoring is not enabled.
 *
 * @param request
 *            The request.
 * @param response
 *            The response.
 * @param chain
 *            The filter chain to be used.
 *
 * @throws IOException
 *             on io errors
 * @throws ServletException
 *             on servlet errors
 */
@Override
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
    if (SessionAndTraceRegistrationFilterForJPetstore.CTRLINST.isMonitoringEnabled()) {
        // if (CTRLINST.isProbeActivated(this.filterOperationSignatureString)) {
        String operationSignature;
        final String componentSignature;
        final String method;
        final String path;
        final String sessionId;
        final List<CallInformation> callInformations = new ArrayList<>();
        String query = null;
        String[] queryParameters = null;
        if (request instanceof HttpServletRequest) {
            final HttpServletRequest httpRequest = (HttpServletRequest) request;
            method = httpRequest.getMethod();
            final String requestPath = httpRequest.getRequestURI().replace('/', '.').substring(1);
            // remove sessionId from request Path
            path = requestPath.contains(";") ? requestPath.substring(0, requestPath.indexOf(";")) : requestPath;
            sessionId = httpRequest.getSession().getId();
            query = httpRequest.getQueryString();
            if (query == null) {
                query = "";
            } else {
                queryParameters = this.andPattern.split(query);
            }
        } else {
            method = "POST";
            path = request.getServletContext().getContextPath().replace('/', '.').substring(1);
            sessionId = "<no session>";
            query = "";
        }
        final String trimmedPath = path;
        TraceMetadata trace = SessionAndTraceRegistrationFilterForJPetstore.TRACEREGISTRY.getTrace();
        final boolean newTrace = trace == null;
        if (newTrace) {
            SessionRegistry.INSTANCE.storeThreadLocalSessionId(sessionId);
            trace = SessionAndTraceRegistrationFilterForJPetstore.TRACEREGISTRY.registerTrace();
            SessionAndTraceRegistrationFilterForJPetstore.CTRLINST.newMonitoringRecord(trace);
        }
        if ("GET".equals(method)) {
            if (queryParameters != null) {
                // pattern ="jpetstore\\.actions\\."
                operationSignature = trimmedPath + "." + this.equalsPattern.matcher(queryParameters[0]).replaceAll("") + "()";
                // is operation called with parameters
                if (queryParameters.length > 1) {
                    // then add the parameters as call informations
                    for (int i = 1; i < queryParameters.length; i++) {
                        final String[] queryParameterSplit = this.equalsPattern.split(queryParameters[i]);
                        callInformations.add(new CallInformation(queryParameterSplit[i], SessionAndTraceRegistrationFilterForJPetstore.INFORMATION_VALUE));
                    }
                }
                // pattern = "\\.action\\."
                operationSignature = this.removeActionOfOperationPattern.matcher(operationSignature).replaceAll("");
            } else {
                // pattern = "\\w*\\.actions\\."
                if (this.isActionPattern.matcher(trimmedPath).matches()) {
                    SessionAndTraceRegistrationFilterForJPetstore.LOGGER.debug("ACTION");
                    // pattern ="jpetstore\\.actions\\."
                    operationSignature = trimmedPath + "()";
                    // pattern = "\\.action\\("
                    operationSignature = this.removeActionOfIndexPattern.matcher(operationSignature).replaceAll(".index(");
                // pattern "\\w*\\.images\\."
                } else if (this.isImagePattern.matcher(trimmedPath).matches()) {
                    SessionAndTraceRegistrationFilterForJPetstore.LOGGER.debug("IMAGE");
                    operationSignature = trimmedPath;
                } else {
                    SessionAndTraceRegistrationFilterForJPetstore.LOGGER.debug("ELSE");
                    operationSignature = trimmedPath + "()";
                }
            }
        } else if ("POST".equals(method)) {
            operationSignature = trimmedPath + "()";
            // matches "(\\w*\\.)*Account\\..*" ?
            if (this.isAccountPattern.matcher(operationSignature).matches()) {
                // post on the account is always a login
                // pattern = "\\.action\\("
                operationSignature = this.removeActionOfIndexPattern.matcher(operationSignature).replaceAll(".login(");
            } else if (this.isCatalogPattern.matcher(operationSignature).matches()) {
                // post on the account is always a login
                // pattern = "\\.action\\("
                operationSignature = this.removeActionOfIndexPattern.matcher(operationSignature).replaceAll(".search(");
            }
            // pattern = "\\.action\\."
            operationSignature = this.removeActionOfIndexPattern.matcher(operationSignature).replaceAll(".index(");
        } else {
            chain.doFilter(request, response);
            return;
        }
        componentSignature = this.pathStrucPattern.matcher(operationSignature).replaceAll("");
        SessionAndTraceRegistrationFilterForJPetstore.LOGGER.info(operationSignature);
        final long traceId = trace.getTraceId();
        try {
            // mapps Object to String
            final ObjectMapper objectMapper = new ObjectMapper();
            SessionAndTraceRegistrationFilterForJPetstore.CTRLINST.newMonitoringRecord(new BeforeOperationEvent(SessionAndTraceRegistrationFilterForJPetstore.TIMESOURCE.getTime(), traceId, trace.getNextOrderId(), operationSignature, componentSignature));
            chain.doFilter(request, response);
            SessionAndTraceRegistrationFilterForJPetstore.CTRLINST.newMonitoringRecord(new ExtendedAfterOperationEvent(SessionAndTraceRegistrationFilterForJPetstore.TIMESOURCE.getTime(), traceId, trace.getNextOrderId(), operationSignature, componentSignature, objectMapper.writeValueAsString(callInformations)));
        } catch (final Throwable th) {
            // NOPMD NOCS (catch throw is ok here)
            SessionAndTraceRegistrationFilterForJPetstore.CTRLINST.newMonitoringRecord(new AfterOperationFailedEvent(SessionAndTraceRegistrationFilterForJPetstore.TIMESOURCE.getTime(), traceId, trace.getNextOrderId(), operationSignature, componentSignature, th.toString()));
            throw new ServletException(th);
        } finally {
            // is this correct?
            SessionAndTraceRegistrationFilterForJPetstore.SESSION_REGISTRY.unsetThreadLocalSessionId();
            // Reset the thread-local trace information
            if (newTrace) {
                // close the trace
                SessionAndTraceRegistrationFilterForJPetstore.TRACEREGISTRY.unregisterTrace();
            }
        }
    // } else {
    // chain.doFilter(request, response);
    // return;
    // }
    } else {
        chain.doFilter(request, response);
    }
}
Also used : CallInformation(org.iobserve.monitoring.probe.models.CallInformation) ArrayList(java.util.ArrayList) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) AfterOperationFailedEvent(kieker.common.record.flow.trace.operation.AfterOperationFailedEvent) ExtendedAfterOperationEvent(org.iobserve.common.record.ExtendedAfterOperationEvent) TraceMetadata(kieker.common.record.flow.trace.TraceMetadata) BeforeOperationEvent(kieker.common.record.flow.trace.operation.BeforeOperationEvent) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with AfterOperationFailedEvent

use of kieker.common.record.flow.trace.operation.AfterOperationFailedEvent in project iobserve-analysis by research-iobserve.

the class SessionAndTraceRegistrationFilterForJPetstoreAttributeCoding method doFilter.

/**
 * Register thread-local session and trace information, executes the given {@link FilterChain}
 * and unregisters the session/trace information. If configured, the execution of this filter is
 * also logged to the {@link IMonitoringController}. This method returns immediately if
 * monitoring is not enabled.
 *
 * @param request
 *            The request.
 * @param response
 *            The response.
 * @param chain
 *            The filter chain to be used.
 *
 * @throws IOException
 *             on io errors
 * @throws ServletException
 *             on servlet errors
 */
@Override
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
    if (SessionAndTraceRegistrationFilterForJPetstoreAttributeCoding.CTRLINST.isMonitoringEnabled()) {
        // if (CTRLINST.isProbeActivated(this.filterOperationSignatureString)) {
        String operationSignature;
        final String componentSignature;
        final String method;
        final String path;
        final String sessionId;
        final List<CallInformation> callInformations = new ArrayList<>();
        String query = null;
        String[] queryParameters = null;
        if (request instanceof HttpServletRequest) {
            final HttpServletRequest httpRequest = (HttpServletRequest) request;
            method = httpRequest.getMethod();
            final String requestPath = httpRequest.getRequestURI().replace('/', '.').substring(1);
            // remove sessionId from request Path
            path = requestPath.contains(";") ? requestPath.substring(0, requestPath.indexOf(";")) : requestPath;
            sessionId = httpRequest.getSession().getId();
            query = httpRequest.getQueryString();
            if (query == null) {
                query = "";
            } else {
                queryParameters = query.split("&");
            }
        } else {
            method = "POST";
            path = request.getServletContext().getContextPath().replace('/', '.').substring(1);
            sessionId = "<no session>";
            query = "";
        }
        final String trimmedPath = path.replaceAll("\\.[A-Za-z0-9]*$", "");
        // final int lastComponentSignatureIndex = trimmedPath.lastIndexOf("actions.");
        // lastComponentSignatureIndex < 0 ?
        componentSignature = "jpetstore.actions";
        // trimmedPath: trimmedPath.substring(0,
        // lastComponentSignatureIndex - 1);
        TraceMetadata trace = SessionAndTraceRegistrationFilterForJPetstoreAttributeCoding.TRACEREGISTRY.getTrace();
        final boolean newTrace = trace == null;
        if (newTrace) {
            SessionRegistry.INSTANCE.storeThreadLocalSessionId(sessionId);
            trace = SessionAndTraceRegistrationFilterForJPetstoreAttributeCoding.TRACEREGISTRY.registerTrace();
            SessionAndTraceRegistrationFilterForJPetstoreAttributeCoding.CTRLINST.newMonitoringRecord(trace);
        }
        if ("GET".equals(method)) {
            if (queryParameters != null && queryParameters.length == 2) {
                operationSignature = trimmedPath.replaceAll("jpetstore\\.actions\\.", "") + "." + queryParameters[0].replace("=", "") + // "("
                "()";
                // +
                // queryParameters[0]
                // +
                // ")";
                final String[] queryParameterSplit = queryParameters[1].split("=");
                final Long code = SessionAndTraceRegistrationFilterForJPetstoreAttributeCoding.codes.containsKey(queryParameterSplit[1]) ? SessionAndTraceRegistrationFilterForJPetstoreAttributeCoding.codes.get(queryParameterSplit[1]).longValue() : -100L;
                callInformations.add(new CallInformation(queryParameterSplit[0], code));
            } else {
                operationSignature = trimmedPath.replaceAll("jpetstore\\.actions\\.", "") + "(" + query.replace(';', ':') + ")";
            }
            operationSignature = operationSignature.replaceAll("\\.action\\(", "(");
            operationSignature = operationSignature.replaceAll("action\\.", "");
        } else if ("POST".equals(method)) {
            operationSignature = trimmedPath.replaceAll("jpetstore\\.actions\\.", "") + "()";
            operationSignature = operationSignature.replaceAll("\\.action\\(", "(");
            operationSignature = operationSignature.replaceAll("action\\.", "");
        } else {
            chain.doFilter(request, response);
            return;
        }
        final long traceId = trace.getTraceId();
        try {
            // mapps Object to String
            final ObjectMapper objectMapper = new ObjectMapper();
            SessionAndTraceRegistrationFilterForJPetstoreAttributeCoding.CTRLINST.newMonitoringRecord(new BeforeOperationEvent(SessionAndTraceRegistrationFilterForJPetstoreAttributeCoding.TIMESOURCE.getTime(), traceId, trace.getNextOrderId(), operationSignature, componentSignature));
            chain.doFilter(request, response);
            SessionAndTraceRegistrationFilterForJPetstoreAttributeCoding.CTRLINST.newMonitoringRecord(new ExtendedAfterOperationEvent(SessionAndTraceRegistrationFilterForJPetstoreAttributeCoding.TIMESOURCE.getTime(), traceId, trace.getNextOrderId(), operationSignature, componentSignature, objectMapper.writeValueAsString(callInformations)));
        } catch (final Throwable th) {
            // NOPMD NOCS (catch throw is ok here)
            SessionAndTraceRegistrationFilterForJPetstoreAttributeCoding.CTRLINST.newMonitoringRecord(new AfterOperationFailedEvent(SessionAndTraceRegistrationFilterForJPetstoreAttributeCoding.TIMESOURCE.getTime(), traceId, trace.getNextOrderId(), operationSignature, componentSignature, th.toString()));
            throw new ServletException(th);
        } finally {
            // is this correct?
            SessionAndTraceRegistrationFilterForJPetstoreAttributeCoding.SESSION_REGISTRY.unsetThreadLocalSessionId();
            // Reset the thread-local trace information
            if (newTrace) {
                // close the trace
                SessionAndTraceRegistrationFilterForJPetstoreAttributeCoding.TRACEREGISTRY.unregisterTrace();
            }
        }
    // } else {
    // chain.doFilter(request, response);
    // return;
    // }
    } else {
        chain.doFilter(request, response);
    }
}
Also used : CallInformation(org.iobserve.monitoring.probe.models.CallInformation) ArrayList(java.util.ArrayList) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) AfterOperationFailedEvent(kieker.common.record.flow.trace.operation.AfterOperationFailedEvent) ExtendedAfterOperationEvent(org.iobserve.common.record.ExtendedAfterOperationEvent) TraceMetadata(kieker.common.record.flow.trace.TraceMetadata) BeforeOperationEvent(kieker.common.record.flow.trace.operation.BeforeOperationEvent) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 4 with AfterOperationFailedEvent

use of kieker.common.record.flow.trace.operation.AfterOperationFailedEvent in project iobserve-analysis by research-iobserve.

the class TraceInterceptor method interceptMethodCall.

/**
 * Around advice configuration.
 *
 * @param context
 *            the invocation context of a bean call.
 * @return the return value of the next method in the chain
 * @throws Throwable
 */
@AroundInvoke
public Object interceptMethodCall(final InvocationContext context) throws Throwable {
    // (IllegalThrowsCheck)
    if (this.monitoringCtrl.isMonitoringEnabled()) {
        final String signature = context.getMethod().toString();
        if (this.monitoringCtrl.isProbeActivated(signature)) {
            // common fields
            TraceMetadata trace = TraceInterceptor.TRACEREGISTRY.getTrace();
            final boolean newTrace = trace == null;
            if (newTrace) {
                trace = TraceInterceptor.TRACEREGISTRY.registerTrace();
                this.monitoringCtrl.newMonitoringRecord(trace);
            }
            final long traceId = trace.getTraceId();
            final String clazz = context.getTarget().getClass().getCanonicalName();
            // measure before execution
            this.monitoringCtrl.newMonitoringRecord(new BeforeOperationEvent(this.timeSource.getTime(), traceId, trace.getNextOrderId(), signature, clazz));
            // execution of the called method
            try {
                final Object retval = context.proceed();
                // measure after successful execution
                this.monitoringCtrl.newMonitoringRecord(new AfterOperationEvent(this.timeSource.getTime(), traceId, trace.getNextOrderId(), signature, clazz));
                return retval;
            } catch (final Throwable th) {
                // NOPMD NOCS (catch throw might
                // ok here)
                // measure after failed execution
                this.monitoringCtrl.newMonitoringRecord(new AfterOperationFailedEvent(this.timeSource.getTime(), traceId, trace.getNextOrderId(), signature, clazz, th.toString()));
                throw th;
            } finally {
                if (newTrace) {
                    // close the trace
                    TraceInterceptor.TRACEREGISTRY.unregisterTrace();
                }
            }
        } else {
            return context.proceed();
        }
    } else {
        return context.proceed();
    }
}
Also used : AfterOperationFailedEvent(kieker.common.record.flow.trace.operation.AfterOperationFailedEvent) AfterOperationEvent(kieker.common.record.flow.trace.operation.AfterOperationEvent) TraceMetadata(kieker.common.record.flow.trace.TraceMetadata) BeforeOperationEvent(kieker.common.record.flow.trace.operation.BeforeOperationEvent) AroundInvoke(javax.interceptor.AroundInvoke)

Example 5 with AfterOperationFailedEvent

use of kieker.common.record.flow.trace.operation.AfterOperationFailedEvent in project iobserve-analysis by research-iobserve.

the class SessionAndTraceRegistrationPayloadFilter method logMonitoringAndHandleFilterChain.

private void logMonitoringAndHandleFilterChain(final FilterChain chain, final ServletRequest request, final ServletResponse response, final long traceId, final int orderIndex, final String operationSignature, final String componentSignature, final String[] parameters, final String[] parameterValues, final int type, final boolean newTrace) throws ServletException {
    try {
        SessionAndTraceRegistrationPayloadFilter.CTRLINST.newMonitoringRecord(new EntryLevelBeforeOperationEvent(SessionAndTraceRegistrationPayloadFilter.TIMESOURCE.getTime(), traceId, orderIndex, operationSignature, componentSignature, parameters, parameterValues, type));
        chain.doFilter(request, response);
        SessionAndTraceRegistrationPayloadFilter.CTRLINST.newMonitoringRecord(new AfterOperationEvent(SessionAndTraceRegistrationPayloadFilter.TIMESOURCE.getTime(), traceId, orderIndex, operationSignature, componentSignature));
    } catch (final Throwable th) {
        // NOPMD NOCS (catch throw is ok here)
        SessionAndTraceRegistrationPayloadFilter.CTRLINST.newMonitoringRecord(new AfterOperationFailedEvent(SessionAndTraceRegistrationPayloadFilter.TIMESOURCE.getTime(), traceId, orderIndex, operationSignature, componentSignature, th.toString()));
        throw new ServletException(th);
    } finally {
        // is this correct?
        SessionAndTraceRegistrationPayloadFilter.SESSION_REGISTRY.unsetThreadLocalSessionId();
        // Reset the thread-local trace information
        if (newTrace) {
            // close the trace
            SessionAndTraceRegistrationPayloadFilter.TRACEREGISTRY.unregisterTrace();
        }
    }
}
Also used : ServletException(javax.servlet.ServletException) AfterOperationFailedEvent(kieker.common.record.flow.trace.operation.AfterOperationFailedEvent) AfterOperationEvent(kieker.common.record.flow.trace.operation.AfterOperationEvent) EntryLevelBeforeOperationEvent(org.iobserve.common.record.EntryLevelBeforeOperationEvent)

Aggregations

AfterOperationFailedEvent (kieker.common.record.flow.trace.operation.AfterOperationFailedEvent)5 ServletException (javax.servlet.ServletException)4 TraceMetadata (kieker.common.record.flow.trace.TraceMetadata)4 BeforeOperationEvent (kieker.common.record.flow.trace.operation.BeforeOperationEvent)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 AfterOperationEvent (kieker.common.record.flow.trace.operation.AfterOperationEvent)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ArrayList (java.util.ArrayList)2 ExtendedAfterOperationEvent (org.iobserve.common.record.ExtendedAfterOperationEvent)2 CallInformation (org.iobserve.monitoring.probe.models.CallInformation)2 AroundInvoke (javax.interceptor.AroundInvoke)1 EntryLevelBeforeOperationEvent (org.iobserve.common.record.EntryLevelBeforeOperationEvent)1