Skip to content
Go back
Spate

An at-least-once ETL pipeline framework written in Rust.

Work feed call metrics in Spate

core: count feed calls under spate_feed_*

No Spate work feed backend exported metrics, so operators could not see how many units a worker held or how fast it settled them. The runtime now records feed calls under `spate_feed_*` for every backend.

Status
Merged
Merged
30 Oct 2026
Area
Observability
Rust
Diff
993 lines added and 34 removed across 17 files

The problem

In version 0.3 its instances shared S3 input through split coordination, where a leader cut the input into splits and leased them out over a NATS store. The lease and commit logic was hard to keep correct, with 14 defects still open when it was deprecated, and it slowed as hosts were added.

A leader hands splits of the input to instances. Every lease, renewal and commit is written to a shared NATS store, and the writes come faster when a third instance joins. A leader hands splits of the input to instances. Every lease, renewal and commit is written to a shared NATS store, and the writes come faster when a third instance joins.

Like a manager who divides a pile of paperwork between staff and logs every hand-over in a shared ledger.

// Spate 0.3, simplified. Each highlighted line is a fenced write to the
// shared store, so two instances never commit the same split.
for split in list(prefix).chunks(split_size) {
    store.write_fenced(lease(split, instance))?; 
}

// On the instance holding the split, while it reads, then once it is done
store.write_fenced(renewal(split))?; 
store.write_fenced(commit(split))?; 

Version 0.4 replaces it with a work feed, a queue of work units that a source reads through. A worker receives a unit, renews it while it holds it, then settles it by acknowledging it, failing it or handing it back.

Two workers take units from a queue in turn, read them and move them to an acknowledged tray. Two workers take units from a queue in turn, read them and move them to an acknowledged tray.

Closer to a shared tray, where each person takes the next item and an item nobody finishes goes back in the tray.

// Spate 0.4, simplified from the S3 source, on Spate's Feed trait.
for delivery in feed.receive(units_free)? {
    read(&delivery);
    feed.renew(delivery.receipt)?; // while it reads
    feed.acknowledge(delivery.receipt)?; // or fail, or hand_back on a stop
}
// No call waits on the network. The backend talks to SQS or Kafka in the background.

The coordination metrics go when the crate is removed, and no feed backend exported any in their place. An operator could not see how many units a worker held, how fast units settled, how often a renewal found its unit gone or how long feed calls took. The metrics had to land first.

What I changed

Every call goes through one helper, which times it and counts any error.

// crates/spate-core/src/feed/metered.rs
fn call<T>(
    &self,
    op: FeedOp,
    call: impl FnOnce() -> Result<T, FeedError>,
) -> Result<T, FeedError> {
    let watch = Stopwatch::start(&*self.clock); 
    let result = call();
    self.metrics.call(op, watch.elapsed(&*self.clock)); 
    if let Err(e) = &result {
        self.metrics.error(op, e.kind); 
    }
    result
}

Tests pin that each call reaches the backend once and returns its answer, that the held gauge is claimed once per pipeline, and that a running pipeline counts what its source does.

Seeing it work

I ran two workers on one queue, against local stand-ins for S3 and SQS, with Prometheus, Loki and Grafana watching. Then I broke things on purpose. I shortened the lease from 60s to 15s and slowed the sink so each case plays out in seconds. The diagrams show what happens to the work, and the numbers come from that run.

A worker dies

Worker A stops while holding two units. Their lease runs out, they return to the queue, and worker B reads them. Worker A stops while holding two units. Their lease runs out, they return to the queue, and worker B reads them.

I killed one worker with no chance to drain. Its units stayed hidden until their lease ran out, then went back to the queue for the other worker. spate_feed_held_units showed the survivor rise from about 2.5 units to its cap of 8, and its settle rate from 0.8 to 1.4 units a second. A worker I froze for 30 seconds instead came back to 8 renewals refused as gone, one for each unit the queue had handed on.

A poisoned unit

A message that is not a notification is failed back by worker A, then worker B, five times in all, then moves to the dead-letter queue. A message that is not a notification is failed back by worker A, then worker B, five times in all, then moves to the dead-letter queue.

I sent the queue a message that is not a storage notification, then a notification for an object that does not exist. The workers failed each one back, and the queue moved each to its dead-letter queue on the fifth delivery. spate_feed_units_failed_total rose by 10, the dead-letter gauge from #1515 read 2, and the settle rate did not dip.

A poisoned record

A worker writes a unit's records to the sink. One record does not decode and goes to a skipped bin. The unit is still acknowledged. A worker writes a unit's records to the sink. One record does not decode and goes to a skipped bin. The unit is still acknowledged.

A bad line inside a good object is a different failure. The deserialiser skipped it and counted it under spate_deser_records_total{outcome="error"}, and the unit was acknowledged as normal. The feed families stayed quiet, which tells an operator the queue is not the place to look.

The sink goes down

A worker holds four units while the sink is down, renewing them every second. New work waits in the queue. When the sink returns, the held units are written. A worker holds four units while the sink is down, renewing them every second. New work waits in the queue. When the sink returns, the held units are written.

For 40 seconds every write to the sink failed. Each worker kept renewing the 8 units it held, so the queue gave none of them away, and new work waited in the queue. The sink retried about 18 writes, settling fell almost to zero and no renewal came back gone. When the sink returned, the held units were written and acknowledged.

Grafana during the sink outage. Units held per worker climb to 8 and stay there, units settled per second fall towards zero and recover, sink write retries rise, and the feed errors panel has no data.

What the feed metrics don’t show

Freezing the queue or the object store for 30 seconds moved no spate_feed_* error. Feed calls never wait on the network, so a short outage behind them shows only as slower settling. The queue freeze changed nothing visible, and the store freeze halved the settle rate.

Judgement calls

I reused existing labels and error series instead of adding new ones. The issue proposed a backend label and a counter for units gone after a refused renewal. I dropped both. component_type already carries the backend key, so a backend label would repeat it on every series. A refused renewal already appears as spate_feed_errors_total{op="renew",error_type="gone"}, so a second counter would count the same event twice. The issue marked its metric names as illustrative.

I split the issue across three pull requests. The issue also asked for a Meter for each backend. That went to #1516 and the dead-letter depth to #1515, so this change holds only the wrapper and its families. The hand_back call arrived after the issue was written, so I added spate_feed_units_handed_back_total for it.

I left calls made through a handle the caller keeps from Pipeline::feed uncounted, because the runtime wraps only the feed it hands the source. The metrics reference says so.

What review changed

The review found three behaviours that no test pinned. For each they showed a one-line change that still passed all 607 tests. A publish the backend dropped was not checked as a retryable error, the feed was not checked against the injected clock, and publish call time was not checked at all. I added a test for each.

The review also asked for the Pipeline::feed rustdoc and the Kafka and SQS feed pages to mention the new families. I added those and fixed two guides with the same gap. I skipped one assertion in the suggested test, because the error count already fails when either code path changes.

Outcome

Merged on 30 October 2026, the morning after it was opened. It gave feeds metrics before the coordination crate’s removal, and is the first of three pull requests for #1196.

Timeline

  1. 29 Oct 2026
    Pull request opened
  2. 30 Oct 2026
    Merged the same day
  3. 1 Nov 2026
    Released in Spate v0.4.0

All open source work →All case studies →