Class LokiConfig.Builder

java.lang.Object
codes.grow.packages.loki.LokiConfig.Builder
Enclosing class:
LokiConfig

public static final class LokiConfig.Builder extends Object
Builder of the configuration.

Unset fields take the environment (when fromEnv(EnvReader) is called) or the default.

  • Method Details

    • fromEnv

      public LokiConfig.Builder fromEnv(EnvReader env)
      Fills every field that was not set explicitly from the environment.
      Parameters:
      env - environment reader
      Returns:
      this builder
      Throws:
      ConfigException - when a variable holds an invalid value
    • url

      public LokiConfig.Builder url(String url)
      Sets the endpoint base URL (default http://127.0.0.1:3100).
      Parameters:
      url - http or https URL; a base path (reverse proxy) is kept
      Returns:
      this builder
    • tenantId

      public LokiConfig.Builder tenantId(String tenantId)
      Sets the tenant sent as X-Scope-OrgID on every request and tail handshake.
      Parameters:
      tenantId - tenant id (null or empty sends no header)
      Returns:
      this builder
    • username

      public LokiConfig.Builder username(String username)
      Sets the Basic-auth user (gateways, Grafana Cloud instance id).
      Parameters:
      username - user
      Returns:
      this builder
    • password

      public LokiConfig.Builder password(Secret password)
      Sets the Basic-auth password (or Grafana Cloud access token).
      Parameters:
      password - password
      Returns:
      this builder
    • password

      public LokiConfig.Builder password(String password)
      Sets the Basic-auth password.
      Parameters:
      password - password
      Returns:
      this builder
    • bearerToken

      public LokiConfig.Builder bearerToken(Secret token)
      Sets the Bearer token sent to a gateway (Authorization: Bearer …).
      Parameters:
      token - token
      Returns:
      this builder
    • bearerToken

      public LokiConfig.Builder bearerToken(String token)
      Sets the Bearer token.
      Parameters:
      token - token
      Returns:
      this builder
    • multiTenantQueries

      public LokiConfig.Builder multiTenantQueries(boolean allow)
      Allows tenant ids joined with | (Loki's multi-tenant query syntax; the server must enable multi_tenant_queries_enabled).
      Parameters:
      allow - whether to allow them (default false)
      Returns:
      this builder
    • allowedLabels

      public LokiConfig.Builder allowedLabels(List<String> names)
      Sets the cardinality guard allowlist (label names that may become index labels; everything else goes to structured metadata).
      Parameters:
      names - label names, or null for Labels.DEFAULT_ALLOWED_LABELS
      Returns:
      this builder
    • disableLabelGuard

      public LokiConfig.Builder disableLabelGuard(boolean disable)
      Sends every label of LokiClient.push(java.util.List<codes.grow.packages.loki.LokiStream>) streams as an index label (the guard is still applied by the log exporter).
      Parameters:
      disable - whether to disable the guard for push (default false)
      Returns:
      this builder
    • connectTimeout

      public LokiConfig.Builder connectTimeout(Duration d)
      Sets the connect timeout (default 10 s).
      Parameters:
      d - positive duration
      Returns:
      this builder
    • requestTimeout

      public LokiConfig.Builder requestTimeout(Duration d)
      Sets the per-attempt timeout (default 30 s).
      Parameters:
      d - positive duration
      Returns:
      this builder
    • totalTimeout

      public LokiConfig.Builder totalTimeout(Duration d)
      Sets the total timeout per call including retries (default 120 s).
      Parameters:
      d - positive duration
      Returns:
      this builder
    • retry

      public LokiConfig.Builder retry(RetryPolicy retry)
      Sets the retry policy (default RetryPolicy.defaults()).
      Parameters:
      retry - policy
      Returns:
      this builder
    • tls

      public LokiConfig.Builder tls(TlsOptions tls)
      Sets the TLS options; environment TLS variables are then ignored.
      Parameters:
      tls - options
      Returns:
      this builder
    • proxy

      public LokiConfig.Builder proxy(String proxy)
      Sets an explicit proxy URL; environment proxies (HTTPS_PROXY) are never used.
      Parameters:
      proxy - proxy URL
      Returns:
      this builder
    • header

      public LokiConfig.Builder header(String name, String value)
      Adds a header sent with every request (and the tail handshake).
      Parameters:
      name - header name
      value - header value
      Returns:
      this builder
    • userAgentSuffix

      public LokiConfig.Builder userAgentSuffix(String suffix)
      Sets the text appended to the User-Agent.
      Parameters:
      suffix - suffix
      Returns:
      this builder
    • hooks

      public LokiConfig.Builder hooks(Hooks hooks)
      Sets request hooks.
      Parameters:
      hooks - hooks
      Returns:
      this builder
    • logger

      public LokiConfig.Builder logger(Logger logger)
      Sets the logger (default silent).
      Parameters:
      logger - logger
      Returns:
      this builder
    • build

      public LokiConfig build()
      Builds and validates the configuration.
      Returns:
      the configuration
      Throws:
      ConfigException - when a rule is violated