Search in sources :

Example 1 with EventPeriods

use of com.splunk.opentelemetry.profiler.events.EventPeriods in project splunk-otel-java by signalfx.

the class LogDataCommonAttributesTest method testBuild.

@Test
void testBuild() {
    String sourceType = "otel.profiling";
    String eventName = "core.core.unicorn";
    Attributes expected = Attributes.builder().put(SOURCE_TYPE, sourceType).put(SOURCE_EVENT_NAME, eventName).put(SOURCE_EVENT_PERIOD, 999L).build();
    EventPeriods periods = mock(EventPeriods.class);
    RecordedEvent event = mock(RecordedEvent.class);
    EventType eventType = mock(EventType.class);
    when(event.getEventType()).thenReturn(eventType);
    when(eventType.getName()).thenReturn(eventName);
    when(periods.getDuration(eventName)).thenReturn(Duration.ofMillis(999));
    LogDataCommonAttributes logDataAttributes = new LogDataCommonAttributes(periods);
    Attributes result = logDataAttributes.builder(event.getEventType().getName()).build();
    assertEquals(expected, result);
}
Also used : EventPeriods(com.splunk.opentelemetry.profiler.events.EventPeriods) EventType(jdk.jfr.EventType) Attributes(io.opentelemetry.api.common.Attributes) RecordedEvent(jdk.jfr.consumer.RecordedEvent) Test(org.junit.jupiter.api.Test)

Example 2 with EventPeriods

use of com.splunk.opentelemetry.profiler.events.EventPeriods in project splunk-otel-java by signalfx.

the class LogDataCreatorTest method testCreate.

@Test
void testCreate() {
    Instant time = Instant.now();
    String stack = "the.stack";
    SpanContext spanContext = SpanContext.create("deadbeefdeadbeefdeadbeefdeadbeef", "0123012301230123", TraceFlags.getSampled(), TraceState.getDefault());
    Context context = Context.root().with(Span.wrap(spanContext));
    long threadId = 987L;
    String eventName = "GoodEventHere";
    EventPeriods periods = mock(EventPeriods.class);
    when(periods.getDuration(eventName)).thenReturn(Duration.ofMillis(606));
    SpanLinkage linkage = new SpanLinkage(spanContext, threadId);
    Resource resource = Resource.getDefault();
    Attributes attributes = Attributes.of(SOURCE_EVENT_NAME, eventName, SOURCE_EVENT_PERIOD, 606L, SOURCE_TYPE, "otel.profiling");
    LogData expected = LogDataBuilder.create(resource, INSTRUMENTATION_LIBRARY_INFO).setContext(context).setBody(stack).setEpoch(time).setAttributes(attributes).build();
    StackToSpanLinkage linkedSpan = new StackToSpanLinkage(time, "the.stack", eventName, linkage);
    LogDataCreator creator = new LogDataCreator(new LogDataCommonAttributes(periods), Resource.getDefault());
    LogData result = creator.apply(linkedSpan);
    assertEquals(expected, result);
}
Also used : Context(io.opentelemetry.context.Context) SpanContext(io.opentelemetry.api.trace.SpanContext) EventPeriods(com.splunk.opentelemetry.profiler.events.EventPeriods) LogData(io.opentelemetry.sdk.logs.data.LogData) StackToSpanLinkage(com.splunk.opentelemetry.profiler.context.StackToSpanLinkage) SpanContext(io.opentelemetry.api.trace.SpanContext) StackToSpanLinkage(com.splunk.opentelemetry.profiler.context.StackToSpanLinkage) SpanLinkage(com.splunk.opentelemetry.profiler.context.SpanLinkage) Instant(java.time.Instant) Resource(io.opentelemetry.sdk.resources.Resource) Attributes(io.opentelemetry.api.common.Attributes) Test(org.junit.jupiter.api.Test)

Example 3 with EventPeriods

use of com.splunk.opentelemetry.profiler.events.EventPeriods in project splunk-otel-java by signalfx.

the class TLABProcessorTest method tlabProcessTest.

