Package codes.grow.packages.betterstack
Class BetterStackConfig
java.lang.Object
codes.grow.packages.betterstack.BetterStackConfig
Immutable configuration of a
BetterStackClient (SPEC section 2.2).
Better Stack Logs has two hosts with separate credentials:
- the source's ingesting host (
url(), for examples1234.eu-nbg-2.betterstackdata.com) with the source token (Authorization: Bearer) - the SQL query host (
queryUrl(), ClickHouse HTTP interface, for exampleeu-nbg-2-connect.betterstackdata.com) with the username and password of a connection (HTTP Basic)
Each set is all-or-nothing and at least one must be complete. A value without ://
becomes https://value; trailing slashes are removed. There is no default ingesting host.
Build one with builder() or read it from the environment with fromEnv().
Precedence: explicit builder value > GROW_BETTER_STACK_LOGS_<NAME> > vendor
variables (BETTERSTACK_*) > default. toString() never prints credentials.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder of the configuration. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final PatternCollection (table) names are identifiers: they cannot be bound as SQL parameters.Vendor variables read forqueryPassword.Vendor variables read forqueryUrl, in order.Vendor variables read forqueryUsername.Vendor variables read forsourceTable.Vendor variables read forsourceToken.Vendor variables read forurlafterGROW_BETTER_STACK_LOGS_URL, in order. -
Method Summary
Modifier and TypeMethodDescriptionReturns base64(username:password) for HTTP Basic.static BetterStackConfig.Builderbuilder()Starts an empty builder (every field at its default).Returns the connect timeout.encoding()Returns the ingest body encoding (defaultIngestEncoding.JSON).static BetterStackConfigfromEnv()Reads the configuration from the process environment.static BetterStackConfigReads the configuration from an explicit variable map (tests).booleanWhether the ingest side (urlandsourceToken) is configured.booleanhasQuery()Whether the SQL query side (queryUrl,queryUsernameandqueryPassword) is configured.headers()Returns the extra request headers.hooks()Returns the hooks.Transport settings of the ingest side (baseUrl=url()).static booleanWhethersis a safe ClickHouse identifier (^[A-Za-z_][A-Za-z0-9_]*$), the rule for collections (source tables).Credential values to redact from error messages and logs (source token, query password and the Basic credential).logger()Returns the logger.static StringnormalizeBaseUrl(String value) Normalizes a host or URL: a value containing://is used as given, a barehost[:port]becomeshttps://host[:port]; trailing slashes are removed.proxy()Returns the explicit proxy URL.Returns the SQL connection password.Transport settings of the SQL query side (baseUrl=queryUrl()).queryUrl()Returns the SQL query base URL.Returns the SQL connection username.Returns the per-attempt timeout.retry()Returns the retry policy.Returns the default collection (t1234_myapp) used bysearch,searchLogs,tailandping.Returns the source token.tls()Returns the TLS options.Returns a builder pre-filled with this configuration.toString()Returns the total timeout per call including retries.url()Returns the ingest base URL (the source's ingesting host).Returns the user agent suffix.voidvalidate()Checks the credential sets, URLs, the source table, timeouts, TLS and proxy.
-
Field Details
-
IDENTIFIER_PATTERN
Collection (table) names are identifiers: they cannot be bound as SQL parameters. -
URL_VENDOR_VARS
Vendor variables read forurlafterGROW_BETTER_STACK_LOGS_URL, in order. -
SOURCE_TOKEN_VENDOR_VARS
Vendor variables read forsourceToken. -
QUERY_URL_VENDOR_VARS
Vendor variables read forqueryUrl, in order. -
QUERY_USERNAME_VENDOR_VARS
Vendor variables read forqueryUsername. -
QUERY_PASSWORD_VENDOR_VARS
Vendor variables read forqueryPassword. -
SOURCE_TABLE_VENDOR_VARS
Vendor variables read forsourceTable.
-
-
Method Details
-
normalizeBaseUrl
Normalizes a host or URL: a value containing://is used as given, a barehost[:port]becomeshttps://host[:port]; trailing slashes are removed.- Parameters:
value- host or URL, may be null- Returns:
- the base URL, or
nullfor blank input
-
isValidIdentifier
Whethersis a safe ClickHouse identifier (^[A-Za-z_][A-Za-z0-9_]*$), the rule for collections (source tables).- Parameters:
s- text- Returns:
- true when valid
-
builder
Starts an empty builder (every field at its default).- Returns:
- a new 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) or neither credential set is complete
-
fromEnv
Reads the configuration from an explicit variable map (tests).- Parameters:
env- variable map- Returns:
- the validated configuration
-
hasIngest
public boolean hasIngest()Whether the ingest side (urlandsourceToken) is configured.- Returns:
- true with ingest credentials
-
hasQuery
public boolean hasQuery()Whether the SQL query side (queryUrl,queryUsernameandqueryPassword) is configured.- Returns:
- true with query credentials
-
validate
public void validate()Checks the credential sets, URLs, the source table, timeouts, TLS and proxy.- Throws:
ConfigException- when a rule is violated
-
ingestTransportConfig
Transport settings of the ingest side (baseUrl=url()).- Returns:
- the transport configuration
- Throws:
ConfigException- without ingest credentials
-
queryTransportConfig
Transport settings of the SQL query side (baseUrl=queryUrl()).- Returns:
- the transport configuration
- Throws:
ConfigException- without query credentials
-
knownSecrets
Credential values to redact from error messages and logs (source token, query password and the Basic credential).- Returns:
- secret values
-
basicCredentials
Returns base64(username:password) for HTTP Basic.- Returns:
- the credential, or empty without query credentials
-
url
Returns the ingest base URL (the source's ingesting host).- Returns:
- the URL, or empty for a query-only client
-
sourceToken
Returns the source token.- Returns:
- the token, or empty
-
queryUrl
Returns the SQL query base URL.- Returns:
- the URL, or empty for an ingest-only client
-
queryUsername
Returns the SQL connection username.- Returns:
- the username, or empty
-
queryPassword
Returns the SQL connection password.- Returns:
- the password, or empty
-
sourceTable
Returns the default collection (t1234_myapp) used bysearch,searchLogs,tailandping.- Returns:
- the collection, or empty
-
encoding
Returns the ingest body encoding (defaultIngestEncoding.JSON).- Returns:
- the encoding
-
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
-
toBuilder
Returns a builder pre-filled with this configuration.- Returns:
- a new builder
-
toString
-