Skip to content

[RCA] Collect a bounded native-log incident window #14223

Open

Description

@hanahmily

Umbrella: #14222

Summary

Collect a bounded native-log incident window. Deliver one usable operation, not a framework-only foundation.

Boundary

Proposed activation caller: bydbctl rca collect --source=native-log. Command names are proposed, not existing APIs.
Reporter collection runs with read-only source access; offline steps use local files only.
No source storage/wire-format changes are requested. The incident format is separately versioned.

Requirements

R1. Reuse the ordinary stream query API for _monitoring_log/log; require UTC start/end, selected nodes, levels, output path, byte budget and deadline. Do not enable logging or modify a cluster.
R2. Persist a private local workspace with schema version, collection interval, source status, hashes and tool build information. Decode searchable tags and binary JSON data.fields without dropping unknown fields; preserve source log_id.
R3. Query one bounded time/node/level selection and filter module/message locally. No adaptive time subdivision or automatic pagination. Mark coverage partial or unknown when scan limits prevent proving completeness, including timestamp ties.
R4. Bound per-query rows, cumulative bytes and elapsed time; no automatic retries in this first slice; record missing schema, unreachable nodes, truncation separately from an empty successful query. Verify retrieved rows rather than trusting producer written counters.

Acceptance criteria

  • A hand-authored three-row fixture includes two rows with the same timestamp, a nested secret in data.fields, and a module predicate whose server-side limit would hide a match. For an unsaturated fixture assert exact IDs and decoded fields; for a saturated fixture require an explicit partial/unknown status, never complete.
  • Invoke the real CLI against the native-log E2E deployment, then with an absent schema and an unavailable endpoint. Assert no server writes/config changes, bounded termination, private files, and a truthful manifest.
  • Interrupt a collection: no complete marker may be left. Existing stream query commands remain unchanged.
  • Use hand-authored or independently captured fixtures with documented provenance; do not generate expected values using the code under test.
  • Add focused behavioral tests before implementation and record the actual RED command/failure, then GREEN results.
  • Keep existing CLI/API behavior compatible. Never overwrite unrelated user files; output conflicts must be refused.

Scope and readiness audit

  • Boundary and behavior: the single operation above; independently observable output and refusal behavior.
  • Production activation: the named CLI or skill entry point above, included in the same PR.
  • Packages/callers: bydbctl/internal/cmd/root.go and stream.go; new internal RCA collector package; existing native-log E2E fixtures.
  • Dependencies: None; first implementation candidate.
  • Classification: initial leaf candidate, NOT automation-ready until contract/RED audit.
  • RED evidence: not executed during this planning task; no claim of passing or failing implementation tests.
  • End-to-end proof: the real command/skill scenarios above, not source-text assertions.
  • Formats/lifecycle/fixtures: private workspace or public archive only; artifact-specific fixture family above.
  • Focused tests: CLI leaves should add TestRCA… coverage under bydbctl/internal/cmd and/or the introduced collector package;
    run go test ./bydbctl/internal/cmd -run TestRCA -count=1 plus the new package tests. Skill leaves must add a replayable evaluation harness
    with an exact command documented in the PR. Final test names/paths are fixed when the prerequisite seam merges.
  • Resource/concurrency checks: cancellation, bounded reads/output and cleanup on failure; use repository panic-aware goroutine wrappers if concurrency is introduced.
  • Decision: one proposed PR. If the named behavior requires an unimplemented server API or another lifecycle change, stop and split that prerequisite.

Required-only scope audit

Bounded export is required; exhaustive historical recovery is not.

Removed/deferred: Adaptive window splitting, automatic pagination, additional drop-metric endpoint collection, configurable retry engines and automatic resume.

Out of scope

Query-trace storage, schema changes, native receiver bug fixes, redaction, public archives, Kubernetes installation.

Concrete verification and closure gate

These are required acceptance tests, not examples that may be skipped. Artifact filenames and unsupported format handling must follow the merged prerequisite contracts. Before queueing, fix the tested schema version, configured limits, observable statuses and independent expected values; record any necessary interface decision in this issue rather than leaving it to an agent mid-run.

Fixed acceptance scenario

