Skip to content

feat(core): extract protocol-agnostic core; add PostgreSQL wire protocol (pgburst mode) #6

Closed

Description

@pingedbrain

What problem does this solve

microburst's detect → decide → effect pipeline proves the thesis that fault injection only exercises real client behavior when the error arrives in the wire format the driver parses. That same thesis applies beyond AWS:

  • PostgreSQL: drivers (pgx, psycopg, JDBC, libpq, ActiveRecord) classify retries by SQLSTATE — 40001 serialization_failure, 40P01 deadlock, 55P03 lock timeout, 53300 too_many_connections, 57P01 admin_shutdown, 25006 read-only after failover. Toxiproxy can drop bytes; it cannot return a protocol-correct ErrorResponse, so retry/failover paths go untested.
  • Redis/RESP: cluster clients only exercise slot-migration handling if they see real -MOVED/-ASK redirects; also -LOADING, -READONLY post-failover, timeouts mid-MULTI.
  • gRPC: status trailers (UNAVAILABLE, RESOURCE_EXHAUSTED, ABORTED) injected mid-stream — needs HTTP/2 frame awareness, not protobuf parsing.
  • MySQL: same shape as PG — error packets with errno + SQLSTATE.

Today the rules engine, effects (latency/timeout/reset/corrupt), control API, fired log, presets and metrics are all protocol-agnostic in spirit but AWS-shaped in packaging. Extracting them into a shared core turns each new wire protocol into a module instead of a fork.

Proposed shape

Keep the pipeline, generalize the seams:

  • protocols/base.py already defines a registry seam (@register_serializer). Extend it upstream: a protocol module declares a frame parser, an operation detector, and an error renderer for its wire format.
  • New top-level mode: microburst --protocol postgres --upstream localhost:5432 (TCP listener instead of HTTP), same control API surface (/_microburst/rules, /fired, presets, Prometheus metrics — possibly namespaced per protocol).
  • PG MVP faults: ErrorResponse with chosen SQLSTATE mid-query, mid-ResultSet termination (partial rows then error), 25P02 aborted-transaction state, connection kill mid-transaction for failover testing, NOTICE storms.
  • Rule sketch:
- protocol: postgres
  query: "INSERT INTO orders"     # regex on query text
  probability: 0.3
  error:
    sqlstate: "55P03"             # lock_not_available
    message: "could not obtain lock"
  latency: {min: 200, max: 1500}

Redis (-MOVED/-ASK) is the natural second module — RESP framing is trivial and cluster-redirect testing is a real gap.

AWS behavior evidence

Not an AWS fault — this extends the fidelity thesis to adjacent wire protocols.

Guess, not verified: most language drivers treat class-40 errors as retryable at the transaction level; worth confirming per-driver (pgx, psycopg, JDBC) before locking semantics.

