Skip to content

design-15 S7a: read-only sing-box stats collector (ADR-004)#6

Merged
lr00rl merged 2 commits into
mainfrom
feat/design-15-singbox-stats
Jul 22, 2026
Merged

design-15 S7a: read-only sing-box stats collector (ADR-004)#6
lr00rl merged 2 commits into
mainfrom
feat/design-15-singbox-stats

Conversation

@lr00rl

@lr00rl lr00rl commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Summary

  • New singbox-stats collector: read-only QueryStats (substring user>>>, never reset) against the core's experimental V2Ray Stats API over loopback gRPC (LATTICE_SINGBOX_STATS_API, off by default). Server keeps monotonic diffing exactly like the xray-cli source.
  • Vendored proto: internal/proxyusage/singboxstats/stats.proto is the upstream definition (byte-identical service/messages, only go_package adjusted) + generated code, regen pinned to development time (README with the one-liner). New deps: google.golang.org/grpc + protobuf (pure Go, per ADR-004, design-15: line_uuid, per-line users, chain recognition, Sub-Store integration lattice#2).
  • Counter names pass through untouched (design-15 §5 u_<hash>) for server-side reversal into (user, line).
  • Joins single-source exclusivity validation + collector-health error reporting.

Verification

  • gofmt/go vet clean; go test ./... all ok (-count=1)
  • New tests: loopback/pattern validation, aggregate+filter, empty/error/negative paths, bufconn end-to-end (patterns sent, reset never set)

Refs LatticeNet/lattice#2 (ADR-004), #5.

lr00rl added 2 commits July 22, 2026 06:00
ADR-004 slice: the new singbox-stats collector queries the core's
experimental V2Ray Stats API over loopback gRPC (LATTICE_SINGBOX_STATS_API,
off by default) with substring patterns and never resets counters — the
server keeps monotonic successive-snapshot diffing. stats.proto is the
upstream definition byte-identical except go_package, with generation
pinned to development time and a regen note in singboxstats/README.md.

Counter names flow through unchanged (design-15 §5 u_<hash> users); the
server reverses them into (user, line) pairs. Collector config joins the
single-source exclusivity validation and the collector-health error
reporting exactly like the xray-cli source.
Report the configured stats endpoint in runtime telemetry, pin the vendored protocol to a verified upstream commit, and publish this slice only as an alpha artifact built against the SDK declared in go.mod.

Constraint: The sing-box experimental API is loopback-only and its wire contract is vendored.

Rejected: Test only against generated local stubs | that cannot detect drift from upstream sing-box.

Confidence: high

Scope-risk: moderate

Reversibility: clean

Directive: Run check-singbox-stats-proto.sh before changing the vendored proto pin.

Tested: go test ./...; go vet ./...; release workflow checker; upstream proto byte comparison; proxyusage race tests

Not-tested: Live gRPC query against HK sing-box, deferred to canary
@lr00rl
lr00rl force-pushed the feat/design-15-singbox-stats branch from aee9c33 to d75b6ca Compare July 22, 2026 13:03
@lr00rl
lr00rl marked this pull request as ready for review July 22, 2026 13:27
@lr00rl
lr00rl merged commit 38a3720 into main Jul 22, 2026
1 check passed
@lr00rl
lr00rl deleted the feat/design-15-singbox-stats branch July 22, 2026 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant