Search in sources :

Example 11 with IMonitoringRecord

use of kieker.common.record.IMonitoringRecord in project iobserve-analysis by research-iobserve.

the class SessionAndTraceRegistrationPayloadFilterTest method testDoFilter.

/**
 * Test method for
 * {@link org.iobserve.monitoring.probe.servlet.SessionAndTraceRegistrationPayloadFilter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)}.
 *
 * @throws InterruptedException
 *             during the sleep time of the thread
 */
// TODO Something goes occasionally wrong in this test. FixME!
// @Test
public void testDoFilter() throws InterruptedException {
    final ServletContext context = new TestServletContext();
    final ServletResponse response = new TestHttpServletResponse();
    final HttpSession session = new TestHttpSession(context);
    final TestHttpServletRequest request = new TestHttpServletRequest(context, session);
    final FilterConfig filterConfig = new TestFilterConfig(context);
    final SessionAndTraceRegistrationPayloadFilter filter = new SessionAndTraceRegistrationPayloadFilter();
    try {
        filter.init(filterConfig);
        filter.doFilter(request, response, this.createChain());
        MonitoringController.getInstance().terminateMonitoring();
        while (!MonitoringController.getInstance().isMonitoringTerminated()) {
            Thread.sleep(1000);
        }
        final List<IMonitoringRecord> storage = TestDummyWriter.getEvents();
        Assert.assertTrue("No records received", !storage.isEmpty());
        IMonitoringRecord record = storage.get(0);
        Assert.assertEquals("Should be KiekerMetadataRecord", KiekerMetadataRecord.class, record.getClass());
        record = storage.get(1);
        Assert.assertEquals("Should be TraceMetadata", TraceMetadata.class, record.getClass());
        record = storage.get(2);
        Assert.assertEquals("Should be EntryLevelBeforeOperationEvent", EntryLevelBeforeOperationEvent.class, record.getClass());
        if (record instanceof EntryLevelBeforeOperationEvent) {
            final EntryLevelBeforeOperationEvent beforeEvent = (EntryLevelBeforeOperationEvent) record;
            Assert.assertEquals("Class signature does not match", TestServletContext.CONTEXT_PATH, beforeEvent.getClassSignature());
            Assert.assertEquals("Operation signature does not match", TestHttpServletRequest.REQUEST_URI, beforeEvent.getOperationSignature());
            final Iterator<String> keys = request.getParameters().keySet().iterator();
            for (final String label : beforeEvent.getParameters()) {
                if (!keys.hasNext()) {
                    Assert.fail("Found more parameters than defined in the request.");
                } else {
                    Assert.assertEquals("Same parameter", keys.next(), label);
                }
            }
            final Iterator<String> values = request.getParameters().values().iterator();
            for (final String label : beforeEvent.getValues()) {
                if (!values.hasNext()) {
                    Assert.fail("Found more parameters than defined in the request.");
                } else {
                    Assert.assertEquals("Same parameter", values.next(), label);
                }
            }
        }
        record = storage.get(3);
        Assert.assertEquals("Should be AfterOperationEvent", AfterOperationEvent.class, record.getClass());
        Assert.assertEquals("Wrong number of records ", 4, storage.size());
    } catch (final ServletException e) {
        Assert.fail(e.getMessage());
    } catch (final IOException e) {
        Assert.fail(e.getMessage());
    }
}
Also used : ServletResponse(javax.servlet.ServletResponse) HttpSession(javax.servlet.http.HttpSession) SessionAndTraceRegistrationPayloadFilter(org.iobserve.monitoring.probe.servlet.SessionAndTraceRegistrationPayloadFilter) IOException(java.io.IOException) ServletException(javax.servlet.ServletException) EntryLevelBeforeOperationEvent(org.iobserve.common.record.EntryLevelBeforeOperationEvent) IMonitoringRecord(kieker.common.record.IMonitoringRecord) ServletContext(javax.servlet.ServletContext) FilterConfig(javax.servlet.FilterConfig)

Example 12 with IMonitoringRecord

use of kieker.common.record.IMonitoringRecord in project iobserve-analysis by research-iobserve.

the class FixTraceMetadata method execute.

@Override
protected void execute(final IMonitoringRecord event) throws Exception {
    if (event instanceof TraceMetadata) {
        this.traces.put(((TraceMetadata) event).getTraceId(), event.getLoggingTimestamp());
        this.outputPort.send(event);
        final List<IMonitoringRecord> keptRecords = this.stash.get(((TraceMetadata) event).getTraceId());
        if (keptRecords != null) {
            for (final IMonitoringRecord record : keptRecords) {
                this.outputPort.send(record);
            }
        }
    } else if (event instanceof ITraceRecord) {
        final Long time = this.traces.get(((ITraceRecord) event).getTraceId());
        if (time != null) {
            this.traces.put(((ITraceRecord) event).getTraceId(), event.getLoggingTimestamp());
            this.outputPort.send(event);
        } else {
            List<IMonitoringRecord> keptRecords = this.stash.get(((ITraceRecord) event).getTraceId());
            if (keptRecords == null) {
                keptRecords = new ArrayList<>();
            }
            keptRecords.add(event);
            this.stash.put(((ITraceRecord) event).getTraceId(), keptRecords);
        }
    } else {
        this.outputPort.send(event);
    }
}
Also used : ITraceRecord(kieker.common.record.flow.ITraceRecord) IMonitoringRecord(kieker.common.record.IMonitoringRecord) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) TraceMetadata(kieker.common.record.flow.trace.TraceMetadata)

