use of com.splunk.opentelemetry.profiler.Configuration.CONFIG_KEY_MEMORY_SAMPLER_INTERVAL 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);
}
}
Aggregations