Use three independently authored native-log rows with IDs L1/L2/L3 inside [10:00, 10:05) UTC and a fourth outside. L2/L3 share a timestamp; one contains a nested data.fields value. With adequate limits, assert exactly L1/L2/L3 and the expected decoded values. With a two-row scan cap, assert partial/unknown coverage, never complete. Exercise absent schema, an unreachable endpoint and cancellation; no completed manifest marker or cluster mutation is allowed.

Executable regression

Proposed named regression: TestRCANativeLogCollect in bydbctl/internal/cmd exercising the registered command through an existing CLI test seam.
After normal repository generation, use:

go test ./bydbctl/internal/cmd -run '^TestRCANativeLogCollect$' -count=1 -v
make test-ci PKG=./bydbctl/internal/cmd

The exact selector must execute at least one test, not return “no tests to run.” If repository conventions require a different test harness or location, update this section with the real command before queueing; do not claim this proposed test already exists. Also run the actual changed internal package suites.

For GraphLoom, apply only the regression tests/fixtures to the chosen base: they must compile and fail by a relevant assertion. Apply the implementation: the same test must pass. Tests that import a new production package missing from the base are not valid assertion-based RED proof; use an existing command seam. Exercise the real CLI with fixture endpoints/files. If the issue requires deployment E2E, record its separate command and result; fixture-server tests alone do not satisfy it.

Evidence required to close this issue

  • Source/base revision, exact commands, fixture provenance and independently specified expected outcomes.
  • Actual positive and negative/partial-case results; explain failures and rerun after fixes.
  • Produced artifact/manifest/report samples with no real sensitive data, and the relevant size/coverage/privacy assertions.
  • Applicable repository checks and integration/evaluation results; explicitly list checks not run. A required check not run leaves acceptance incomplete, not passed.
  • For failures/cancellation, confirm no false completion marker and no unrelated user-file overwrite.

No verification execution is claimed by adding this section. Do not close the issue merely because code or documentation was submitted.