private void tlabProcessTest(Long tlabSize) {
    Instant now = Instant.now();
    AtomicReference<LogData> seenLogData = new AtomicReference<>();
    LogProcessor consumer = seenLogData::set;
    String stackAsString = "\"mockingbird\" #606\n" + "   java.lang.Thread.State: UNKNOWN\n" + "i am a serialized stack believe me";
    StackSerializer serializer = mock(StackSerializer.class);
    LogDataCommonAttributes commonAttrs = new LogDataCommonAttributes(new EventPeriods(x -> null));
    Clock clock = new MockClock(now);
    RecordedEvent event = createMockEvent(serializer, now, tlabSize);
    Config config = mock(Config.class);
    when(config.getBoolean(CONFIG_KEY_TLAB_ENABLED, DEFAULT_MEMORY_ENABLED)).thenReturn(true);
    SpanContext spanContext = SpanContext.create(TraceId.fromLongs(123, 456), SpanId.fromLong(123), TraceFlags.getSampled(), TraceState.getDefault());
    SpanContextualizer spanContextualizer = mock(SpanContextualizer.class);
    when(spanContextualizer.link(THREAD_ID)).thenReturn(new SpanLinkage(spanContext, THREAD_ID));
    TLABProcessor processor = TLABProcessor.builder(config).stackSerializer(serializer).logProcessor(consumer).commonAttributes(commonAttrs).resource(Resource.getDefault()).spanContextualizer(spanContextualizer).build();
    processor.accept(event);
    assertEquals(stackAsString, seenLogData.get().getBody().asString());
    assertEquals(TimeUnit.SECONDS.toNanos(now.getEpochSecond()) + clock.nanoTime(), seenLogData.get().getEpochNanos());
    assertEquals("otel.profiling", seenLogData.get().getAttributes().get(SOURCE_TYPE));
    assertEquals("tee-lab", seenLogData.get().getAttributes().get(SOURCE_EVENT_NAME));
    assertEquals(ONE_MB, seenLogData.get().getAttributes().get(ALLOCATION_SIZE_KEY));
    assertEquals(spanContext, seenLogData.get().getSpanContext());
}
Also used : Clock(io.opentelemetry.sdk.common.Clock) TraceFlags(io.opentelemetry.api.trace.TraceFlags) LogProcessor(io.opentelemetry.sdk.logs.LogProcessor) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) SpanId(io.opentelemetry.api.trace.SpanId) Resource(io.opentelemetry.sdk.resources.Resource) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) SOURCE_EVENT_NAME(com.splunk.opentelemetry.profiler.ProfilingSemanticAttributes.SOURCE_EVENT_NAME) SpanLinkage(com.splunk.opentelemetry.profiler.context.SpanLinkage) EventPeriods(com.splunk.opentelemetry.profiler.events.EventPeriods) AtomicReference(java.util.concurrent.atomic.AtomicReference) Answer(org.mockito.stubbing.Answer) TraceState(io.opentelemetry.api.trace.TraceState) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ALLOCATION_SIZE_KEY(com.splunk.opentelemetry.profiler.TLABProcessor.ALLOCATION_SIZE_KEY) CONFIG_KEY_MEMORY_SAMPLER_INTERVAL(com.splunk.opentelemetry.profiler.Configuration.CONFIG_KEY_MEMORY_SAMPLER_INTERVAL) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) EventType(jdk.jfr.EventType) LogData(io.opentelemetry.sdk.logs.data.LogData) CONFIG_KEY_TLAB_ENABLED(com.splunk.opentelemetry.profiler.Configuration.CONFIG_KEY_TLAB_ENABLED) SpanContext(io.opentelemetry.api.trace.SpanContext) DEFAULT_MEMORY_ENABLED(com.splunk.opentelemetry.profiler.Configuration.DEFAULT_MEMORY_ENABLED) Mockito.when(org.mockito.Mockito.when) DEFAULT_MEMORY_SAMPLING_INTERVAL(com.splunk.opentelemetry.profiler.Configuration.DEFAULT_MEMORY_SAMPLING_INTERVAL) Instant(java.time.Instant) RecordedStackTrace(jdk.jfr.consumer.RecordedStackTrace) SpanContextualizer(com.splunk.opentelemetry.profiler.context.SpanContextualizer) Config(io.opentelemetry.instrumentation.api.config.Config) TimeUnit(java.util.concurrent.TimeUnit) RecordedEvent(jdk.jfr.consumer.RecordedEvent) Test(org.junit.jupiter.api.Test) SOURCE_TYPE(com.splunk.opentelemetry.profiler.ProfilingSemanticAttributes.SOURCE_TYPE) RecordedThread(jdk.jfr.consumer.RecordedThread) StackSerializer(com.splunk.opentelemetry.profiler.util.StackSerializer) AttributeKey(io.opentelemetry.api.common.AttributeKey) TraceId(io.opentelemetry.api.trace.TraceId) Mockito.mock(org.mockito.Mockito.mock) LogData(io.opentelemetry.sdk.logs.data.LogData) EventPeriods(com.splunk.opentelemetry.profiler.events.EventPeriods) SpanContext(io.opentelemetry.api.trace.SpanContext) StackSerializer(com.splunk.opentelemetry.profiler.util.StackSerializer) Config(io.opentelemetry.instrumentation.api.config.Config) SpanLinkage(com.splunk.opentelemetry.profiler.context.SpanLinkage) Instant(java.time.Instant) RecordedEvent(jdk.jfr.consumer.RecordedEvent) AtomicReference(java.util.concurrent.atomic.AtomicReference) LogProcessor(io.opentelemetry.sdk.logs.LogProcessor) Clock(io.opentelemetry.sdk.common.Clock) SpanContextualizer(com.splunk.opentelemetry.profiler.context.SpanContextualizer)

