-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re #5: Some cleanups. Also added experimental test that records alloc…
…ations - results are mind blowing. Some improvements based on that test.
- Loading branch information
Showing
9 changed files
with
142 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
loki-log4j2-appender/src/test/java/pl/tkowalcz/tjahzi/log4j2/AllocationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package pl.tkowalcz.tjahzi.log4j2; | ||
|
||
import com.google.monitoring.runtime.instrumentation.AllocationRecorder; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.junit.jupiter.api.Disabled; | ||
import org.junit.jupiter.api.Test; | ||
import org.testcontainers.containers.BindMode; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.containers.wait.strategy.Wait; | ||
import org.testcontainers.junit.jupiter.Container; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
import org.testcontainers.shaded.com.google.common.util.concurrent.Uninterruptibles; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
|
||
@Testcontainers | ||
public class AllocationTest { | ||
|
||
@Container | ||
public GenericContainer loki = new GenericContainer("grafana/loki:latest") | ||
.withCommand("-config.file=/etc/loki-config.yaml") | ||
.withClasspathResourceMapping("loki-config.yaml", | ||
"/etc/loki-config.yaml", | ||
BindMode.READ_ONLY) | ||
.waitingFor( | ||
Wait.forHttp("/ready") | ||
.forPort(3100) | ||
) | ||
.withExposedPorts(3100); | ||
|
||
@Test | ||
@Disabled | ||
void shouldSendData() throws URISyntaxException { | ||
AtomicLong allocatedMemory = new AtomicLong(); | ||
Runtime.getRuntime().addShutdownHook(new Thread(() -> System.out.println("allocatedMemory = " + allocatedMemory))); | ||
|
||
// Given | ||
System.setProperty("loki.host", loki.getHost()); | ||
System.setProperty("loki.port", loki.getFirstMappedPort().toString()); | ||
|
||
URI uri = getClass() | ||
.getClassLoader() | ||
.getResource("basic-appender-test-log4j2-configuration.xml") | ||
.toURI(); | ||
|
||
((org.apache.logging.log4j.core.LoggerContext) LogManager.getContext(false)) | ||
.setConfigLocation(uri); | ||
|
||
String logLine = "Cupcake ipsum dolor sit amet cake wafer. " + | ||
"Souffle jelly beans biscuit topping. " + | ||
"Danish bonbon gummies powder caramels. "; | ||
|
||
Logger logger = LogManager.getLogger(pl.tkowalcz.tjahzi.log4j2.LokiAppenderTest.class); | ||
|
||
// When | ||
for (int i = 0; i < 1000; i++) { | ||
logger.info(logLine); | ||
Uninterruptibles.sleepUninterruptibly(10, TimeUnit.MILLISECONDS); | ||
} | ||
|
||
AllocationRecorder.addSampler((count, desc, newObj, size) -> { | ||
if (!desc.startsWith("java/time")) { | ||
allocatedMemory.addAndGet(size); | ||
} | ||
}); | ||
|
||
for (int i = 0; i < 1000; i++) { | ||
logger.info(logLine); | ||
Uninterruptibles.sleepUninterruptibly(10, TimeUnit.MILLISECONDS); | ||
} | ||
|
||
// Then | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters