Search in sources :

Example 6 with RecordedEvent

use of jdk.jfr.consumer.RecordedEvent in project splunk-otel-java by signalfx.

the class SpanContextualizerTest method contextEvent.

private static RecordedEvent contextEvent(String traceId, String spanId, long threadId) {
    RecordedEvent event = mock(RecordedEvent.class);
    EventType type = mock(EventType.class);
    when(type.getName()).thenReturn(ContextAttached.EVENT_NAME);
    when(event.getEventType()).thenReturn(type);
    when(event.getString("traceId")).thenReturn(traceId);
    when(event.getString("spanId")).thenReturn(spanId);
    RecordedThread thread = mock(RecordedThread.class);
    when(thread.getJavaThreadId()).thenReturn(threadId);
    when(event.getThread()).thenReturn(thread);
    return event;
}
Also used : EventType(jdk.jfr.EventType) RecordedEvent(jdk.jfr.consumer.RecordedEvent) RecordedThread(jdk.jfr.consumer.RecordedThread)

Example 7 with RecordedEvent

use of jdk.jfr.consumer.RecordedEvent in project splunk-otel-java by signalfx.

the class EventProcessingChainTest method testLifecycle.

@Test
void testLifecycle() {
    EventType contextAttachedType = newEventType(ContextAttached.EVENT_NAME);
    EventType threadDumpType = newEventType(ThreadDumpProcessor.EVENT_NAME);
    EventType tlabType = newEventType(TLABProcessor.NEW_TLAB_EVENT_NAME);
    Instant now = Instant.now();
    RecordedEvent tlab1 = newEvent(tlabType, now.minus(100, ChronoUnit.MILLIS));
    RecordedEvent tlab2 = newEvent(tlabType, now.plus(100, ChronoUnit.MILLIS));
    // context even happens after the thread dump but is seen first
    RecordedEvent contextEvent = newEvent(contextAttachedType, now);
    RecordedEvent threadDump = newEvent(threadDumpType, now.minus(250, ChronoUnit.MILLIS));
    EventProcessingChain chain = new EventProcessingChain(contextualizer, threadDumpProcessor, tlabProcessor);
    chain.accept(tlab1);
    chain.accept(contextEvent);
    chain.accept(tlab2);
    chain.accept(threadDump);
    verifyNoInteractions(contextualizer, threadDumpProcessor, tlabProcessor);
    chain.flushBuffer();
    InOrder inOrder = inOrder(contextualizer, threadDumpProcessor, tlabProcessor);
    inOrder.verify(threadDumpProcessor).accept(threadDump);
    inOrder.verify(tlabProcessor).accept(tlab1);
    inOrder.verify(contextualizer).updateContext(contextEvent);
    inOrder.verify(tlabProcessor).accept(tlab2);
    inOrder.verifyNoMoreInteractions();
}
Also used : InOrder(org.mockito.InOrder) EventType(jdk.jfr.EventType) Instant(java.time.Instant) RecordedEvent(jdk.jfr.consumer.RecordedEvent) Test(org.junit.jupiter.api.Test)

Example 8 with RecordedEvent

use of jdk.jfr.consumer.RecordedEvent in project splunk-otel-java by signalfx.

the class EventProcessingChainTest method eventsDispatchedInTimeOrder.

@Test
void eventsDispatchedInTimeOrder() {
    EventType contextAttachedType = newEventType(ContextAttached.EVENT_NAME);
    EventType threadDumpType = newEventType(ThreadDumpProcessor.EVENT_NAME);
    Instant now = Instant.now();
    RecordedEvent event1 = newEvent(contextAttachedType, now.plus(1, SECONDS));
    RecordedEvent event2 = newEvent(contextAttachedType, now.plus(2, SECONDS));
    RecordedEvent event3 = newEvent(threadDumpType, now.plus(3, SECONDS));
    RecordedEvent event4 = newEvent(null, null);
    // Our events are in time order: context1, context2, threadDump1, threadDump2.
    // However, we will send them to the chain out of order: context2, context1, threadDump.
    // Expectation is that we see them dispatched in the correct order.
    // The "chunk" is finished only after event4, and event4 is part of a new chunk so is not
    // dispatched.
    EventProcessingChain.ChunkTracker chunkTracker = mock(EventProcessingChain.ChunkTracker.class);
    when(chunkTracker.isNewChunk(isA(RecordedEvent.class))).thenReturn(false, false, false, true);
    EventProcessingChain chain = new EventProcessingChain(contextualizer, threadDumpProcessor, tlabProcessor, chunkTracker);
    // Out of order
    chain.accept(event2);
    // Out of order
    chain.accept(event1);
    chain.accept(event3);
    chain.accept(event4);
    InOrder ordered = inOrder(contextualizer, threadDumpProcessor);
    ordered.verify(contextualizer).updateContext(event1);
    ordered.verify(contextualizer).updateContext(event2);
    ordered.verify(threadDumpProcessor).accept(event3);
    ordered.verifyNoMoreInteractions();
}
Also used : InOrder(org.mockito.InOrder) EventType(jdk.jfr.EventType) Instant(java.time.Instant) RecordedEvent(jdk.jfr.consumer.RecordedEvent) Test(org.junit.jupiter.api.Test)

