
com.github.loki4j.client.pipeline.PipelineConfig Maven / Gradle / Ivy
package com.github.loki4j.client.pipeline;
import java.util.function.BiFunction;
import java.util.function.Function;
import com.github.loki4j.client.http.ApacheHttpClient;
import com.github.loki4j.client.http.HttpConfig;
import com.github.loki4j.client.http.JavaHttpClient;
import com.github.loki4j.client.http.Loki4jHttpClient;
import com.github.loki4j.client.util.ByteBufferFactory;
import com.github.loki4j.client.util.Loki4jLogger;
import com.github.loki4j.client.writer.JsonWriter;
import com.github.loki4j.client.writer.ProtobufWriter;
import com.github.loki4j.client.writer.Writer;
/**
* Configuration properties for Loki4j pipeline.
*/
public class PipelineConfig {
public static final WriterFactory json = new WriterFactory(
(capacity, bufferFactory) -> new JsonWriter(capacity),
"application/json");
public static final WriterFactory protobuf = new WriterFactory(
(capacity, bbFactory) -> new ProtobufWriter(capacity, bbFactory),
"application/x-protobuf");
public static final Function defaultHttpClientFactory = cfg ->
(cfg.clientSpecific instanceof HttpConfig.JavaHttpConfig)
? new JavaHttpClient(cfg)
: new ApacheHttpClient(cfg);
public static HttpConfig.Builder apache(int maxConnections, long connectionKeepAliveMs) {
return HttpConfig.builder()
.setClientConfig(new HttpConfig.ApacheHttpConfig(maxConnections, connectionKeepAliveMs));
}
public static HttpConfig.Builder java(long innerThreadsExpirationMs) {
return HttpConfig.builder()
.setClientConfig(new HttpConfig.JavaHttpConfig(innerThreadsExpirationMs));
}
/**
* Name of this pipeline.
*/
public final String name;
/**
* Max number of events to put into a single batch before sending it to Loki.
*/
public final int batchMaxItems;
/**
* Max number of bytes a single batch can contain (as counted by Loki).
* This value should not be greater than server.grpc_server_max_recv_msg_size
* in your Loki config.
*/
public final int batchMaxBytes;
/**
* Max time in milliseconds to keep a batch before sending it to Loki, even if
* max items/bytes limits for this batch are not reached.
*/
public final long batchTimeoutMs;
/**
* If true, log records in batch are sorted by timestamp.
* If false, records will be sent to Loki in arrival order.
* Turn this on if you see 'entry out of order' error from Loki.
*/
public final boolean sortByTime;
/**
* If you use only one label for all log records, you can
* set this flag to true and save some CPU time on grouping records by label.
*/
public final boolean staticLabels;
/**
* Max number of bytes to keep in the send queue.
* When the queue is full, incoming log events are dropped.
*/
public final long sendQueueMaxBytes;
/**
* Max number of attempts to send a batch to Loki before it will be dropped.
* A failed batch send could be retried only in case of ConnectException or 503 status from Loki.
* All other exceptions and 4xx-5xx statuses do not cause a retry in order to avoid duplicates.
*/
public final int maxRetries;
/**
* Time in milliseconds to wait before the next attempt to re-send a failed batch.
*/
public final long retryTimeoutMs;
/**
* Disables retries of batches that Loki responds to with a 429 status code (TooManyRequests).
* This reduces impacts on batches from other tenants, which could end up being delayed or dropped
* due to backoff.
*/
public final boolean dropRateLimitedBatches;
/**
* A timeout for Loki4j threads to sleep if encode or send queues are empty.
* Decreasing this value means lower latency at cost of higher CPU usage.
*/
public final long internalQueuesCheckTimeoutMs;
/**
* Use off-heap memory for storing intermediate data.
*/
public final boolean useDirectBuffers;
/**
* If true, the pipeline will try to send all the remaining events on shutdown,
* so the proper shutdown procedure might take longer.
* Otherwise, the pipeline will drop the unsent events.
*/
public final boolean drainOnStop;
/**
* If true, the pipeline will report its metrics using Micrometer.
*/
public final boolean metricsEnabled;
/**
* A factory for Writer.
*/
public final WriterFactory writerFactory;
/**
* Configuration properties for HTTP clients.
*/
public final HttpConfig httpConfig;
/**
* A factory for HTTP client for sending logs to Loki.
* Argument is a config required for constructing an HTTP client.
*/
public final Function httpClientFactory;
/**
* A factory for an internal logger.
* Argument is a source class to report log messages from.
*/
public final Function
© 2015 - 2025 Weber Informatics LLC | Privacy Policy