mirror of
https://github.com/tiennm99/tjahzi.git
synced 2026-10-19 00:15:24 +00:00
Improved tests. Improved defaults of some of configuration parameters and described them in documentation.
This commit is contained in:
1 parent
7759fae9dd
commit
071b634101
6 files changed
+73
-27
No files matched your search
@@ -68,7 +68,7 @@ This example sets up a root logger with a Loki appender.
|
||||
</Loggers>
|
||||
|
||||
<appenders>
|
||||
<Loki name="Loki">
|
||||
<Loki name="Loki" bufferSizeMegabytes="64">
|
||||
<host>${sys:loki.host}</host>
|
||||
<port>${sys:loki.port}</port>
|
||||
|
||||
@@ -112,7 +112,32 @@ a `X-Scope-OrgID` header when [running Loki in multi-tenant mode](https://grafan
|
||||
#### Label (optional)
|
||||
|
||||
Specify additional labels attached to each log line sent via this appender instance.
|
||||
|
||||
|
||||
#### bufferSizeMegabytes (optional, default = 1MB)
|
||||
|
||||
Size of the `log buffer`. Must be power of two between 1MB and 1GB. See https://github.com/tkowalcz/tjahzi/wiki/Log-buffer-sizing for more explanations.
|
||||
|
||||
#### maxRetries (optional, default = 3)
|
||||
|
||||
Maximum number of retries to perform when delivering log message to Loki. Log buffer data is delivered in order, one batch after
|
||||
the other, so too much retries will block delivery of subsequent log batches (on the other hand if we need to retry many times then
|
||||
next batches will probably fail too).
|
||||
|
||||
#### connectTimeoutMillis (optional, default = 5s)
|
||||
|
||||
This configures socket connect timeout when connecting to Loki. After unsuccessful connection attempt it will continue to retry indefinitely
|
||||
employing exponential backoff (initial backoff = 250ms, maximum backoff = 30s, multiplier = 3).
|
||||
|
||||
#### readTimeoutMillis (optional, default = 60s)
|
||||
|
||||
Sets socket read timeout on Loki connection.
|
||||
|
||||
#### useOffHeapBuffer (optional, default = true)
|
||||
|
||||
Whether Tjahzi should allocate native buffer for `Log buffer` component. We can go into a rabbit hole of divagations what are the
|
||||
implications of this. Most important in our view is that having 10s or 100s of MB of space taken out of heap is not very
|
||||
friendly to garbage collector which might have to occasionally copy it around.
|
||||
|
||||
# LICENSE
|
||||
|
||||
This work is released under MIT license. Feel free to use, copy and modify this work as long as you credit original authors.
|
||||
|
||||
@@ -54,13 +54,13 @@ public class LokiAppender extends AbstractAppender {
|
||||
private int port;
|
||||
|
||||
@PluginBuilderAttribute
|
||||
private int connectTimeoutMillis = 0;
|
||||
private int connectTimeoutMillis = 5000;
|
||||
|
||||
@PluginBuilderAttribute
|
||||
private int readTimeoutMillis = 0;
|
||||
private int readTimeoutMillis = 60_000;
|
||||
|
||||
@PluginBuilderAttribute
|
||||
private int maxRetries = 0;
|
||||
private int maxRetries = 3;
|
||||
|
||||
@PluginBuilderAttribute
|
||||
private int bufferSizeMegabytes = 32;
|
||||
|
||||
+19
-21
@@ -3,10 +3,6 @@ package pl.tkowalcz.tjahzi.log4j2;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.core.LoggerContext;
|
||||
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 java.net.URI;
|
||||
@@ -17,27 +13,29 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@Testcontainers
|
||||
class BufferSizeConfigurationTest {
|
||||
|
||||
@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
|
||||
void shouldSendData() throws URISyntaxException {
|
||||
void shouldUseDefaultWhenLogBufferSizeIsNotSetViaConfiguration() throws URISyntaxException {
|
||||
// Given
|
||||
System.setProperty("loki.host", loki.getHost());
|
||||
System.setProperty("loki.port", loki.getFirstMappedPort().toString());
|
||||
|
||||
URI uri = getClass()
|
||||
.getClassLoader()
|
||||
.getResource("appender-test-with-custom-settings-log4j2-configuration.xml")
|
||||
.getResource("appender-test-with-buffer-size-megabytes-unset.xml")
|
||||
.toURI();
|
||||
|
||||
// When
|
||||
LoggerContext context = (LoggerContext) LogManager.getContext(false);
|
||||
context.setConfigLocation(uri);
|
||||
|
||||
// Then
|
||||
LokiAppender loki = context.getConfiguration().getAppender("Loki");
|
||||
assertThat(loki.getLoggingSystem().getLogBufferSize()).isEqualTo(32 * 1024 * 1024);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldSetLogBufferSizeViaConfiguration() throws URISyntaxException {
|
||||
// Given
|
||||
URI uri = getClass()
|
||||
.getClassLoader()
|
||||
.getResource("appender-test-with-buffer-size-megabytes-set-to-64.xml")
|
||||
.toURI();
|
||||
|
||||
// When
|
||||
|
||||
File renamed without changes.
+23
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration status="OFF" shutdownHook="disable" packages="pl.tkowalcz.tjahzi.log4j2">
|
||||
<Loggers>
|
||||
<Root level="INFO">
|
||||
<AppenderRef ref="Loki"/>
|
||||
</Root>
|
||||
</Loggers>
|
||||
|
||||
<appenders>
|
||||
<Loki name="Loki">
|
||||
<host>${sys:loki.host}</host>
|
||||
<port>${sys:loki.port}</port>
|
||||
|
||||
<ThresholdFilter level="ALL"/>
|
||||
<PatternLayout>
|
||||
<Pattern>%X{tid} [%t] %d{MM-dd HH:mm:ss.SSS} %5p %c{1} - %m%n%exception{full}</Pattern>
|
||||
</PatternLayout>
|
||||
|
||||
<Header name="server" value="127.0.0.1"/>
|
||||
<Label name="server" value="127.0.0.1"/>
|
||||
</Loki>
|
||||
</appenders>
|
||||
</configuration>
|
||||
@@ -4,7 +4,7 @@ public class ClientConfigurationBuilder {
|
||||
|
||||
public static final String DEFAULT_LOG_ENDPOINT = "/loki/api/v1/push";
|
||||
|
||||
public static final int DEFAULT_CONNECT_TIMEOUT_MILLIS = 60_000;
|
||||
public static final int DEFAULT_CONNECT_TIMEOUT_MILLIS = 5_000;
|
||||
public static final int DEFAULT_REQUEST_TIMEOUT_MILLIS = 60_000;
|
||||
|
||||
public static final int DEFAULT_MAX_RETRIES = 0;
|
||||
|
||||
Reference in new issue
Block a user