Example 9 with RecordedEvent

use of jdk.jfr.consumer.RecordedEvent in project splunk-otel-java by signalfx.

the class JfrPathHandlerTest method testAccept.

@Test
void testAccept() {
    Path path = Paths.get("/path/to/something.jfr");
    EventProcessingChain chain = mock(EventProcessingChain.class);
    Consumer<Path> onFileFinished = mock(Consumer.class);
    RecordedEventStream.Factory eventStreamFactory = mock(RecordedEventStream.Factory.class);
    RecordedEventStream recordedEventStream = mock(RecordedEventStream.class);
    RecordedEvent e1 = mock(RecordedEvent.class);
    RecordedEvent e2 = mock(RecordedEvent.class);
    RecordedEvent e3 = mock(RecordedEvent.class);
    AtomicBoolean closeWasCalled = new AtomicBoolean(false);
    Stream<RecordedEvent> stream = Stream.of(e1, e2, e3).onClose(() -> closeWasCalled.set(true));
    when(eventStreamFactory.get()).thenReturn(recordedEventStream);
    when(recordedEventStream.open(path)).thenReturn(stream);
    JfrPathHandler jfrPathHandler = JfrPathHandler.builder().eventProcessingChain(chain).onFileFinished(onFileFinished).recordedEventStreamFactory(eventStreamFactory).build();
    jfrPathHandler.accept(path);
    verify(chain).accept(e1);
    verify(chain).accept(e2);
    verify(chain).accept(e3);
    verify(chain).flushBuffer();
    verify(chain).logEventStats();
    verifyNoMoreInteractions(chain);
    verify(onFileFinished).accept(path);
    assertTrue(closeWasCalled.get());
}
Also used : Path(java.nio.file.Path) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) RecordedEvent(jdk.jfr.consumer.RecordedEvent) Test(org.junit.jupiter.api.Test)

Example 10 with RecordedEvent

use of jdk.jfr.consumer.RecordedEvent in project splunk-otel-java by signalfx.

the class BasicJfrRecordingFileTest method testCloseException.

@Test
void testCloseException() throws Exception {
    RecordedEvent ev = mock(RecordedEvent.class);
    when(recordingFile.hasMoreEvents()).thenReturn(true, true, true, false);
    when(jfr.openRecordingFile(path)).thenReturn(recordingFile);
    when(jfr.readEvent(recordingFile, path)).thenReturn(ev);
    doThrow(new IOException("it hurts")).when(recordingFile).close();
    BasicJfrRecordingFile basicJfrRecordingFile = new BasicJfrRecordingFile(jfr);
    Stream<RecordedEvent> stream = basicJfrRecordingFile.open(path);
    stream.collect(Collectors.toList());
    verify(recordingFile).close();
// no exception thrown, success
}
Also used : RecordedEvent(jdk.jfr.consumer.RecordedEvent) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Aggregations

RecordedEvent (jdk.jfr.consumer.RecordedEvent)27 Test (org.junit.jupiter.api.Test)14 EventType (jdk.jfr.EventType)11 RecordingFile (jdk.jfr.consumer.RecordingFile)11 Instant (java.time.Instant)5 RecordedThread (jdk.jfr.consumer.RecordedThread)5 Config (io.opentelemetry.instrumentation.api.config.Config)4 File (java.io.File)4 RecordedStackTrace (jdk.jfr.consumer.RecordedStackTrace)4 EventPeriods (com.splunk.opentelemetry.profiler.events.EventPeriods)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 TimeUnit (java.util.concurrent.TimeUnit)3 CONFIG_KEY_MEMORY_SAMPLER_INTERVAL (com.splunk.opentelemetry.profiler.Configuration.CONFIG_KEY_MEMORY_SAMPLER_INTERVAL)2 CONFIG_KEY_TLAB_ENABLED (com.splunk.opentelemetry.profiler.Configuration.CONFIG_KEY_TLAB_ENABLED)2 DEFAULT_MEMORY_ENABLED (com.splunk.opentelemetry.profiler.Configuration.DEFAULT_MEMORY_ENABLED)2 DEFAULT_MEMORY_SAMPLING_INTERVAL (com.splunk.opentelemetry.profiler.Configuration.DEFAULT_MEMORY_SAMPLING_INTERVAL)2 SOURCE_EVENT_NAME (com.splunk.opentelemetry.profiler.ProfilingSemanticAttributes.SOURCE_EVENT_NAME)2 SOURCE_TYPE (com.splunk.opentelemetry.profiler.ProfilingSemanticAttributes.SOURCE_TYPE)2 ALLOCATION_SIZE_KEY (com.splunk.opentelemetry.profiler.TLABProcessor.ALLOCATION_SIZE_KEY)2