Class CloudWatchLogsConfig

java.lang.Object
codes.grow.packages.cloudwatchlogs.CloudWatchLogsConfig

public final class CloudWatchLogsConfig extends Object
Immutable configuration of a CloudWatchLogsClient (SPEC section 2.2, API.md section 5).

Build one with builder() or read it from the environment with fromEnv(). Precedence: explicit builder value > GROW_AWS_CLOUDWATCH_LOGS_<NAME> > standard AWS / CloudWatch variables (AWS_ENDPOINT_URL_CLOUDWATCH_LOGS, AWS_REGION, AWS_ACCESS_KEY_ID, CLOUDWATCH_LOG_GROUP, …) > default. Credentials left unset use the AWS SDK default chain. toString() never prints credentials.

  • Field Details

    • DEFAULT_MAX_EVENT_BYTES

      public static final int DEFAULT_MAX_EVENT_BYTES
      Default per-event message limit in UTF-8 bytes (256 KiB).
      See Also:
    • MAX_EVENT_BYTES_HARD_CAP

      public static final int MAX_EVENT_BYTES_HARD_CAP
      Largest message PutLogEvents accepts: 1 MiB minus the 26 bytes AWS counts per event.
      See Also:
    • DEFAULT_ROLE_SESSION_NAME

      public static final String DEFAULT_ROLE_SESSION_NAME
      Default STS role session name used with roleArn.
      See Also:
    • API_VERSION

      public static final String API_VERSION
      CloudWatch Logs API version.
      See Also:
  • Method Details

    • isValidLogGroupName

      public static boolean isValidLogGroupName(String name)
      Returns whether name is a valid log group name (1–512 of [.-_/#A-Za-z0-9]).
      Parameters:
      name - candidate name
      Returns:
      true when valid
    • isValidLogStreamName

      public static boolean isValidLogStreamName(String name)
      Returns whether name is a valid log stream name (1–512 characters, no : or *).
      Parameters:
      name - candidate name
      Returns:
      true when valid
    • defaultLogStreamName

      public static String defaultLogStreamName()
      Default stream name <hostname>-<pid>-<random6> (characters outside the allowed set become -).
      Returns:
      a new stream name
    • builder

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

      public static CloudWatchLogsConfig 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 CloudWatchLogsConfig fromEnv(Map<String,String> env)
      Reads the configuration from an explicit variable map (tests).
      Parameters:
      env - variable map
      Returns:
      the validated configuration
    • toBuilder

      public CloudWatchLogsConfig.Builder toBuilder()
      Returns a builder holding every value of this configuration.
      Returns:
      a new builder
    • validate

      public void validate()
      Checks every rule (URL, timeouts, TLS, credential pairs, names, limits).
      Throws:
      ConfigException - when a rule is violated (all problems in one message)
    • toTransportConfig

      public TransportConfig toTransportConfig()
      Translates the common fields into transport settings (used by the Grow HTTP client of the AWS SDK).
      Returns:
      the transport configuration
    • knownSecrets

      public List<String> knownSecrets()
      Credential values to redact from error messages and logs.
      Returns:
      the live secret values
    • url

      public String url()
      Effective endpoint: endpoint() when set, otherwise the public AWS endpoint of region() (us-east-1 when the region is left to the SDK). Informational.
      Returns:
      the URL
    • endpoint

      public Optional<String> endpoint()
      Returns the explicit endpoint override passed to the AWS SDK.
      Returns:
      the endpoint, or empty when the SDK resolves it
    • connectTimeout

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

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

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

      public RetryPolicy retry()
      Returns the retry policy (maxAttempts = maxRetries + 1 in the SDK standard mode).
      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
    • region

      public Optional<String> region()
      Returns the AWS region.
      Returns:
      the region, or empty (SDK chain: environment, profile)
    • accessKeyId

      public Optional<String> accessKeyId()
      Returns the access key id.
      Returns:
      the key id, or empty
    • secretAccessKey

      public Optional<Secret> secretAccessKey()
      Returns the secret access key.
      Returns:
      the secret, or empty
    • sessionToken

      public Optional<Secret> sessionToken()
      Returns the session token.
      Returns:
      the token, or empty
    • profile

      public Optional<String> profile()
      Returns the shared config profile.
      Returns:
      the profile, or empty
    • credentialsProvider

      public Optional<software.amazon.awssdk.auth.credentials.AwsCredentialsProvider> credentialsProvider()
      Returns the explicit AWS credentials provider.
      Returns:
      the provider, or empty
    • roleArn

      public Optional<String> roleArn()
      Returns the role assumed with STS.
      Returns:
      the role ARN, or empty
    • roleSessionName

      public String roleSessionName()
      Returns the STS session name (default grow-sdk).
      Returns:
      the session name
    • externalId

      public Optional<String> externalId()
      Returns the STS external id.
      Returns:
      the external id, or empty
    • logGroup

      public Optional<String> logGroup()
      Returns the default log group of the log client and the query client.
      Returns:
      the group, or empty
    • logStream

      public String logStream()
      Returns the log stream of the log client (default <hostname>-<pid>-<random6>).
      Returns:
      the stream name
    • accountId

      public Optional<String> accountId()
      Returns the AWS account id used to build log group ARNs for live tail.
      Returns:
      the account id, or empty (looked up with DescribeLogGroups)
    • maxEventBytes

      public int maxEventBytes()
      Returns the per-event message limit in UTF-8 bytes (default 262 144).
      Returns:
      the limit
    • oversizePolicy

      public OversizePolicy oversizePolicy()
      Returns the policy for oversized events (default OversizePolicy.TRUNCATE).
      Returns:
      the policy
    • autoCreate

      public boolean autoCreate()
      Returns whether putLogEvents creates a missing log stream (default true).
      Returns:
      the flag
    • sdkClient

      public Optional<software.amazon.awssdk.services.cloudwatchlogs.CloudWatchLogsAsyncClient> sdkClient()
      Returns the caller-supplied AWS SDK client.
      Returns:
      the client, or empty
    • toString

      public String toString()
      Overrides:
      toString in class Object