Example 4 with EventPeriods

use of com.splunk.opentelemetry.profiler.events.EventPeriods in project splunk-otel-java by signalfx.

the class TLABProcessorTest method testSampling.

@Test
void testSampling() {
    int samplerInterval = 5;
    AtomicReference<LogData> seenLogData = new AtomicReference<>();
    LogProcessor consumer = seenLogData::set;
    StackSerializer serializer = mock(StackSerializer.class);
    LogDataCommonAttributes commonAttrs = new LogDataCommonAttributes(new EventPeriods(x -> null));
    SpanContextualizer spanContextualizer = mock(SpanContextualizer.class);
    when(spanContextualizer.link(anyLong())).thenReturn(SpanLinkage.NONE);
    Config config = mock(Config.class);
    when(config.getBoolean(CONFIG_KEY_TLAB_ENABLED, DEFAULT_MEMORY_ENABLED)).thenReturn(true);
    when(config.getInt(CONFIG_KEY_MEMORY_SAMPLER_INTERVAL, DEFAULT_MEMORY_SAMPLING_INTERVAL)).thenReturn(samplerInterval);
    TLABProcessor processor = TLABProcessor.builder(config).stackSerializer(serializer).logProcessor(consumer).commonAttributes(commonAttrs).resource(Resource.getDefault()).spanContextualizer(spanContextualizer).build();
    RecordedEvent event = createMockEvent(serializer, Instant.now(), null);
    for (int i = 0; i < samplerInterval + 2; i++) {
        processor.accept(event);
        if (i % samplerInterval == 0) {
            assertEquals("otel.profiling", seenLogData.get().getAttributes().get(SOURCE_TYPE));
            assertEquals("tee-lab", seenLogData.get().getAttributes().get(SOURCE_EVENT_NAME));
            assertEquals("Systematic sampler", seenLogData.get().getAttributes().get(SAMPLER_NAME_KEY));
            assertEquals(Long.valueOf(samplerInterval), seenLogData.get().getAttributes().get(SAMPLER_INTERVAL_KEY));
        } else {
            assertNull(seenLogData.get());
        }
        seenLogData.set(null);
    }
}
Also used : Clock(io.opentelemetry.sdk.common.Clock) TraceFlags(io.opentelemetry.api.trace.TraceFlags) LogProcessor(io.opentelemetry.sdk.logs.LogProcessor) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) SpanId(io.opentelemetry.api.trace.SpanId) Resource(io.opentelemetry.sdk.resources.Resource) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) SOURCE_EVENT_NAME(com.splunk.opentelemetry.profiler.ProfilingSemanticAttributes.SOURCE_EVENT_NAME) SpanLinkage(com.splunk.opentelemetry.profiler.context.SpanLinkage) EventPeriods(com.splunk.opentelemetry.profiler.events.EventPeriods) AtomicReference(java.util.concurrent.atomic.AtomicReference) Answer(org.mockito.stubbing.Answer) TraceState(io.opentelemetry.api.trace.TraceState) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ALLOCATION_SIZE_KEY(com.splunk.opentelemetry.profiler.TLABProcessor.ALLOCATION_SIZE_KEY) CONFIG_KEY_MEMORY_SAMPLER_INTERVAL(com.splunk.opentelemetry.profiler.Configuration.CONFIG_KEY_MEMORY_SAMPLER_INTERVAL) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) EventType(jdk.jfr.EventType) LogData(io.opentelemetry.sdk.logs.data.LogData) CONFIG_KEY_TLAB_ENABLED(com.splunk.opentelemetry.profiler.Configuration.CONFIG_KEY_TLAB_ENABLED) SpanContext(io.opentelemetry.api.trace.SpanContext) DEFAULT_MEMORY_ENABLED(com.splunk.opentelemetry.profiler.Configuration.DEFAULT_MEMORY_ENABLED) Mockito.when(org.mockito.Mockito.when) DEFAULT_MEMORY_SAMPLING_INTERVAL(com.splunk.opentelemetry.profiler.Configuration.DEFAULT_MEMORY_SAMPLING_INTERVAL) Instant(java.time.Instant) RecordedStackTrace(jdk.jfr.consumer.RecordedStackTrace) SpanContextualizer(com.splunk.opentelemetry.profiler.context.SpanContextualizer) Config(io.opentelemetry.instrumentation.api.config.Config) TimeUnit(java.util.concurrent.TimeUnit) RecordedEvent(jdk.jfr.consumer.RecordedEvent) Test(org.junit.jupiter.api.Test) SOURCE_TYPE(com.splunk.opentelemetry.profiler.ProfilingSemanticAttributes.SOURCE_TYPE) RecordedThread(jdk.jfr.consumer.RecordedThread) StackSerializer(com.splunk.opentelemetry.profiler.util.StackSerializer) AttributeKey(io.opentelemetry.api.common.AttributeKey) TraceId(io.opentelemetry.api.trace.TraceId) Mockito.mock(org.mockito.Mockito.mock) LogData(io.opentelemetry.sdk.logs.data.LogData) EventPeriods(com.splunk.opentelemetry.profiler.events.EventPeriods) StackSerializer(com.splunk.opentelemetry.profiler.util.StackSerializer) Config(io.opentelemetry.instrumentation.api.config.Config) RecordedEvent(jdk.jfr.consumer.RecordedEvent) AtomicReference(java.util.concurrent.atomic.AtomicReference) LogProcessor(io.opentelemetry.sdk.logs.LogProcessor) SpanContextualizer(com.splunk.opentelemetry.profiler.context.SpanContextualizer) Test(org.junit.jupiter.api.Test)

