Class LokiClient.Builder

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

public static final class LokiClient.Builder extends Object
Builder that configures and creates a client in one chain.
  • Method Details

    • fromEnv

      public LokiClient.Builder fromEnv(EnvReader env)
      Fills unset fields from an environment reader.
      Parameters:
      env - reader, e.g. EnvReader.system()
      Returns:
      this builder
    • url

      public LokiClient.Builder url(String url)
      Sets the endpoint base URL.
      Parameters:
      url - URL
      Returns:
      this builder
    • tenantId

      public LokiClient.Builder tenantId(String tenantId)
      Sets the tenant (X-Scope-OrgID).
      Parameters:
      tenantId - tenant id
      Returns:
      this builder
    • basicAuth

      public LokiClient.Builder basicAuth(String username, String password)
      Sets Basic-auth credentials (gateways, Grafana Cloud).
      Parameters:
      username - user
      password - password or access token
      Returns:
      this builder
    • basicAuth

      public LokiClient.Builder basicAuth(String username, Secret password)
      Sets Basic-auth credentials.
      Parameters:
      username - user
      password - password or access token
      Returns:
      this builder
    • bearerToken

      public LokiClient.Builder bearerToken(String token)
      Sets the Bearer token for gateways.
      Parameters:
      token - token
      Returns:
      this builder
    • bearerToken

      public LokiClient.Builder bearerToken(Secret token)
      Sets the Bearer token for gateways.
      Parameters:
      token - token
      Returns:
      this builder
    • multiTenantQueries

      public LokiClient.Builder multiTenantQueries(boolean allow)
      Allows tenant ids joined with | (multi-tenant queries).
      Parameters:
      allow - whether to allow them
      Returns:
      this builder
    • allowedLabels

      public LokiClient.Builder allowedLabels(List<String> names)
      Sets the cardinality guard allowlist.
      Parameters:
      names - label names
      Returns:
      this builder
    • disableLabelGuard

      public LokiClient.Builder disableLabelGuard(boolean disable)
      Parameters:
      disable - whether to disable it
      Returns:
      this builder
    • connectTimeout

      public LokiClient.Builder connectTimeout(Duration d)
      Sets the connect timeout.
      Parameters:
      d - duration
      Returns:
      this builder
    • requestTimeout

      public LokiClient.Builder requestTimeout(Duration d)
      Sets the per-attempt timeout.
      Parameters:
      d - duration
      Returns:
      this builder
    • totalTimeout

      public LokiClient.Builder totalTimeout(Duration d)
      Sets the total timeout.
      Parameters:
      d - duration
      Returns:
      this builder
    • retry

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

      public LokiClient.Builder tls(TlsOptions tls)
      Sets the TLS options.
      Parameters:
      tls - options
      Returns:
      this builder
    • proxy

      public LokiClient.Builder proxy(String proxy)
      Sets the proxy URL.
      Parameters:
      proxy - URL
      Returns:
      this builder
    • header

      public LokiClient.Builder header(String name, String value)
      Adds a header.
      Parameters:
      name - name
      value - value
      Returns:
      this builder
    • userAgentSuffix

      public LokiClient.Builder userAgentSuffix(String suffix)
      Sets the user agent suffix.
      Parameters:
      suffix - suffix
      Returns:
      this builder
    • hooks

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

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

      public LokiClient build()
      Builds the configuration and the client.
      Returns:
      a new client
      Throws:
      ConfigException - when the configuration is invalid