Package codes.grow.packages.graylog
Class GraylogConfig
java.lang.Object
codes.grow.packages.graylog.GraylogConfig
Immutable configuration of a
GraylogClient (SPEC section 2.2).
Build one with builder() or read it from the environment with fromEnv().
Precedence: explicit builder value > GROW_GRAYLOG_<NAME> > vendor variables (
GRAYLOG_*) > platform stack aliases (GRAYLOG_HOST, GRAYLOG_PORT,
GRAYLOG_TRANSPORT) > default. toString() never prints credentials.
REST credentials: an API token (sent as HTTP Basic <token>:token) wins over username
and password. The GELF fields configure the ingest transports of GraylogClient.logClient(GraylogLogClientOptions): unset values default to the host of url(), TCP, port 12201 (12202 for HTTP, see gelfPortFor(GelfProtocol)) and
http://<gelfHost>:<port>/gelf (see gelfHttpEndpoint()).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder of the configuration. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault GELF HTTP port (Graylog has no fixed one; 12202 is the common choice).static final intDefault GELF UDP and TCP port.static final GelfProtocolDefault GELF protocol.static final intDefault port of the OpenTelemetry (gRPC) input.static final StringDefaultX-Requested-Byvalue (Graylog requires it on every non-GET request).static final StringDefault REST endpoint. -
Method Summary
Modifier and TypeMethodDescriptionapiToken()Returns the Graylog access token.static GraylogConfig.Builderbuilder()Starts an empty builder (every field at its default).Returns the connect timeout.static GraylogConfigfromEnv()Reads the configuration from the process environment.static GraylogConfigReads the configuration from an explicit variable map (tests).gelfHost()Returns the host of the GELF inputs: the configured value, else the host ofurl().Returns the effective GELF HTTP URL:gelfHttpUrl()when set, elsehttp(s)://<gelfHost>:<gelfPortFor(HTTP)>/gelf(https withgelfTls()).Returns the explicitly configured GELF HTTP URL.gelfPort()Returns the explicitly configured GELF port.intgelfPortFor(GelfProtocol protocol) Returns the GELF port used forprotocol: the configured port when set, else 12202 for HTTP and 12201 otherwise.Returns the GELF protocol of new log clients (default TCP).booleangelfTls()Returns whether the GELF TCP transport uses TLS and the default GELF HTTP URL uses https.headers()Returns the extra request headers.hooks()Returns the hooks.logger()Returns the logger.Returns the explicitly configured OTLP/gRPC endpoint.Returns the effective OTLP/gRPC endpoint:otlpEndpoint()when set, elsehttp://<gelfHost>:4317.password()Returns the HTTP Basic password.proxy()Returns the explicit proxy URL.Returns theX-Requested-Byvalue of non-GET requests.Returns the per-attempt timeout.retry()Returns the retry policy.tls()Returns the TLS options.Returns a builder pre-filled with this configuration.toString()Returns the total timeout per call including retries.Translates the common fields into transport settings (credentials are added per request).url()Returns the REST base URL.Returns the user agent suffix.username()Returns the HTTP Basic username.voidvalidate()Checks URLs, timeouts, TLS pairs, the GELF settings and the credentials.
-
Field Details
-
DEFAULT_URL
Default REST endpoint.- See Also:
-
DEFAULT_GELF_PORT
public static final int DEFAULT_GELF_PORTDefault GELF UDP and TCP port.- See Also:
-
DEFAULT_GELF_HTTP_PORT
public static final int DEFAULT_GELF_HTTP_PORTDefault GELF HTTP port (Graylog has no fixed one; 12202 is the common choice).- See Also:
-
DEFAULT_OTLP_GRPC_PORT
public static final int DEFAULT_OTLP_GRPC_PORTDefault port of the OpenTelemetry (gRPC) input.- See Also:
-
DEFAULT_REQUESTED_BY
DefaultX-Requested-Byvalue (Graylog requires it on every non-GET request).- See Also:
-
DEFAULT_GELF_PROTOCOL
Default GELF protocol.
-
-
Method Details
-
builder
Starts an empty builder (every field at its default).- Returns:
- a new builder
-
toBuilder
Returns a builder pre-filled with this configuration.- 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)
-
fromEnv
Reads the configuration from an explicit variable map (tests).- Parameters:
env- variable map- Returns:
- the validated configuration
-
validate
public void validate()Checks URLs, timeouts, TLS pairs, the GELF settings and the credentials.- Throws:
ConfigException- when a rule is violated
-
toTransportConfig
Translates the common fields into transport settings (credentials are added per request).- Returns:
- the transport configuration
-
url
Returns the REST base URL.- Returns:
- the URL
-
apiToken
Returns the Graylog access token.- Returns:
- the token, or empty
-
username
Returns the HTTP Basic username.- Returns:
- the username, or empty
-
password
Returns the HTTP Basic password.- Returns:
- the password, or empty
-
gelfHost
Returns the host of the GELF inputs: the configured value, else the host ofurl().- Returns:
- the host
-
gelfPort
Returns the explicitly configured GELF port.- Returns:
- the port, or empty for the protocol default
-
gelfPortFor
Returns the GELF port used forprotocol: the configured port when set, else 12202 for HTTP and 12201 otherwise.- Parameters:
protocol- the GELF protocol- Returns:
- the port
-
gelfProtocol
Returns the GELF protocol of new log clients (default TCP).- Returns:
- the protocol
-
gelfHttpUrl
Returns the explicitly configured GELF HTTP URL.- Returns:
- the URL, or empty
-
gelfHttpEndpoint
Returns the effective GELF HTTP URL:gelfHttpUrl()when set, elsehttp(s)://<gelfHost>:<gelfPortFor(HTTP)>/gelf(https withgelfTls()).- Returns:
- the URL
-
gelfTls
public boolean gelfTls()Returns whether the GELF TCP transport uses TLS and the default GELF HTTP URL uses https.- Returns:
- true when enabled
-
otlpEndpoint
Returns the explicitly configured OTLP/gRPC endpoint.- Returns:
- the endpoint, or empty
-
otlpGrpcEndpoint
Returns the effective OTLP/gRPC endpoint:otlpEndpoint()when set, elsehttp://<gelfHost>:4317.- Returns:
- the endpoint
-
requestedBy
Returns theX-Requested-Byvalue of non-GET requests.- Returns:
- the value
-
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
-