Files
rustfs/scripts
Zhengchao An 3ed682be42 feat: offline log fault-analysis system (rustfs diagnose) (#4876)
* feat(log-analyzer): add crate skeleton and unified event model

Implements LA-1 (rustfs/backlog#1282) of the log fault-analysis system
(rustfs/backlog#1281): new synchronous rustfs-log-analyzer crate with the
LogEvent/LogLevel/SourceRef/EventKind/ParseStats model shared by all
later stages. No tokio, no rustfs-* internal deps by design.

Note: thiserror listed in the issue is deferred until a stage actually
defines error types (LA-3/LA-4) to avoid an unused dependency.

* feat(log-analyzer): add line parsing layer

Implements LA-2 (rustfs/backlog#1283): four parse channels tried in order
per line — native tracing JSON, container-prefix stripping (K8s CRI /
docker compose / journald) with JSON retry, multi-line Rust panic block
folding (both pre- and post-1.65 formats, stderr has no JSON logger), and
a plain-text fallback that never fails. Parse accounting feeds the report
parse-ratio disclosure.

* feat(log-analyzer): add ingest layer for directories and archives

Implements LA-3 (rustfs/backlog#1284): expands customer inputs (files,
directories, zip/tar/tar.gz/.zst/.gz, stdin-like readers) into parsed
events. Magic-byte detection with extension fallback, recursive archive
walking with depth/entry/byte/memory caps (every capped input disclosed
in IngestReport.skipped), first-level directory names become node labels,
and nothing is ever extracted to disk so hostile entry paths are inert.

Adds tar 0.4 to workspace deps (sync; the async astral-tokio-tar used by
rustfs-zip does not fit this crate's no-tokio contract).

* feat(log-analyzer): add rule model, matching engine, and finding aggregation

Implements LA-4 (rustfs/backlog#1285): owned serde-round-trippable Rule/
Matcher/Severity types (external JSON rules deserialize into the same
types later), fail-fast RuleSet validation that reports every problem at
once, a linear-scan engine with regexes compiled once, and an
order-independent FindingsCollector (commutative aggregates only; the
test asserts byte-identical output across shuffled input orders).

* feat(log-analyzer): add built-in seed rule library (68 rules, 12 categories)

Implements LA-5 (rustfs/backlog#1286): the 2026-07 repository-wide
failure-log survey distilled into rules across disk health, erasure/
bitrot, quorum, network/RPC, distributed locks, heal, scanner, IAM,
startup/config/TLS, capacity, decommission/rebalance, and process panics.

Every anchor was verified verbatim against the source tree (94/94 hits,
zero corrections needed). Quorum rules pre-fill implies_root_cause for
the Phase-2 folding (rustfs/backlog#1290); client-side rules carry burst
thresholds (min_count) so isolated client mistakes don't clutter reports.
Tests: one realistic positive sample per rule (table-driven), exact-set
smoke samples including the intentional internode/client signature
double-hit, and negative cases.

* feat(log-analyzer): add analysis orchestration, report rendering, and redaction

Implements LA-6 (rustfs/backlog#1287): a single-pass Analyzer that does
rule matching, minute-bucket timelines (gap-filled, merged to <=60
buckets), unmatched WARN/ERROR template clustering (placeholders for
numbers/uuids/paths/addresses/quotes, 5000-template cap disclosed as
<overflow>), mixed-UTC-offset detection, and below-min_count demotion to
a low-confidence section. Renderers: pipe-friendly terminal text, stable
JSON (schema_version=1), and ticket-pasteable Markdown. --redact hashes
customer identifiers (stable h:sha256[..8]) in samples/evidence/messages
while keeping rule ids, targets, and panic locations intact.

* feat(rustfs): add 'rustfs diagnose' subcommand for offline log fault analysis

Implements LA-7 (rustfs/backlog#1288): wires rustfs-log-analyzer into the
main binary as a diagnose subcommand that short-circuits before
observability/storage init (same pattern as 'info' / 'tls inspect') so
the report on stdout is never wrapped by the JSON logger.

rustfs diagnose <paths>... [--format text|json|md] [--since 24h]
  [--until ...] [--min-level warn] [--redact] [--top N] [--samples N]
Accepts files, directories, archives (.zip/.tar/.tar.gz/.zst/.gz) and '-'
for stdin. Exit codes: 0 = diagnosis completed (findings never fail the
process), 2 = bad arguments / no readable input.

diagnose_e2e covers the six MVP acceptance scenarios from
rustfs/backlog#1281 (directory+zst archive, multi-node zip attribution,
CRI-prefixed kubectl logs, panic folding, stable JSON schema, CLI parsing
incl. the legacy 'rustfs <volume>' preprocessor regression); the
full-binary smoke test is #[ignore]d (run with -- --ignored).
Usage doc: docs/operations/log-diagnose.md.

* ci(log-analyzer): guard rule anchors against log-message drift

Implements LA-8 (rustfs/backlog#1289): every seed-rule anchor must exist
verbatim in the rustfs source tree, so changing a log message without
updating its rule fails the gate instead of silently killing the rule.

- la-dump-anchors bin emits 'rule_id<TAB>anchor' TSV;
- scripts/check_log_analyzer_rules.sh greps each anchor (fixed-string,
  *.rs only, excluding crates/log-analyzer itself to avoid self-matches);
- RuleSet::new now rejects anchors that are blank, contain tab/newline,
  or are shorter than 8 bytes (no discriminating power); the '[FATAL]'
  anchor gained its trailing space to meet the floor while still matching
  the emit_fatal_stderr format string;
- wired as log-analyzer-rules-check into the pre-pr gate (it compiles the
  crate, so it stays out of the fast pre-commit set).

Negative self-test: breaking an anchor makes the script exit 1 naming the
rule ('MISSING anchor for rule inconsistent-drive: zzz-not-exist-anchor').

* refactor(log-analyzer): use root-relative provenance for directory inputs

Binary smoke run showed report samples citing full absolute paths, which
drowns the useful part. Directory inputs now label sources as
"<root-name>/<relative-path>" (e.g. "smoke-logs/node1/rustfs.log");
archives and single files keep their existing provenance.

* chore(log-analyzer): reword comment to satisfy the typos gate

* fix(log-analyzer): declare chrono serde feature locally after workspace feature localization

* fix(log-analyzer): bound line reads so a newline-less input cannot bypass the byte cap

read_until grew the line buffer with the entire remaining stream before the
max_total_bytes check ran, so a single multi-GB line (decompression bomb or
corrupt file) could allocate unboundedly. Replace it with a capped reader that
enforces the remaining global budget chunk-by-chunk and adds a per-line cap
(IngestOptions::max_line_bytes, default 1 MiB); over-cap tails are discarded
but still charged, and truncation is disclosed once per file as the new
line_too_long skip reason. Flagged by Codex review on #4876.

* fix(log-analyzer): redact field-shaped identifiers inside message text and widen the hash to 64 bits

--redact only hashed IPv4 literals in unstructured message text, so
bucket/object/access-key values embedded in messages (access_key=AK123,
'bucket: media, object: private/a.bin') leaked into reports documented as
safe to forward. Apply the SENSITIVE_FIELDS list to key=value / key: value
shapes in message text with the same hash as structured fields, and extend
the hash from 8 to 16 hex chars so cross-identifier collisions stay
negligible. Flagged by Codex and Copilot review on #4876.

* fix(log-analyzer): strip collector prefixes before panic-block absorption

An open panic block tested continuation lines against absorbs() before their
CRI/compose/journald prefix was stripped, so containerized panics stored the
prefix in the payload and split into a truncated panic plus text noise as soon
as the note/backtrace lines arrived. Stripping now happens once at the top of
feed() and every channel judges the payload. Flagged by Codex review on #4876.

* fix(log-analyzer): remove two input-order dependencies in representative selection

The unmatched-cluster target stayed pinned to the first-seen event while the
representative sample could be replaced, so sample and target could come from
different events and vary with input order; the pair now updates together by
lexicographic (sample, target) min. Sample selection tie-broke on line number
alone, which is only unique within one file; the key now includes the source
file. Flagged by Copilot review on #4876.

* fix(rustfs): reject negative relative times in diagnose --since/--until

parse_time_arg accepted "-24h" and produced a future timestamp, contradicting
the documented 'counted back from now' semantics. The amount now parses as
unsigned, so a leading '-' fails with the usual invalid-time error. Flagged by
Copilot review on #4876.

* feat(log-analyzer): Phase 2 — causal folding, timeline anomalies, external rules (LA-9) (#4942)

* feat(log-analyzer): collapse cascade symptoms under their root-cause finding

Phase-2 sub-item A (rustfs/backlog#1290): a finding whose rule declares
implies_root_cause edges folds under a qualifying root — root.first_seen <=
symptom.first_seen + 5min and root.last_seen >= symptom.first_seen - 30min,
existence-based when either side has no timestamps (pure stderr panics).
Findings gain collapsed_into/caused; text/markdown render the root block with
an indented cascade line and stop listing collapsed symptoms flat, while JSON
keeps every finding. Roots are promoted to the most severe position among
their block so the report top still answers 'the most likely cause'.

* feat(log-analyzer): detect timeline/clock anomalies (schema v2)

Phase-2 sub-item B (rustfs/backlog#1290): three deterministic hints rendered
between the summary and findings — mixed UTC offsets (with a clock-skew note
when signature-mismatch findings coexist), per-node time ranges that do not
overlap at all (both nodes >100 timestamped events), and log gaps of at least
max(15min, 3x bucket width) after >=3 consecutive active minutes, upgraded to
restart evidence when a startup-class finding begins within 5min after the
gap. JSON gains timeline_anomalies and schema_version bumps to 2.

* feat(diagnose): load external rules with --rules <file.json>

Phase-2 sub-item C (rustfs/backlog#1290): an external JSON rule file
({schema_version: 1, rules: [Rule...]}, the exact serde shape of the built-in
rules) merges over the seed library, with same-id rules replacing built-ins so
the support team can hotfix a misfiring rule without a release. The merged set
validates as a whole and any problem (bad regex, duplicate id, empty matcher
group, wrong schema version) prints every error and exits 2 — analysis never
runs on a half-broken set. External anchors are exempt from the CI anchor
guard, documented as author-owned quality. Adds the custom-rules section to
docs/operations/log-diagnose.md.

* fix(log-analyzer): address PR #4876 review (redaction coverage, order-independence, guards)

Redaction (--redact) now honours its "forwardable" intent across every report surface instead of a 15-name field whitelist applied over a subset:
- redact_event scrubs the full fields map (sensitive names hashed whole, every other value run through redact_text) plus provenance, so the JSON/Markdown full-sample dump no longer leaks non-whitelisted fields (client_ip, url, user, ...).
- node labels are hashed once at ingestion, so summary.nodes, per-node timeline ranges, samples and timeline anomalies stay consistent and correlatable under one stable hash.
- evidence values, unmatched-cluster templates and skipped-input paths are now redacted; peer/disk/drive/volume/node/user added to the sensitive set; IPv6 literals are hashed (without touching `rust::paths` or HH:MM:SS clocks); provenance keeps the leaf filename and hashes the customer directory/archive prefix.
- redact.rs and docs/operations/log-diagnose.md reworded to "best-effort identifier scrubbing", not an anonymization guarantee.

Order-independence (the crate's headline contract):
- the evidence value cap keeps the lexicographically smallest N distinct values instead of the first-N-by-arrival (previously order-dependent).
- first_seen/last_seen break equal-instant ties on the offset, so the serialized RFC3339 offset no longer depends on input order.

Parsing:
- a new-format panic header no longer swallows the line immediately after it when that line is itself a JSON event or a second panic header (previously dropped an interleaved ERROR in merged stdout/stderr, or merged a panic-during-panic); trailing "note: ..." backtrace lines now fold into the block.

CLI:
- diagnose --since/--until reject absurd relative amounts via checked_sub_signed instead of panicking; the exit-code doc now matches actual behaviour.

CI:
- check_log_analyzer_rules.sh is wired into the ci.yml test-and-lint job (it was only in make pre-pr, so anchor drift from other PRs could merge green).

Markdown table cells escape '|' so customer log text cannot break the table structure.

---------

Co-authored-by: houseme <housemecn@gmail.com>
2026-07-18 15:00:34 +00:00
..
2025-12-18 20:13:24 +08:00
2025-12-18 20:13:24 +08:00
2025-12-28 21:57:44 +08:00
2025-12-18 20:13:24 +08:00

scripts/ index

Authoritative inventory of everything under scripts/ (backlog#1153 infra-13). One row per top-level entry; subdirectories get one row each and keep their own READMEs. The test-layer map that ties the major runners together lives in docs/testing/README.md.

Statuses

  • ci-gate — wired into CI, release, or image-build pipelines. Do not move, rename, or change flags without updating the wiring listed in the last column.
  • dev-tool — run by humans: local dev loops, runbooks, validation harnesses. Kept working, not wired into CI.
  • archived — one-shot scripts whose investigation/issue is finished, moved to scripts/archive/. Unmaintained reference material: never wire into CI, and expect bit-rot. To resurrect one, move it back and give it an index row here.

Adding a script? Add an index row in the same PR. Issue-scoped scripts (run_issueNNN_*, validate_issue_NNN_*) are expected to be archived when their issue closes.

Repository & CI gates

Entry Status Purpose Wiring / docs
check_architecture_migration_rules.sh ci-gate Architecture-boundary anti-regression guard ci.yml Quick Checks; make pre-commit
check_body_cache_whitelist.sh ci-gate Keeps the app-layer body-cache eligibility gate fail-closed ci.yml Quick Checks
check_doc_paths.sh ci-gate Fails when instruction/architecture docs reference repo paths that no longer exist make pre-commit / pre-pr
check_extension_schema_boundaries.sh ci-gate Extension-schema crate boundary guard ci.yml Quick Checks; make pre-commit
check_layer_dependencies.sh ci-gate Crate-layering DAG guard (reads layer-dependency-baseline.txt) ci.yml Quick Checks
check_logging_guardrails.sh ci-gate Blocks legacy logging patterns from returning make pre-commit / pre-pr
check_migration_gate_count.sh ci-gate Migration-critical test gate with committed count floor (.config/migration-gate-floor.txt) ci.yml Test and Lint; docs/testing/README.md
check_no_planning_docs.sh ci-gate Blocks committed planning-type documents ci.yml Quick Checks; make pre-commit
check_no_tokio_io_uring.sh ci-gate Keeps tokio's io-uring backend disabled ci.yml Quick Checks
check_unsafe_code_allowances.sh ci-gate Unsafe-code allowance ledger guard ci.yml Quick Checks
layer-dependency-baseline.txt ci-gate (data) Committed baseline consumed by check_layer_dependencies.sh arch-checks skill
static.sh ci-gate Static-build helper executed inside image builds Dockerfile.source, Dockerfile.decommission-local
helm_chart_version.sh ci-gate Keeps the Helm chart version in sync with the release helm-package.yml
test_helm_templates.sh ci-gate Helm template rendering test helm-package.yml

Test & e2e runners

Entry Status Purpose Wiring / docs
e2e-run.sh ci-gate Boots a rustfs server and runs the s3s-e2e black-box conformance tool against it ci.yml e2e-tests jobs; docs/testing/README.md
run_ecstore_validation_suite.sh dev-tool ecstore black-box validation suite (quick/full/destructive/fuzz profiles) docs/testing/README.md, docs/testing/ecstore-validation-suite-design.md
run_e2e_tests.sh dev-tool Local e2e_test crate runner (starts a server, applies filters, cleans up) crates/e2e_test/README.md
run.sh dev-tool Local rustfs startup wrapper make e2e-server; Justfile
run.ps1 dev-tool Windows counterpart of run.sh
probe.sh dev-tool Probe-style e2e run make probe-e2e
run_scanner_validation_harness.sh dev-tool Scanner validation harness docs/operations/scanner-benchmark-runbook.md
test_scanner_validation_harness.sh dev-tool Self-test for the scanner validation harness
test_build_rustfs_options.sh dev-tool Shell test for rustfs build-option wiring make test (script-tests)
test_entrypoint_credentials.sh dev-tool Container entrypoint credential-handling test make test (script-tests)
test_helm_chart_version.sh dev-tool Test for helm_chart_version.sh
windows-sftp-listener-smoke.sh dev-tool Confirms rustfs.exe --features sftp binds an SFTP listener on Windows

Benchmark & performance harnesses

Entry Status Purpose Wiring / docs
run_hotpath_warp_ab.sh ci-gate Linux warp A/B rig for the hotpath series performance-ab.yml (scheduled); docs/operations/hotpath-warp-ab-runbook.md
hotpath_warp_ab_gate.sh dev-tool Relative-budget gate evaluated over the warp A/B results used by run_hotpath_warp_ab.sh; hotpath runbook
run_internode_grpc_ab_bench.sh dev-tool One-click A/B driver for the internode gRPC optimization stages docs/operations/internode-grpc-benchmark-runbook.md
run_internode_transport_baseline.sh dev-tool Internode transport baseline runner internode runbook; crates/io-metrics/README.md
run_four_node_cluster_failover_bench.sh dev-tool Four-node cluster failover benchmark docker/compose/README.md; internode runbook
run_object_batch_bench.sh dev-tool Batch object benchmark runner (warp/s3bench) internode + scanner runbooks
run_object_batch_bench_enhanced.sh dev-tool Enhanced batch benchmark runner; hub used by the smoke rigs hotpath runbook
run_get_codec_streaming_smoke.sh dev-tool Local GET benchmark harness for the codec streaming read path docs/testing/ecstore-validation-suite-design.md
run_gt1g_get_http_matrix.sh dev-tool >1 GiB GET HTTP matrix docs/testing/ecstore-validation-suite-design.md
run_gt1g_multipart_put_matrix.sh dev-tool >1 GiB multipart PUT matrix docs/testing/ecstore-validation-suite-design.md
run_scanner_benchmarks.sh dev-tool (disposition pending) Scanner performance benchmark runner. Contains a hardcoded stale path; disposition owned by backlog perf-10 — do not fix, move, or delete it here

Local development & operations

Entry Status Purpose Wiring / docs
dev_clear.sh dev-tool Local dev cleanup. scripts/dev_*.sh is a CI paths-filter glob — keep the naming ci.yml/build.yml paths filters
dev_deploy.sh dev-tool Copy a built binary to dev servers make deploy (.config/make/deploy.mak); Justfile
dev_rustfs.sh dev-tool Local dev run loop
dev_rustfs.env dev-tool (data) Env presets for the dev scripts
restart_local_single_node_multidisk_rustfs.sh dev-tool Restart a local single-node multi-disk instance
inspect_dashboard.sh dev-tool Sanity-checks the Grafana dashboard JSON .docker/observability
notify.sh dev-tool Starts a local webhook receiver for notify-target development
install-flatc.sh dev-tool Local flatc installer (macOS)
install-protoc.sh dev-tool Local protoc installer (macOS/Linux)
makefile-header.sh dev-tool Generates the ## —— section —— header lines used in .config/make/*.mak
tls_gen.md dev-tool (doc) Notes on generating local TLS certificates

Subdirectories

Entry Status Purpose Wiring / docs
fuzz/ ci-gate Unified cargo-fuzz runner and helpers for the fuzz/ sub-workspace fuzz.yml; fuzz/README.md
s3-tests/ ci-gate ceph/s3-tests compatibility harness (allow-lists, patches, report tooling) ci.yml; e2e-s3tests.yml; scripts/s3-tests/README.md
security/ ci-gate Workflow-pin enforcement and release supply-chain asset generation audit.yml; build.yml
table-catalog/ dev-tool S3-Tables / pyiceberg validation suite docs/architecture/s3-tables-support-matrix.md
test/ dev-tool Manual operational validation runbooks (decommission, tier lifecycle), paired .sh + .md
archive/ archived Retired one-shot scripts (see below)

Archived (scripts/archive/)

Moved 2026-07 (backlog#1153 infra-13) after a whole-tree reference census: each entry had zero references from CI, Makefiles, docs, or code — or was referenced only by other scripts in this same archived set. Reasons:

Entry Was
validate_issue_785_list_objects.sh One-shot issue validation (list-objects series)
validate_issue_786_list_objects.sh One-shot issue validation (list-objects series)
validate_issue_787_list_quorum.sh One-shot issue validation (list-quorum)
validate_issue_841_list_objects_observability.sh One-shot issue validation (list observability)
validate_issue_1365_docker.sh One-shot issue validation (docker repro)
validate_issue_2723_site_replication.sh One-shot issue validation (site replication)
validate_issue_3031_docker.sh One-shot issue validation (docker repro)
run_issue712_deeper_zero_copy_put_with_capture.sh One-shot perf capture for backlog#712
run_issue797_local_4node_16disk_ab.sh One-shot 4-node/16-disk A/B for backlog#797
run_issue_2573_acceptance.sh One-shot acceptance run for issue #2573
run_issue_2941_perf_capture.sh One-shot perf capture for issue #2941
run_put_large_stage_breakdown.sh backlog#706 large-PUT stage breakdown (family)
run_put_large_stage_breakdown_with_capture.sh backlog#706 one-shot wrapper (family)
run_put_large_tuning_matrix.sh backlog#706 tuning matrix (family)
collect_put_large_stage_breakdown_artifacts.sh backlog#706 artifact collector (family)
analyze_put_service_metrics_deltas.py backlog#706 metrics-delta analyzer (family)
README-stress-test.md GET-optimization one-shot suite doc
stress-test-get-optimization.sh GET-optimization one-shot stress test
quick-validate-get-optimization.sh GET-optimization one-shot validation
benchmark-sf-optimization.sh GET-optimization one-shot benchmark
prepare_gt1g_get_test_objects.sh >1 GiB GET investigation one-shot fixture prep
run_gt1g_multipart_put_server_path_focus.sh >1 GiB PUT investigation one-shot focus run
run_get_metrics_gate_smoke.sh One-shot GET metrics-gate smoke
run_listobjects_verified_bench.sh One-shot verified list-objects bench
run_object_batch_bench_abc.sh One-shot capacity/object profile A/B/C controller
run_object_data_cache_bench.sh One-shot GET bench for the object-data-cache rollout gate
setup-test-binaries.sh One-shot Docker-build test binary fixture
test.sh Ancient manual mc bucket smoke scratchpad
test_policy.json Orphaned IAM policy fixture (hardcoded test bucket)