Skip to main content

Module google_cloud_logging

Module google_cloud_logging 

Source
Expand description

The google-cloud-logging node — ships access-log entries to Google Cloud Logging in batches.

Ported from APISIX’s google-cloud-logging.lua. On the request path the node builds a log entry (via the shared build_entry) and hands it to a BatchSink. A background task wraps the buffered entries into the Cloud Logging entries:write payload and POSTs them to https://logging.googleapis.com/v2/entries:write with an OAuth2 bearer token. The node passes the context through unchanged.

§Authentication (service-account JWT → OAuth2 access token)

Cloud Logging is called with a short-lived OAuth2 access token obtained via the service-account JWT-bearer grant:

  1. A JWT is assembled and RS256-signed with the service account’s private_key — claims iss = client_email, scope = space-joined scopes, aud = token_uri, iat/exp (1h lifetime).
  2. The JWT is POSTed to token_uri as grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer&assertion=<jwt>.
  3. The returned access_token is cached ([tokio::sync::Mutex]) and reused until ~60s before its expires_in, then refreshed.

§Deviations from APISIX

  • APISIX derives per-entry httpRequest/insertId fields and merges log_format_extra. featherbit uses the shared log entry as the jsonPayload and omits httpRequest/insertId; use log_format to shape the payload.
  • log_id defaults to featherbit%2Flogs (APISIX: apisix.apache.org%2Flogs).
  • resource defaults to {"type":"global"}.

Structs§

AuthConfig 🔒
Service-account credentials resolved from auth_config or auth_file.
CachedToken 🔒
GoogleCloudFlusher 🔒
Delivers batched log entries to the Cloud Logging entries:write endpoint.
GoogleCloudLoggingPlugin
Ships log entries to Google Cloud Logging in batches.
TokenManager 🔒
Caches the OAuth2 access token and refreshes it near expiry.
TokenResponse 🔒

Constants§

DEFAULT_ENTRIES_URI 🔒
DEFAULT_SCOPES 🔒
DEFAULT_TOKEN_URI 🔒

Functions§

build_jwt 🔒
Assembles and RS256-signs the service-account JWT assertion.
build_log_entry 🔒
Wraps one log entry into a Cloud Logging LogEntry.
build_write_payload 🔒
Builds the full entries:write request payload.
civil_from_days 🔒
Howard Hinnant’s civil-from-days: days since the unix epoch → (year, month, day).
now_secs 🔒
resolve_auth 🔒
Resolves the service-account credentials from auth_config (inline) or auth_file (path to a JSON file). client_email, private_key, and project_id are required.
rfc3339_zulu 🔒
RFC3339 UTC timestamp (YYYY-MM-DDTHH:MM:SSZ) from a unix second count.