Search in sources :

Example 11 with TraceMetadata

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

the class SessionAndTraceRegistrationPayloadFilter 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 (SessionAndTraceRegistrationPayloadFilter.CTRLINST.isMonitoringEnabled()) {
        // if (CTRLINST.isProbeActivated(this.filterOperationSignatureString)) {
        final String method;
        final String path;
        final String sessionId;
        if (request instanceof HttpServletRequest) {
            final HttpServletRequest httpRequest = (HttpServletRequest) request;
            method = httpRequest.getMethod();
            final String requestPath = httpRequest.getRequestURI();
            // TODO is this a generic thing?
            /**
             * remove sessionId from request path.
             */
            path = requestPath.contains(";") ? requestPath.substring(0, requestPath.indexOf(";")) : requestPath;
            sessionId = httpRequest.getSession().getId();
            final String operationSignature = path;
            final List<String> parameters = new ArrayList<>();
            final List<String> parameterValues = new ArrayList<>();
            final Enumeration<String> names = httpRequest.getParameterNames();
            while (names.hasMoreElements()) {
                final String name = names.nextElement();
                final String[] values = httpRequest.getParameterValues(name);
                for (final String value : values) {
                    parameters.add(name);
                    parameterValues.add(value);
                }
            }
            final String componentSignature = request.getServletContext().getContextPath();
            TraceMetadata trace = SessionAndTraceRegistrationPayloadFilter.TRACEREGISTRY.getTrace();
            final boolean newTrace = trace == null;
            if (newTrace) {
                SessionRegistry.INSTANCE.storeThreadLocalSessionId(sessionId);
                trace = SessionAndTraceRegistrationPayloadFilter.TRACEREGISTRY.registerTrace();
                SessionAndTraceRegistrationPayloadFilter.CTRLINST.newMonitoringRecord(trace);
            }
            final long traceId = trace.getTraceId();
            if ("GET".equals(method)) {
                this.logMonitoringAndHandleFilterChain(chain, httpRequest, response, traceId, trace.getNextOrderId(), operationSignature, componentSignature, parameters.toArray(new String[parameters.size()]), parameterValues.toArray(new String[parameterValues.size()]), 1, newTrace);
            } else if ("POST".equals(method)) {
                this.logMonitoringAndHandleFilterChain(chain, httpRequest, response, traceId, trace.getNextOrderId(), operationSignature, componentSignature, parameters.toArray(new String[parameters.size()]), parameterValues.toArray(new String[parameterValues.size()]), 1, newTrace);
            } else {
                chain.doFilter(request, response);
                return;
            }
        } else {
            /**
             * not a http request.
             */
            chain.doFilter(request, response);
        }
    } else {
        chain.doFilter(request, response);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ArrayList(java.util.ArrayList) TraceMetadata(kieker.common.record.flow.trace.TraceMetadata)

Example 12 with TraceMetadata

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

the class TestSend method main.

/**
 * Execute send test.
 *
 * @param args
 *            arguments are ignored.
 */
public static void main(final String[] args) {
    TestSend.LOGGER.debug("Sender");
    final Configuration configuration = ConfigurationFactory.createDefaultConfiguration();
    configuration.setProperty(ConfigurationKeys.CONTROLLER_NAME, "Kieker-Test");
    configuration.setProperty(ConfigurationKeys.WRITER_CLASSNAME, TestSend.WRITER_NAME);
    configuration.setProperty(SingleSocketTcpWriter.CONFIG_HOSTNAME, "localhost");
    configuration.setProperty(SingleSocketTcpWriter.CONFIG_PORT, "9876");
    configuration.setProperty(SingleSocketTcpWriter.CONFIG_BUFFERSIZE, "1024");
    configuration.setProperty(SingleSocketTcpWriter.CONFIG_FLUSH, "true");
    // add ignored values
    configuration.setProperty(ConfigurationKeys.PREFIX + "test", "true");
    configuration.setProperty(TestSend.WRITER_NAME + ".test", "true");
    TestSend.LOGGER.debug("Configuration complete");
    final IMonitoringController ctrl = MonitoringController.createInstance(configuration);
    TestSend.LOGGER.debug("Controller active");
    TestSend.LOGGER.debug("Send first record");
    IMonitoringRecord record = new TraceMetadata(1, 2, "demo", "hostname", 0, 0);
    ctrl.newMonitoringRecord(record);
    TestSend.LOGGER.debug("Send second record");
    record = new BeforeOperationEvent(0, 1, 0, "Send", "main");
    ctrl.newMonitoringRecord(record);
    TestSend.LOGGER.debug("Done");
}
Also used : IMonitoringController(kieker.monitoring.core.controller.IMonitoringController) Configuration(kieker.common.configuration.Configuration) IMonitoringRecord(kieker.common.record.IMonitoringRecord) TraceMetadata(kieker.common.record.flow.trace.TraceMetadata) BeforeOperationEvent(kieker.common.record.flow.trace.operation.BeforeOperationEvent)

Aggregations

TraceMetadata (kieker.common.record.flow.trace.TraceMetadata)12 BeforeOperationEvent (kieker.common.record.flow.trace.operation.BeforeOperationEvent)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 ServletException (javax.servlet.ServletException)4 AfterOperationFailedEvent (kieker.common.record.flow.trace.operation.AfterOperationFailedEvent)4 ArrayList (java.util.ArrayList)3 AfterOperationEvent (kieker.common.record.flow.trace.operation.AfterOperationEvent)3 KiekerMetadataRecord (kieker.common.record.misc.KiekerMetadataRecord)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 AroundInvoke (javax.interceptor.AroundInvoke)2 ITraceRecord (kieker.common.record.flow.ITraceRecord)2 AfterOperationFailedObjectEvent (kieker.common.record.flow.trace.operation.object.AfterOperationFailedObjectEvent)2 AfterOperationObjectEvent (kieker.common.record.flow.trace.operation.object.AfterOperationObjectEvent)2 BeforeOperationObjectEvent (kieker.common.record.flow.trace.operation.object.BeforeOperationObjectEvent)2 ExtendedAfterOperationEvent (org.iobserve.common.record.ExtendedAfterOperationEvent)2 CallInformation (org.iobserve.monitoring.probe.models.CallInformation)2 InetSocketAddress (java.net.InetSocketAddress)1 SocketAddress (java.net.SocketAddress)1 HashMap (java.util.HashMap)1 List (java.util.List)1