Activity

  1. added
    enhancement
    on Oct 9, 2026
  2. pingedbrain commented on Oct 9, 2026

    @pingedbrain
    OwnerAuthor

    Design exploration — how the PG wire mode fits microburst

    Spent a session mapping this properly. The core finding: PostgreSQL should not be forced through the HTTP pipeline. HTTP is one-request→one-response; PG is a long-lived bidirectional framed stream. What the two share is the decision plane, not the transport loop.

    What gets reused as-is

    • Rule DSL + matching engine (rules.py) — service/operation/label matchers map cleanly to verb+table detection
    • Fired log, control API (/_microburst/*), metrics, stats endpoint — protocol-agnostic already
    • Latency/reset/timeout effect semantics — the implementation is transport-specific but the knobs are the same

    What is PG-specific (src/microburst/pg/)

    • Frame parser (startup packet, Q, extended protocol P/B/D/E/S, X)
    • Operation detector — SQL verb + table extraction, not header matching
    • ErrorResponse renderer — S/V/C/M/D/F/L fields; SQLSTATE-correct (40001, 40P01, 55P03, 53300, 57P01, 57014…)
    • TCP connection handler — own listener, forwarding loop per connection
    • Control API stays HTTP on a separate port

    The honest thesis difference

    AWS SDKs auto-retry — so microburst exercises the driver's retry path. PG drivers (pgx, psycopg, JDBC, libpq) generally don't auto-retry; they surface SQLSTATE + severity to the application. The fidelity target shifts: the error must be indistinguishable from real PostgreSQL so the application's classification/retry code gets exercised. Same product, different consumer.

    The hard problem: state divergence

    An injected ERROR inside a transaction puts the client in failed-transaction state while the upstream never saw it — connections desync. MVP dodges this: FATAL-class errors only (they kill the connection, no divergence), ERROR-class only when the tx status byte is I (idle). Emulating 25P02-in-transaction faithfully is Phase 2 and needs minimal tx state tracking.

    MVP scope

    1. Startup faults — 53300 too_many_connections FATAL at connect
    2. Simple protocol (Q) error injection + latency/reset/timeout (57014 query_canceled vs hang)
    3. Extended protocol at batch granularity
    4. Mid-ResultSet kill via TCP abort (partial rows, then the connection dies — no protocol error needed)

    Naming: single package microburst with --protocol postgres; no microburst-core extraction yet — the seam is src/microburst/pg/ as a sibling transport, shared rule engine imported directly.

    Marking this in-progress — implementation starts after the current effects batch lands.

  3. self-assigned this
    on Oct 9, 2026
  4. pingedbrain commented on Oct 9, 2026

    @pingedbrain
    OwnerAuthor

    Phase 1 MVP landed in fb62d9c: src/microburst/pg/ (v3 frame codec, SSL/GSSENC refusal, ErrorResponse renderer with real SQLSTATE+severity, verb+table detector, asyncio TCP proxy), --protocol postgres flag, shared rule engine (sql: matcher, error.sqlstate alias, partial_rows). Verified live against real PG16 + psql: SCRAM passthrough, 53300 FATAL at startup, 40001 ERROR outside tx, tx-status-aware skip inside tx (fired note), partial_rows TCP-abort mid-ResultSet. Remaining for later phases: COPY interception, prepared-statement-by-name, Redis/MySQL same-seam.

  5. pingedbrain commented on Oct 10, 2026

    @pingedbrain
    OwnerAuthor

    Phase 1.5 landed in 8a11fea: Redis/RESP mode proves the sibling-transport seam generalizes — src/microburst/redis/ (RESP2+RESP3 codec, -LINE renderer, verb+key detector, asyncio proxy). --protocol redis --port 16379. Live-verified vs real Redis 7 + redis-cli: -MOVED/-ASK cluster redirects parse correctly in clients, MULTI-skip semantics (errors skip while queuing — fired note), cut_reply mid-bulk aborts, pub/sub splice passthrough. The seam held: rules engine/fired/metrics/stats/control API all shared, ~40 LOC of glue in cli.py.

  6. pingedbrain commented on Oct 10, 2026

    @pingedbrain
    OwnerAuthor

    Phase 2 complete — the seam is now proven at four transports. 10c6f8c: MySQL wire mode (, src/microburst/mysql/) — ERR packets with real errno+SQLSTATE (1213/40001 deadlock, 1040/08004 too-many-connections at handshake), tx-status-aware injection (SERVER_STATUS_IN_TRANS tracked), COM_STMT_PREPARE id→SQL map so sql: matches EXECUTE. Live-verified vs MariaDB 11.8 + mariadb client. ff1ff2d: generic TCP fallback (, user-declared length-prefix/delimiter/fixed framing, payload: byte-regex, respond: synthetic bytes) covers protocols without a dedicated module. The transports registry (src/microburst/transports.py) is the formal seam — new transports are registry entries + sibling packages. Remaining scope on this issue: gRPC trailers (HTTP/2 path), subscribe/stream-mode injection, TLS termination.

  7. pingedbrain commented on Oct 27, 2026

    @pingedbrain
    OwnerAuthor

    Status update: --protocol grpc landed in c10c99c — h2c transport with trailers-only and mid-stream (partial_messages) error injection, RST_STREAM aborts, and stalls with real flow-control backpressure. That leaves subscribe/stream-mode injection and TLS termination as the remaining scope on this issue.

  8. pingedbrain commented on Oct 28, 2026

    @pingedbrain
    OwnerAuthor

    Epic complete — every item has landed on main:

    • ✅ Protocol-agnostic core + TRANSPORTS registry (transports.py — run_* contract, schemes, per-transport options)
    • ✅ PostgreSQL wire mode (src/microburst/pg/) — SQLSTATE errors, tx-aware injection, startup refusals
    • ✅ Redis wire mode (src/microburst/redis/) — RESP2/RESP3, -CODE errors, MOVED/ASK, MULTI-aware skipping
    • ✅ MySQL wire mode (src/microburst/mysql/) — errno+SQLSTATE ERR_Packets, tx tracking, auth passthrough
    • ✅ Generic TCP (src/microburst/tcp/) + framing — protocol-blind transport faults
    • ✅ gRPC/h2c (src/microburst/grpc/) — trailers-only + mid-stream injection, RST_STREAM, flow-control stalls
    • ✅ Redis subscribe/push/MONITOR stream-mode injection — per-push decide with drop:/error:/latency/reset/cut_reply.after_messages (feat(redis): fault injection in pub/sub and MONITOR push streams #17)
    • ✅ TLS termination on the client leg via --tls-cert/--tls-key across all transports incl. https listener; pg SSLRequest→S and mysql SSLRequest upgrade in-band; upstream stays plaintext (feat(tls): client-side TLS termination via --tls-cert/--tls-key #19)

    ci on main is green. Remaining per-transport follow-ups live in ROADMAP's "What remains" lists (RESP3 blob-error synthesis, binlog/cursor streams, per-stream timers, etc.) — trackable as separate issues when needed.

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

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions