Class GraylogConfig

java.lang.Object
codes.grow.packages.graylog.GraylogConfig

public final class GraylogConfig extends Object
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()).

  • Field Details

    • DEFAULT_URL

      public static final String DEFAULT_URL
      Default REST endpoint.
      See Also:
    • DEFAULT_GELF_PORT

      public static final int DEFAULT_GELF_PORT
      Default GELF UDP and TCP port.
      See Also:
    • DEFAULT_GELF_HTTP_PORT

      public static final int DEFAULT_GELF_HTTP_PORT
      Default 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_PORT
      Default port of the OpenTelemetry (gRPC) input.
      See Also:
    • DEFAULT_REQUESTED_BY

      public static final String DEFAULT_REQUESTED_BY
      Default X-Requested-By value (Graylog requires it on every non-GET request).
      See Also:
    • DEFAULT_GELF_PROTOCOL

      public static final GelfProtocol DEFAULT_GELF_PROTOCOL
      Default GELF protocol.
  • Method Details

    • builder

      public static GraylogConfig.Builder builder()
      Starts an empty builder (every field at its default).
      Returns:
      a new builder
    • toBuilder

      public GraylogConfig.Builder toBuilder()
      Returns a builder pre-filled with this configuration.
      Returns:
      a new builder
    • fromEnv

      public static GraylogConfig 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

      public static GraylogConfig fromEnv(Map<String,String> env)
      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

      public TransportConfig toTransportConfig()
      Translates the common fields into transport settings (credentials are added per request).
      Returns:
      the transport configuration
    • url

      public String url()
      Returns the REST base URL.
      Returns:
      the URL
    • apiToken

      public Optional<Secret> apiToken()
      Returns the Graylog access token.
      Returns:
      the token, or empty
    • username

      public Optional<String> username()
      Returns the HTTP Basic username.
      Returns:
      the username, or empty
    • password

      public Optional<Secret> password()
      Returns the HTTP Basic password.
      Returns:
      the password, or empty
    • gelfHost

      public String gelfHost()
      Returns the host of the GELF inputs: the configured value, else the host of url().
      Returns:
      the host
    • gelfPort

      public OptionalInt gelfPort()
      Returns the explicitly configured GELF port.
      Returns:
      the port, or empty for the protocol default
    • gelfPortFor

      public int gelfPortFor(GelfProtocol protocol)
      Returns the GELF port used for protocol: the configured port when set, else 12202 for HTTP and 12201 otherwise.
      Parameters:
      protocol - the GELF protocol
      Returns:
      the port
    • gelfProtocol

      public GelfProtocol gelfProtocol()
      Returns the GELF protocol of new log clients (default TCP).
      Returns:
      the protocol
    • gelfHttpUrl

      public Optional<String> gelfHttpUrl()
      Returns the explicitly configured GELF HTTP URL.
      Returns:
      the URL, or empty
    • gelfHttpEndpoint

      public String gelfHttpEndpoint()
      Returns the effective GELF HTTP URL: gelfHttpUrl() when set, else http(s)://<gelfHost>:<gelfPortFor(HTTP)>/gelf (https with gelfTls()).
      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

      public Optional<String> otlpEndpoint()
      Returns the explicitly configured OTLP/gRPC endpoint.
      Returns:
      the endpoint, or empty
    • otlpGrpcEndpoint

      public String otlpGrpcEndpoint()
      Returns the effective OTLP/gRPC endpoint: otlpEndpoint() when set, else http://<gelfHost>:4317.
      Returns:
      the endpoint
    • requestedBy

      public String requestedBy()
      Returns the X-Requested-By value of non-GET requests.
      Returns:
      the value
    • connectTimeout

      public Duration connectTimeout()
      Returns the connect timeout.
      Returns:
      the timeout
    • requestTimeout

      public Duration requestTimeout()
      Returns the per-attempt timeout.
      Returns:
      the timeout
    • totalTimeout

      public Duration totalTimeout()
      Returns the total timeout per call including retries.
      Returns:
      the timeout
    • retry

      public RetryPolicy retry()
      Returns the retry policy.
      Returns:
      the policy
    • tls

      public TlsOptions tls()
      Returns the TLS options.
      Returns:
      the options
    • proxy

      public Optional<String> proxy()
      Returns the explicit proxy URL.
      Returns:
      the proxy, or empty
    • headers

      public Map<String,String> headers()
      Returns the extra request headers.
      Returns:
      immutable map
    • userAgentSuffix

      public Optional<String> userAgentSuffix()
      Returns the user agent suffix.
      Returns:
      the suffix, or empty
    • hooks

      public Hooks hooks()
      Returns the hooks.
      Returns:
      the hooks
    • logger

      public Logger logger()
      Returns the logger.
      Returns:
      the logger
    • toString

      public String toString()
      Overrides:
      toString in class Object