Example 5 with EventPeriods

use of com.splunk.opentelemetry.profiler.events.EventPeriods in project splunk-otel-java by signalfx.

the class JfrActivator method activateJfrAndRunForever.

private void activateJfrAndRunForever(Config config, Resource resource) {
    // can't be null, default value is set in Configuration.getProperties
    Duration recordingDuration = config.getDuration(CONFIG_KEY_RECORDING_DURATION, null);
    Path outputDir = Paths.get(config.getString(CONFIG_KEY_PROFILER_DIRECTORY));
    RecordingFileNamingConvention namingConvention = new RecordingFileNamingConvention(outputDir);
    RecordingEscapeHatch recordingEscapeHatch = RecordingEscapeHatch.builder().namingConvention(namingConvention).configKeepsFilesOnDisk(keepFiles(config)).recordingDuration(recordingDuration).build();
    Map<String, String> jfrSettings = buildJfrSettings(config);
    RecordedEventStream.Factory recordedEventStreamFactory = () -> new BasicJfrRecordingFile(JFR.instance);
    SpanContextualizer spanContextualizer = new SpanContextualizer();
    EventPeriods periods = new EventPeriods(jfrSettings::get);
    LogDataCommonAttributes commonAttributes = new LogDataCommonAttributes(periods);
    LogExporter logsExporter = LogExporterBuilder.fromConfig(config);
    ScheduledExecutorService exportExecutorService = HelpfulExecutors.newSingleThreadedScheduledExecutor("Batched Logs Exporter");
    BatchingLogsProcessor batchingLogsProcessor = BatchingLogsProcessor.builder().maxTimeBetweenBatches(MAX_TIME_BETWEEN_BATCHES).maxBatchSize(MAX_BATCH_SIZE).batchAction(logsExporter).executorService(exportExecutorService).build();
    batchingLogsProcessor.start();
    LogDataCreator logDataCreator = new LogDataCreator(commonAttributes, resource);
    StackToSpanLinkageProcessor processor = new StackToSpanLinkageProcessor(logDataCreator, batchingLogsProcessor);
    ThreadDumpProcessor threadDumpProcessor = buildThreadDumpProcessor(spanContextualizer, processor, buildStackTraceFilter(config), config);
    TLABProcessor tlabProcessor = TLABProcessor.builder(config).logProcessor(batchingLogsProcessor).commonAttributes(commonAttributes).resource(resource).spanContextualizer(spanContextualizer).build();
    EventProcessingChain eventProcessingChain = new EventProcessingChain(spanContextualizer, threadDumpProcessor, tlabProcessor);
    Consumer<Path> deleter = buildFileDeleter(config);
    JfrDirCleanup dirCleanup = new JfrDirCleanup(deleter);
    Consumer<Path> onFileFinished = buildOnFileFinished(deleter, dirCleanup);
    JfrPathHandler jfrPathHandler = JfrPathHandler.builder().recordedEventStreamFactory(recordedEventStreamFactory).eventProcessingChain(eventProcessingChain).onFileFinished(onFileFinished).build();
    Consumer<Path> onNewRecording = buildOnNewRecording(jfrPathHandler, dirCleanup);
    JfrRecorder recorder = JfrRecorder.builder().settings(jfrSettings).maxAgeDuration(recordingDuration.multipliedBy(10)).jfr(JFR.instance).namingConvention(namingConvention).onNewRecordingFile(onNewRecording).build();
    RecordingSequencer sequencer = RecordingSequencer.builder().recordingDuration(recordingDuration).recordingEscapeHatch(recordingEscapeHatch).recorder(recorder).build();
    sequencer.start();
    dirCleanup.registerShutdownHook();
}
Also used : EventPeriods(com.splunk.opentelemetry.profiler.events.EventPeriods) SpanContextualizer(com.splunk.opentelemetry.profiler.context.SpanContextualizer) Path(java.nio.file.Path) BatchingLogsProcessor(com.splunk.opentelemetry.logs.BatchingLogsProcessor) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Duration(java.time.Duration) LogExporter(io.opentelemetry.sdk.logs.export.LogExporter)

Aggregations

EventPeriods (com.splunk.opentelemetry.profiler.events.EventPeriods)5 Test (org.junit.jupiter.api.Test)4 SpanContextualizer (com.splunk.opentelemetry.profiler.context.SpanContextualizer)3 SpanLinkage (com.splunk.opentelemetry.profiler.context.SpanLinkage)3 SpanContext (io.opentelemetry.api.trace.SpanContext)3 LogData (io.opentelemetry.sdk.logs.data.LogData)3 Resource (io.opentelemetry.sdk.resources.Resource)3 Instant (java.time.Instant)3 EventType (jdk.jfr.EventType)3 RecordedEvent (jdk.jfr.consumer.RecordedEvent)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 StackSerializer (com.splunk.opentelemetry.profiler.util.StackSerializer)2 AttributeKey (io.opentelemetry.api.common.AttributeKey)2 Attributes (io.opentelemetry.api.common.Attributes)2