Example 13 with IMonitoringRecord

use of kieker.common.record.IMonitoringRecord in project iobserve-analysis by research-iobserve.

the class HackedRecordFromBinaryFileCreator method processBuffer.

private void processBuffer(final ReaderRegistry<String> registry, final IValueDeserializer deserializer, final OutputPort<IMonitoringRecord> outputPort) throws IOException {
    this.buffer.flip();
    try {
        /**
         * Needs at least an record id.
         */
        while (this.buffer.position() + 4 <= this.buffer.limit()) {
            this.buffer.mark();
            final IMonitoringRecord record = this.deserializeRecord(registry, deserializer);
            if (record == null) {
                return;
            } else {
                outputPort.send(record);
            }
        }
        this.buffer.mark();
        this.buffer.compact();
    } catch (final BufferUnderflowException ex) {
        HackedRecordFromBinaryFileCreator.LOGGER.warn("Unexpected buffer underflow. Resetting and compacting buffer.", ex);
        this.buffer.reset();
        this.buffer.compact();
        throw ex;
    }
}
Also used : IMonitoringRecord(kieker.common.record.IMonitoringRecord) BufferUnderflowException(java.nio.BufferUnderflowException)

Example 14 with IMonitoringRecord

use of kieker.common.record.IMonitoringRecord in project iobserve-analysis by research-iobserve.

the class MultipleConnectionTcpReaderStage method deserializeRecord.

private boolean deserializeRecord(final Connection connection, final int clazzId) throws IOException {
    final String recordClassName = connection.getRegistry().get(clazzId);
    // identify logging timestamp
    if (connection.getBuffer().remaining() < MultipleConnectionTcpReaderStage.LONG_BYTES) {
        // incomplete record, move back
        connection.getBuffer().reset();
        connection.getBuffer().compact();
        return false;
    } else {
        final long loggingTimestamp = connection.getBuffer().getLong();
        // identify record data
        final IRecordFactory<? extends IMonitoringRecord> recordFactory = this.recordFactories.get(recordClassName);
        if (connection.getBuffer().remaining() < recordFactory.getRecordSizeInBytes()) {
            // incomplete record, move back
            connection.getBuffer().reset();
            connection.getBuffer().compact();
            return false;
        } else {
            try {
                final IMonitoringRecord record = recordFactory.create(connection.getValueDeserializer());
                this.recordRewriter.rewrite(connection, record, loggingTimestamp, this.outputPort);
                return true;
            } catch (final RecordInstantiationException ex) {
                super.logger.error("Failed to create: " + recordClassName, ex);
                // incomplete record, move back
                connection.getBuffer().reset();
                connection.getBuffer().compact();
                return false;
            }
        }
    }
}
Also used : IMonitoringRecord(kieker.common.record.IMonitoringRecord) RecordInstantiationException(kieker.common.exception.RecordInstantiationException)

Example 15 with IMonitoringRecord

use of kieker.common.record.IMonitoringRecord in project iobserve-analysis by research-iobserve.

the class ProbeControlFilterTest method setUp.

/**
 * Setup the test.
 */
@Before
public void setUp() {
    synchronized (this) {
        final IRecordReceivedListener listener = new IRecordReceivedListener() {

            @Override
            public void onRecordReceived(final IMonitoringRecord record) {
            // do nothing.. the TCP sender is tested elsewhere
            }
        };
        ProbeControlFilterTest.port++;
        this.tcpReader = new SingleSocketRecordReader(ProbeControlFilterTest.port, ProbeControlFilterTest.BUFFER_SIZE, ProbeControlFilterTest.LOGGER, listener);
        new Thread(this.tcpReader).start();
        this.probeControlFilter = new ProbeControlFilter(new TcpProbeController());
    }
}
Also used : IRecordReceivedListener(kieker.common.record.IRecordReceivedListener) SingleSocketRecordReader(kieker.monitoring.core.controller.tcp.SingleSocketRecordReader) ProbeControlFilter(org.iobserve.stages.tcp.ProbeControlFilter) IMonitoringRecord(kieker.common.record.IMonitoringRecord) TcpProbeController(org.iobserve.utility.tcp.TcpProbeController) Before(org.junit.Before)

Aggregations

IMonitoringRecord (kieker.common.record.IMonitoringRecord)15 IOException (java.io.IOException)2 BufferUnderflowException (java.nio.BufferUnderflowException)2 ArrayList (java.util.ArrayList)2 FilterConfig (javax.servlet.FilterConfig)2 ServletContext (javax.servlet.ServletContext)2 ServletException (javax.servlet.ServletException)2 ServletResponse (javax.servlet.ServletResponse)2 HttpSession (javax.servlet.http.HttpSession)2 RecordInstantiationException (kieker.common.exception.RecordInstantiationException)2 IRecordReceivedListener (kieker.common.record.IRecordReceivedListener)2 ITraceRecord (kieker.common.record.flow.ITraceRecord)2 TraceMetadata (kieker.common.record.flow.trace.TraceMetadata)2 TextValueDeserializer (kieker.common.record.io.TextValueDeserializer)2 EntryLevelBeforeOperationEvent (org.iobserve.common.record.EntryLevelBeforeOperationEvent)2 ProbeControlFilter (org.iobserve.stages.tcp.ProbeControlFilter)2 Before (org.junit.Before)2 List (java.util.List)1 ServletContextEvent (javax.servlet.ServletContextEvent)1 MappingException (kieker.analysisteetime.plugin.reader.filesystem.util.MappingException)1