Skip to main content

Module sls_logger

Module sls_logger 

Source
Expand description

Alibaba Cloud SLS (Simple Log Service) access-logger (sls-logger).

Ships access-log entries to Alibaba Cloud’s Log Service. Each request builds one log entry (the shared build_entry shape, or a custom log_format) that is handed to a fire-and-forget BatchSink; a background task POSTs batches to the SLS PutLogs REST endpoint, signed with an HMAC-SHA1 Authorization: LOG <id>:<signature> header.

§Deviations from APISIX

APISIX’s sls-logger does not use the SLS HTTP REST API. It serializes each entry into an RFC 5424 syslog frame (with the project, logstore, and access keys embedded as syslog structured-data) and streams it over a raw TLS/TCP socket to the SLS syslog ingress. featherbit has no TCP sink; its shared infrastructure is HTTP-only. This port therefore targets the documented SLS PutLogs REST API instead (https://www.alibabacloud.com/help/en/sls/developer-reference/api-putlogs):

  • The batch is POSTed as JSON {"__topic__","__source__","__logs__":[…]} to https://<project>.<host>:<port>/logstores/<logstore>/shards/lb.
  • Requests are signed per the SLS spec: Content-MD5, Date, the sorted x-log-* canonical headers, and the canonical resource are HMAC-SHA1 signed with the access-key secret, base64-encoded, and sent as Authorization: LOG <access_key_id>:<signature>.
  • SLS requires string log values, so non-string entry fields are JSON-encoded (mirroring how the syslog path stringifies the entry).

The signing helper and its primitives (MD5, HMAC-SHA1) are unit-tested against fixed vectors; no end-to-end SLS handshake is exercised.

Structs§

SlsFlusher 🔒
Delivers batches to the SLS PutLogs REST endpoint.
SlsLoggerPlugin
Node that batches access-log entries and ships them to Alibaba Cloud SLS.

Constants§

API_VERSION 🔒
SIGNATURE_METHOD 🔒

Functions§

build_logs_payload 🔒
Builds the SLS PutLogs JSON payload. Each entry becomes a log object of string values (non-string fields JSON-encoded) plus a __time__ field. Pure and network-free for testing.
format_http_date 🔒
Formats a Unix timestamp (seconds) as an RFC 1123 GMT date, as SLS’s Date header requires (e.g. Mon, 03 Jan 2022 04:05:06 GMT).
hmac_sha1 🔒
HMAC-SHA1 via ring, returning the raw 20-byte tag.
md5 🔒
Self-contained MD5 (RFC 1321). SLS requires a Content-MD5 header and the project has no MD5 dependency, so it is implemented here and unit-tested against the RFC vectors.
md5_hex_upper 🔒
Uppercase hex MD5 digest, as required for the SLS Content-MD5 header.
required_string 🔒
sign_request 🔒
Builds the SLS request signature and the headers it covers.
stringify 🔒
SLS log values must be strings; keep strings as-is, JSON-encode the rest.