Skip to content

obs sink: byte-aware chunking for SLS PutLogs (blocks content capture) #529

Description

@moonming

Surfaced by the independent audit of #528 (finding M1).

Problem

The sink framework's byte-ceiling is advertised but enforced nowhere:

  • SinkCapabilities.max_batch_bytes is set by sinks but read by no code. SinkPipeline batches purely by record count (max_batch, default 100) + flush interval.
  • The docs contradict each other on who enforces it:
    • capabilities.rs (max_batch_bytes): "The pipeline never hands the sink a batch larger than this."
    • pipeline.rs module doc: "the sink owns chunking a batch down to its own per-request byte limit inside append_batch."
    • Reality: neither happens.

AliyunSlsSink::append_batch encodes all records into a single LogGroup → one PutLogs. SLS caps the request body (single LogGroup, low single-digit MB). On today's metadata-only path this is fine (≈100 records × ~0.5–2 KB ≪ limit). But the next milestone — full prompt/response content capture (SinkContent) — makes a 100-record batch easily exceed the limit, and SLS then returns 400 PostBodyInvalid, which classifies as SinkError::Permanent → the whole batch is dropped, never retried. A log sink silently dropping under load is exactly the failure the sink's error-classification is meant to avoid.

Fix (do this before content capture ships)

  1. Implement byte-aware chunking in AliyunSlsSink::append_batch (per the pipeline.rs design — the sink self-chunks, since only the sink knows the encoded size): pack records into multiple PutLogs requests, each kept under a conservative raw-size ceiling (~3 MB), always sending at least one record per request. Fast-path the common case (whole batch fits → one encode + one POST); only split when oversize.
  2. Reconcile the contradictory capability docs (capabilities.rs vs pipeline.rs) to a single source of truth: the sink self-limits.
  3. Add a unit test that drives a synthetic >ceiling batch (e.g. one large SinkContent) and asserts it fans out across multiple signed PutLogs requests.
  4. Restore the SLS capability to batch_unit: Both + max_batch_bytes: Some(...) once (1) lands.

Interim (in #528)

The SLS capability was downgraded to the honest current state — batch_unit: Records, max_batch_bytes: None (parity with OtlpSink) — so it no longer advertises an unenforced ceiling. This issue blocks the content-capture milestone.

Refs: #528, api7/AISIX-Cloud#687

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High-value differentiatorcross-repoRequires changes in DP + CP + Dashboard UI + e2edocumentationImprovements or additions to documentationenhancementNew feature or requestreal chain testRun the real-chain workflow on this PR

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions