Class LokiConfig
LokiClient (SPEC section 2.2).
Build one with builder() or read it from the environment with fromEnv().
Precedence: explicit builder value > GROW_GRAFANA_LOKI_<NAME> > vendor variables
> default. toString() never prints credentials.
Loki itself has no authentication: LokiConfig.Builder.tenantId(String) is sent as
X-Scope-OrgID (required by multi-tenant Loki), Basic (username/password) and
Bearer credentials are for gateways and hosted Loki (Grafana Cloud: user = instance id, password
= access token).
| Field | Variables (in order) |
|---|---|
| url | GROW_GRAFANA_LOKI_URL, LOKI_URL |
| tenantId | GROW_GRAFANA_LOKI_TENANT_ID, LOKI_TENANT_ID |
| username | GROW_GRAFANA_LOKI_USERNAME, LOKI_USERNAME,
LOKI_BASIC_AUTH_USER |
| password | GROW_GRAFANA_LOKI_PASSWORD, LOKI_PASSWORD,
LOKI_BASIC_AUTH_PASSWORD |
| bearerToken | GROW_GRAFANA_LOKI_BEARER_TOKEN,
LOKI_BEARER_TOKEN |
plus the common CONNECT_TIMEOUT, REQUEST_TIMEOUT, TOTAL_TIMEOUT,
MAX_RETRIES, CA_CERT, CLIENT_CERT, CLIENT_KEY,
INSECURE_SKIP_VERIFY and PROXY after the GROW_GRAFANA_LOKI_ prefix.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder of the configuration. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDefault endpoint (the stack catalog port 3100).static final intLongest tenant id Loki accepts, in bytes. -
Method Summary
Modifier and TypeMethodDescriptionReturns the cardinality guard allowlist: label names that may become index labels.Returns theAuthorizationheader value when credentials are configured.Returns the Bearer token for gateways.static LokiConfig.Builderbuilder()Starts an empty builder (every field at its default).Returns the connect timeout.booleanReturns whetherLokiClient.push(java.util.List<codes.grow.packages.loki.LokiStream>)sends every stream label as an index label.static LokiConfigfromEnv()Reads the configuration from the process environment.static LokiConfigReads the configuration from an explicit variable map (tests).headers()Returns the extra request headers.hooks()Returns the hooks.Returns the credential values that are removed from error messages and logs.logger()Returns the logger.booleanReturns whether tenant ids joined with|(multi-tenant queries) are allowed.password()Returns the Basic-auth password (or Grafana Cloud access token).proxy()Returns the explicit proxy URL.Returns the per-attempt timeout.retry()Returns the retry policy.tenantId()Returns the tenant sent asX-Scope-OrgID.tenantIdProblem(String id, boolean multiTenantQueries) Returns the problem with a tenant id (X-Scope-OrgID), or empty when it is valid.tls()Returns the TLS options.Starts a builder holding every field of this configuration.toString()Returns the total timeout per call including retries.Translates the common fields into transport settings.url()Returns the endpoint base URL.Returns the user agent suffix.username()Returns the Basic-auth user.voidvalidate()Checks URL scheme, positive timeouts, TLS pairs, the tenant id and the credential rules.
-
Field Details
-
DEFAULT_URL
Default endpoint (the stack catalog port 3100).- See Also:
-
MAX_TENANT_ID_LENGTH
public static final int MAX_TENANT_ID_LENGTHLongest tenant id Loki accepts, in bytes.- See Also:
-
-
Method Details
-
builder
Starts an empty builder (every field at its default).- Returns:
- a new builder
-
toBuilder
Starts a builder holding every field of this configuration.- Returns:
- a pre-filled builder
-
fromEnv
Reads the configuration from the process environment.- Returns:
- the validated configuration
- Throws:
ConfigException- when a variable holds an invalid value (the message names the variable, never the value)
-
fromEnv
Reads the configuration from an explicit variable map (tests).- Parameters:
env- variable map- Returns:
- the validated configuration
-
tenantIdProblem
Returns the problem with a tenant id (X-Scope-OrgID), or empty when it is valid.Loki rules: non-empty, at most 150 bytes, not
.or.., only[A-Za-z0-9!-_.*'()]. A|(multi-tenant query) is accepted only whenmultiTenantQueriesis set, and every part must then be valid.- Parameters:
id- tenant idmultiTenantQueries- whethera|bids are allowed- Returns:
- the problem, or empty
-
validate
public void validate()Checks URL scheme, positive timeouts, TLS pairs, the tenant id and the credential rules.- Throws:
ConfigException- when a rule is violated
-
toTransportConfig
Translates the common fields into transport settings.- Returns:
- the transport configuration
-
authorizationHeader
Returns theAuthorizationheader value when credentials are configured.- Returns:
Bearer …orBasic …, or empty
-
knownSecrets
Returns the credential values that are removed from error messages and logs.- Returns:
- secret values (password, token, encoded Basic credentials)
-
url
Returns the endpoint base URL.- Returns:
- the URL
-
tenantId
Returns the tenant sent asX-Scope-OrgID.- Returns:
- the tenant id, or empty (no header)
-
username
Returns the Basic-auth user.- Returns:
- the user, or empty
-
password
Returns the Basic-auth password (or Grafana Cloud access token).- Returns:
- the password, or empty
-
bearerToken
Returns the Bearer token for gateways.- Returns:
- the token, or empty
-
multiTenantQueries
public boolean multiTenantQueries()Returns whether tenant ids joined with|(multi-tenant queries) are allowed.- Returns:
- true when allowed
-
allowedLabels
Returns the cardinality guard allowlist: label names that may become index labels.- Returns:
- the configured list, or
Labels.DEFAULT_ALLOWED_LABELS
-
disableLabelGuard
public boolean disableLabelGuard()Returns whetherLokiClient.push(java.util.List<codes.grow.packages.loki.LokiStream>)sends every stream label as an index label.- Returns:
- true when the guard is off for
push(the log exporter always applies it)
-
connectTimeout
Returns the connect timeout.- Returns:
- the timeout
-
requestTimeout
Returns the per-attempt timeout.- Returns:
- the timeout
-
totalTimeout
Returns the total timeout per call including retries.- Returns:
- the timeout
-
retry
Returns the retry policy.- Returns:
- the policy
-
tls
Returns the TLS options.- Returns:
- the options
-
proxy
Returns the explicit proxy URL.- Returns:
- the proxy, or empty
-
headers
Returns the extra request headers.- Returns:
- immutable map
-
userAgentSuffix
Returns the user agent suffix.- Returns:
- the suffix, or empty
-
hooks
Returns the hooks.- Returns:
- the hooks
-
logger
Returns the logger.- Returns:
- the logger
-
toString
-