Activity

  1. added this to the BanyanDB - 0.13.0 milestone on Nov 16, 2026
  2. added
    enhancementEnhancement on performance or codes
    databaseBanyanDB - SkyWalking native database
    loggingLog collecting and analysis
    on Nov 16, 2026
  3. UchihaIthachi commented on Nov 18, 2026

    @UchihaIthachi

    @hanahmily is #14223 open for a contributor, or is it meant for your queue once the contract is fixed?

    If a contributor is fine, I'd like to take it. I checked the test seam first: bydbctl/internal/cmd already runs the real CLI from plain Go tests (analyze_native_test.go builds the root with RootCmdFlags and calls Execute), so TestRCANativeLogCollect with -run '^TestRCANativeLogCollect$' would really run there. I can also write down the open contract points here first (schema version, limits, statuses) before any code, if that helps.

  4. hanahmily commented on Nov 18, 2026

    @hanahmily
    ContributorAuthor

    @UchihaIthachi Thanks for checking the CLI test setup. The RootCmdFlags/Execute approach matches what we intended. Writing down the small contract here before implementation would help:

    1. CLI inputs: UTC interval, nodes, levels, output directory, row/byte limits and deadline. Reuse existing BYDBCTL connection/authentication options.
    2. Private output: a versioned manifest plus log records. Preserve log_id, source identity and decoded data.fields; record collector build, hashes and coverage.
    3. Results: distinguish successful collection from complete evidence. Define how empty, partial, unavailable and unknown coverage are represented, together with CLI exit behavior.
    4. Bounds: no automatic pagination, time-window splitting or retries. Reaching a scan limit—including timestamp ties—must not produce a false completeness claim.
    5. Tests: use the existing CLI entry point for assertion-based RED/GREEN. Include exact-record, capped-output, missing-schema, timeout and cancellation cases. Retain the separate native-log deployment integration check.

    To clarify private output: these are files saved locally within the reporter's approved environment, before sanitization—not a special private GitHub repository. For example:

    incident/
    ├── manifest.json      # Scope, tool version, coverage, errors and hashes
    └── native-logs.jsonl   # Collected logs, including decoded data.fields
    

    These filenames are illustrative, not a fixed contract. The logs may contain sensitive query values, customer identifiers, internal addresses or accidentally logged credentials. Do not automatically upload this directory or feed its raw contents to a hosted AI model. Later issues select and sanitize evidence into a separate candidate directory; only the reviewed and approved archive is intended for public sharing.

    This issue collects evidence faithfully; it does not make that evidence safe to publish. A sample manifest, sample log record and a small input/status table should be enough to review the contract. No new server API or general collection framework is needed.

  5. UchihaIthachi commented on Nov 20, 2026

    @UchihaIthachi

    Thanks @hanahmily. Short version first, details below.

    • Read-only: a schema GET first (a missing stream gives a 500, not a NotFound, so this is how I tell schema_missing apart), then one query, no pagination/retry.
    • collection (did the run finish) is kept separate from coverage (complete / empty / partial / unavailable / unknown). Exit 0 = complete or empty, 6 = partial, 3 = failed.
    • Hitting the row or byte cap is always partial, with an exclusive covered_until, since rows often share a millisecond.

    Two questions:

    1. Through a liaison, a node outside the live set just isn't queried, so I'd record per-node counts and not claim reachability. OK?
    2. Skip ~/.bydbctl.yaml like the data commands do, so nothing is written outside --output?

    I checked this against main (8efdf0ca) and with real queries on a local standalone.

  6. surlymochan commented on Nov 20, 2026

    @surlymochan

    Scope/readiness spot-check on the seam named in this issue (read-only verification, no implementation claim):

    • The named callers bydbctl/internal/cmd/root.go and stream.go both exist — but in apache/skywalking-banyandb, not in this repo. In apache/skywalking, bydbctl appears only in e2e docker-compose references.
    • The _monitoring_log stream referenced by R1 is likewise a BanyanDB-side concept (it shows up in skywalking-banyandb docs/design for self-stored logs).

    So the implementation seam resolves cleanly, just across the repo boundary: if the PR for this leaf is meant to land in skywalking-banyandb, the paths in the audit section are correct as written; if it is meant to land here, the stream-query reuse in R1 would need a cross-repo call or a move. Flagging only so the PR venue is explicit before the RED audit runs — the requirements themselves (bounded rows/bytes/time, partial-or-unknown coverage marking, no server writes) read as implementable against that seam either way.

  7. UchihaIthachi commented on Nov 20, 2026

    @UchihaIthachi

    Here are the details I meant to include above (they didn't make it into that comment, sorry).

    @surlymochan thanks, good point. Like the other BanyanDB issues tracked here, the code goes to apache/skywalking-banyandb, so the PR will be there and link back to this issue. The paths in the audit section are relative to that repo.

    Inputs

    Flag Required Notes
    --source native-log yes only value for now
    --start, --end yes RFC3339 in UTC (Z), ms precision at most (the server returns 400 for sub-ms), start < end, window [start, end)
    --node yes, repeatable node_id
    --level yes, repeatable level, one of the zerolog names the sink stores
    --output yes created with 0700; refused if anything already exists there
    --module, --message-contains no filtered locally after the fetch
    --max-rows no, default 900 query limit; 900 is what the nativelog tests use because of the memory budget; above 100000 the server refuses it
    --max-bytes no, default 32MiB size of native-logs.jsonl; the HTTP response read is capped at 2x this
    --deadline no, default 2m for the whole run

    Connection/auth: the existing -a, -u/-p and TLS flags, through the same REST helper as bydbctl stream query, with the request tied to the deadline/cancel context. Like the data commands, it doesn't read or create ~/.bydbctl.yaml.

    What it does

    1. GET the _monitoring_log group and log stream schema. 404 there means schema_missing. I added this step because querying a missing stream gives a 500 with "stream doesn't exist", not a NotFound. The stream's mod_revision goes into the manifest.
    2. One query on _monitoring_log/log: time order ascending (empty index rule, SORT_ASC), limit = --max-rows, projection = the 8 searchable tags + data.fields. Nodes/levels go in as (node_id = n AND level = l) OR ... pairs. No pagination, no splitting, no retry.
    3. Check every row before writing it: inside the window, timestamps not going backwards, log_id present. If not, coverage becomes unknown.
    Why OR pairs instead of IN ... AND IN ...

    I first tried node_id IN (...) AND level IN (...) and got a 500 ("timeRange and series are required"). Any multi-value IN combined with AND on these two entity tags fails the same way. Looks like ParseEntities in pkg/query/logical/parser.go collapses an AND into one series key and gives up when a position has two values, while OR keeps the list. The OR form returns the right rows (I checked it filters node and level correctly), so this issue doesn't need a fix there. Happy to open a separate issue for it if that's useful.

    Results

    collection = did the run finish. coverage = what the evidence actually proves. I also keep fetched_records (what the server returned) apart from records (what was written after --module/--message-contains), so a filter can't make a capped scan look empty.

    Case source_status collection coverage Exit
    fewer rows than --max-rows, nothing capped, some written ok succeeded complete 0
    same, nothing written ok succeeded empty 0
    hit --max-rows (ties included) or --max-bytes ok succeeded partial + covered_until 6
    group/stream missing schema_missing failed unavailable 3
    can't connect unreachable failed unavailable 3
    deadline hit timeout failed unknown 3
    401/403, ResourceExhausted, response too big, bad rows, anything else error failed unknown 3
    Ctrl-C as far as it got cancelled unknown 3
    bad flags nothing written 1
    --output exists nothing written 2

    1/2/3 mean the same as in pkg/transfer/exitcode. 6 would be local to the rca command. covered_until is exclusive: last fetched row's timestamp when the row cap is hit, or the first unwritten row's when the byte cap is hit. Rows at the same millisecond are common in the real data, so anything at that timestamp may be missing. Only succeeded + complete/empty claims the window is complete. Ctrl-C cleans up temp files; a kill -9 leaves no manifest.json.

    manifest.json (example)

    {
      "schema_version": "rca.native-log.v1",
      "collector": {"build": "<version.Build()>"},
      "source": {"addr": "http://banyand:17913", "group": "_monitoring_log", "stream": "log", "stream_mod_revision": "1795134849798106000"},
      "request": {"start": "2026-11-18T10:00:00Z", "end": "2026-11-18T10:05:00Z",
                  "nodes": ["data-0"], "levels": ["error", "warn"], "module": "", "message_contains": ""},
      "limits": {"max_rows": 900, "max_bytes": 33554432, "deadline": "2m0s"},
      "started_at": "2026-11-19T08:00:00Z", "finished_at": "2026-11-19T08:00:01Z",
      "source_status": "ok", "collection": "succeeded", "coverage": "partial",
      "covered_until": "2026-11-18T10:02:30Z",
      "fetched_records": 900, "records": 900,
      "nodes": {"data-0": {"records": 900}},
      "files": [{"name": "native-logs.jsonl", "bytes": 412337, "sha256": "…"}],
      "errors": []
    }

    addr is saved without any user:pass@.

    native-logs.jsonl (one line)

    {"log_id":"data-0-1731920000-42","timestamp":"2026-11-18T10:02:30Z","node_id":"data-0","node_type":"data","module":"STREAM","level":"error","grpc_address":"10.0.0.5:17912","http_address":"10.0.0.5:17913","message":"query failed","fields":{"group":"sw_trace","err":{"code":"Unavailable"}}}

    log_id comes from the tag (the response elementId is a different, server-side id). fields is the decoded data.fields with all keys kept; if it isn't valid JSON it's stored as base64 with "fields_raw": true. Whole lines only, files 0600, written to temp names and renamed, manifest last.

    Tests

    TestRCANativeLogCollect in bydbctl/internal/cmd, through RootCmdFlags + Execute, against an httptest server with hand-written fixtures (provenance + fake secret noted in testdata/rca/README.md). Rows: L1 10:01:00, L2 and L3 both 10:02:30 (L3 has a nested secret in data.fields), L4 10:06:00 outside the window.

    Cases: exact records; empty window; --max-rows 2 → partial, covered_until 10:02:30, exit 6; a --module match sitting past the cap → fetched 2, written 0, partial; byte cap; non-JSON fields; missing schema; ResourceExhausted; unreachable; timeout; cancel mid-response; existing --output; bad flags (non-UTC, sub-ms, unknown level). Every case checks its exit code and manifest, so on main they all fail on assertions (rca is an unknown command) rather than not compiling.

    RED/GREEN: go test ./bydbctl/internal/cmd -run '^TestRCANativeLogCollect$' -count=1 -v, then make test-ci PKG=./bydbctl/internal/cmd. Plus a deployment case next to test/integration/standalone/nativelog: real CLI against a node with native logging on (schema and revision unchanged afterwards), and one with it off (schema_missing, no group created).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

databaseBanyanDB - SkyWalking native databaseenhancementEnhancement on performance or codesloggingLog collecting and analysis

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions