Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmd/fabric-api/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@ func runGateway(parent context.Context, o *gatewayOptions) error {
}
}()
defer gs.Stop()
// A shutdown signal closes every connection at once, so a service
// stream's routers stop within 2 s rather than running on while the
// manager shuts down.
defer context.AfterFunc(ctx, gs.Stop)()

slog.Info("starting fabric-api gateway", "version", metadata.Version, "site", o.site, "cluster", o.clusterName,
"cell", o.cell, "debug", debugAddr)
Expand Down
3 changes: 2 additions & 1 deletion docs/agents/ARCHITECTURE-FABRIC-API.md
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,8 @@ manifest sets yet (see
| `internal/fabric/gateway/limit` | `Limits` and `Validate`; `Buckets` (request and packet token buckets, never negative, key families bounded without evicting debt); `Attempts` (duplicate attempt keys, fail closed); `Authority` (uncached Lease check, epoch, 125 s recovery hold, `Watch`) | Buckets, attempt keys, epoch (memory) |
| `internal/fabric/gateway` (`discovery.go`) | Pod snapshot with omission reasons, one pod per node, node budget, node-to-certs-pod mapping (`NoCertificatePod`); `Inventory`, the service's one-router-per-node snapshot (newest usable pod, `NotRequested`, `NoSidecar`, unscheduled count, 256-router cap) | No |
| `internal/fabric/gateway` (`debug.go`) | Operator debug service, leader forwarding through the election lease | Connection to the leader |
| `internal/fabric/gateway` (`service.go`) | `NewServer`, service `Allowlist`, Looking Glass service authorization and attribution validation, one-hop typed forwarding to the leader, capabilities, and (when `Enabled`) streamed execution with terminal coverage | No |
| `internal/fabric/gateway` (`service.go`) | `NewServer`, service `Allowlist`, Looking Glass service authorization and attribution validation, one-hop typed forwarding to the leader, capabilities, and (when `Enabled`) streamed execution with terminal coverage and its output budget | No |
| `internal/fabric/gateway` (`stream.go`) | Delivery and transport bounds: the single stream writer with its 2 s write bound, per-replica call and service connection caps, fixed windows and keepalive on the listener and the follower's leader connection | No |
| `internal/fabric/gateway` (`janitor.go`) | `Janitor.Sweep`, `StaleCounter` | No |
| `internal/fabric/gateway` (`metrics.go`) | `fabric_api_gateway_*` and shared `fabric_api_*` collectors | Prometheus collectors |
| `internal/fabric/api/v1alpha1` | `FabricQuery` Go types with kubebuilder markers, condition and reason constants, request labels | No |
Expand Down
21 changes: 21 additions & 0 deletions docs/fabric-api/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,27 @@ until the job's deadline plus 2 seconds, since the node may still be sending
it. The rates and caps are the contract's defaults; only `--cell-slots` and
`--cell-queue` change them.

### Stream delivery and transport bounds

Every gateway replica bounds Looking Glass service delivery, whether or not
`--aggregate-budgets` is set. None of these values is configurable:

| Bound | Value | Past it |
| -------------------------------------------------------------------------------------------- | ---------------------------------- | ----------------------------------------------------------------------------------------- |
| One write to the consumer, or a finished outcome waiting for the stream's two-outcome buffer | 2 s | The request is cancelled and its stream ends `CANCELLED`; its routers stop |
| One outcome event | 144 KiB | The router's outcome is a `ResponseTooLarge` failure |
| Serialized events of one stream | 5 MiB | That router and every router still running fail `OutputLimitExceeded`, as does `complete` |
| `RunDiagnostic` calls / forwarded calls | 32 / 16 per replica | `QueueFull` with a 1 s retry delay |
| Service identity TLS connections | 64 per replica | The connection is closed after its handshake |
| A silent connection | Pinged after 4 s, closed 4 s later | Its calls are cancelled |

Every connection to the listener, and a follower's connection to the leader,
uses fixed 64 KiB flow-control windows and buffers. A follower relays one event
at a time under the same 2 s write bound, and never forwards a call twice. A
client may ping no more often than every 5 seconds. On `SIGTERM` the gateway
closes its listener's connections at once, cancelling operator and service
calls in flight.

### Enabling

The deployment manifests do not set these flags yet. Turn them on in this
Expand Down
14 changes: 10 additions & 4 deletions docs/fabric-api/service-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,16 @@ requires the gateway's admission, and capabilities advertise
`aggregate-probe-budgets` only while execution is enabled with it. Nodes
charge direct operator probes only with `--require-probe-permits`, so enabling
execution requires every node to run with it. No deployment sets `Enabled` or
these flags, so a valid `RunDiagnostic` is answered with `ServiceDisabled`. Not yet implemented: the blocked-send bound and
stream-level ownership rules of #1046, and the metrics and packaged
configuration of #1047. Operator and FabricQuery discovery still return pod
candidates, including duplicates.
these flags, so a valid `RunDiagnostic` is answered with `ServiceDisabled`.
The delivery and transport bounds under "Cancellation, delivery, and failure
assumptions" are enforced (#1046): one writer per stream, the 2 s write and
hand-off bound on the leader and on a forwarding follower, the per-outcome and
per-stream output caps, the per-replica call and service connection caps,
fixed 64 KiB windows and buffers, and keepalive on the gateway listener
(`internal/fabric/gateway/stream.go`). A shutdown signal stops the listener at
once. Service disable is a startup setting until #1047 adds its controls, and
the metrics and packaged configuration are #1047's. Operator and FabricQuery
discovery still return pod candidates, including duplicates.

## Service and identity

Expand Down
4 changes: 4 additions & 0 deletions internal/fabric/errcode/errcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ const (
// DuplicateRequest means a request ID was reused with identical
// arguments; it is never answered with a saved result.
DuplicateRequest Code = "DuplicateRequest"
// OutputLimitExceeded means a Looking Glass service stream's output
// budget cannot hold another router's result.
OutputLimitExceeded Code = "OutputLimitExceeded"
)

// grpcCodes maps each code to the gRPC status code it travels as.
Expand Down Expand Up @@ -128,6 +131,7 @@ var grpcCodes = map[Code]codes.Code{
QueueFull: codes.ResourceExhausted,
LimiterUnavailable: codes.Unavailable,
DuplicateRequest: codes.AlreadyExists,
OutputLimitExceeded: codes.ResourceExhausted,
}

// MetadataQueryCode is the ErrorInfo metadata key carrying the query
Expand Down
2 changes: 1 addition & 1 deletion internal/fabric/gateway/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func (d *Debug) conn(addr string) (*grpc.ClientConn, error) {
// A forwarded call may already have run on the leader, so it is
// never replayed, not even transparently.
grpc.WithDisableRetry(),
}, d.DialOptions...)
}, append(leaderDialOptions(), d.DialOptions...)...)
c, err := grpc.NewClient(addr, opts...)
if err != nil {
return nil, err
Expand Down
12 changes: 10 additions & 2 deletions internal/fabric/gateway/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,21 +238,29 @@ func (r *Runner) fanOut(ctx context.Context, project, requestID string, q query.
// cancelled when the gateway loses the election.
var errOwnershipLost = errors.New("the gateway lost execution ownership")

// errOutputLimit is the cause with which a service request's execution is
// cancelled when its stream's output budget runs out.
var errOutputLimit = errors.New("the stream's output budget is exhausted")

// requestErr reports a failure that ctx's end, or the request's expiration,
// caused as the request's own DeadlineExceeded, Cancelled or, when the
// election was lost, OwnershipLost.
// election was lost or the output budget ran out, OwnershipLost or
// OutputLimitExceeded.
func requestErr(ctx context.Context, err error, expired bool) error {
if err == nil || (ctx.Err() == nil && !expired) {
return err
}
switch errcode.Of(err) {
case errcode.Timeout, errcode.NodeUnreachable, errcode.QueueTimeout:
case errcode.Timeout, errcode.NodeUnreachable, errcode.QueueTimeout, errcode.Cancelled:
default:
return err
}
if errors.Is(context.Cause(ctx), errOwnershipLost) {
return errcode.Status(errcode.OwnershipLost, "the gateway lost execution ownership before the router finished")
}
if errors.Is(context.Cause(ctx), errOutputLimit) {
return errcode.Status(errcode.OutputLimitExceeded, "the stream's output budget ran out before the router finished")
}
if expired || errors.Is(ctx.Err(), context.DeadlineExceeded) {
return errcode.Status(errcode.DeadlineExceeded, "the request's deadline passed before the router finished")
}
Expand Down
Loading
Loading