fleetwire

module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2026 License: Apache-2.0

README

fleetwire

A telemetry pipeline for fleets of Ubuntu Core devices that stores every reading exactly once, through network cuts, broker and database outages, process kills and power loss, and keeps each tenant's data apart and encrypted with the tenant's own keys.

For every device, every seq that left the device is, after the system recovers, either stored exactly once, or covered by a gap that the device itself reported. No seq is stored twice. No seq disappears without a report.

The agent keeps each reading on disk until an end-to-end acknowledgement says it is stored. Every hop in between (MQTT QoS 1, Kafka, the consumer group) may lose or repeat messages, and the agent resends until the ack comes. Ingest removes the repeats under a per-device row lock, and a PostgreSQL exclusion constraint makes storing a seq twice impossible. The delivery guarantee has the argument and its limits.

flowchart LR
  subgraph Device["Device: strict snap on Ubuntu Core 24"]
    C[Collectors] --> W[(Local log)] --> S[Uplink]
  end
  S -- "MQTT v5, mTLS" --> M[Mosquitto]
  M -- "shared subscription" --> B[Bridge x2]
  B -- "acks=all" --> K[(Kafka x3)]
  K --> I[Ingest x2]
  I -- "one transaction per batch,\nencrypted with tenant keys" --> P[(PostgreSQL\nrow-level security)]
  I -- "end-to-end ack" --> M --> S
  A[API, jobs, CRL] --> P
  S -- "enroll, renew" --> A

Results

Every scenario runs the real stack (make up) with thousands of real agent instances in one process, injects the fault (or kills the process), keeps the load on, and then reads everything back from the database, decrypted. A scenario passes only with 0 missing and 0 duplicate seqs. Recovery is the time from the end of the fault until the p99 delay from collection to commit is under 5 s again.

All runs below used one UpCloud VM (4 vCPU AMD EPYC 9575F, 8 GB RAM, Ubuntu 26.04) for the load generator, the whole stack and the observability tools, at commit add94424b241. The tables, with the exact commands, are in docs/results/.

2,000 devices, one reading every 10 s each, device state on disk (make chaos):

Scenario Readings Missing Duplicates Recovery Result
network cut, 60 s 44,314 0 0 1m16s PASS
network degraded (300 ± 200 ms, 512 KB/s, 5% resets), 120 s 51,659 0 0 0s PASS
Mosquitto restart 23,604 0 0 0s PASS
one Kafka broker killed, 60 s 35,667 0 0 0s PASS
all Kafka brokers stopped, 60 s 41,088 0 0 52s PASS
PostgreSQL killed, 60 s 35,688 0 0 36s PASS
bridge SIGKILL, 30 s 34,109 0 0 0s PASS
ingest SIGKILL, 30 s 35,205 0 0 0s PASS
agent SIGKILL (all 2,000 at once) 23,234 0 0 0s PASS

10,000 devices, one reading every 10 s each (1,000 readings/s), device state on tmpfs (see Limitations):

Scenario Readings Missing Duplicates Recovery Result
network cut, 60 s 482,255 0 0 4m48s PASS
network degraded, 120 s 647,059 0 0 6m40s PASS
Mosquitto restart 411,034 0 0 4m33s PASS
one Kafka broker killed, 60 s 681,276 0 0 8m17s PASS
all Kafka brokers stopped, 60 s 794,433 0 0 > 10m PASS
PostgreSQL killed, 60 s 792,362 0 0 > 10m PASS
bridge SIGKILL, 30 s 590,336 0 0 7m2s PASS
ingest SIGKILL, 30 s 765,866 0 0 > 10m PASS
agent SIGKILL (all 10,000 at once) 280,421 0 0 3m2s PASS

Every reading was stored exactly once, but not on time. The VM was saturated (load average about 90, 4 GB in swap): in the steady minute before each fault ingest stored 870 to 990 readings/s, a backlog of about 20,000 records from the ramp-up never cleared, and the p99 delay was about 30 s. Recovery, measured as "p99 under 5 s again", took minutes; "> 10m" means the runner stopped waiting.

Power loss: 10 hard resets (QMP system_reset) of a VM running the agent snap, at random moments, with a reading every 200 ms and wal.sync=interval: 9,089 readings, all acknowledged, 0 missing, 0 duplicates. The VM ran Ubuntu Server 24.04, not Ubuntu Core (see Limitations).

Target Measured
Correctness: 0 missing, 0 duplicates in every failure scenario Met: 9 of 9 at 2,000 devices, 9 of 9 at 10,000, and 10 power cuts
Scale: 10,000 devices, one reading every 10 s, on one dev VM All 10,000 ran and every reading was stored once, with the devices' state on tmpfs; with it on the database's disk, ingest stored about 770 of 1,000 readings/s
Latency: p99 from collection to commit under 5 s at normal load Met at 2,000 devices: p99 2.49 s, p50 2.20 s over 6 steady minutes, most of it the agent's own 1 s batch wait and 1 s fsync interval. Not met at 10,000: about 30 s
Throughput: highest rate before the lag keeps growing 1,000 batches/s of one reading (p99 2.5 s); at 1,500/s the lag crept up. In batches of 64, 32,000 readings/s (table)
Agent: under 30 MB RSS, binary under 20 MB 19.7 to 21.9 MB RSS (the snap daemon, and an agent with six collectors over 12 minutes); binary 16.2 MB, snap 5.2 MB

Quick start

You need Linux with Docker (Compose v2), Go (the version in go.mod) and make.

$ make demo        # dev CA, stack, migrations, 5 real agents, 60 s of data
$ make e2e         # end-to-end test against the stack
$ make chaos SCENARIOS=network-cut,ingest-kill DEVICES=200

make demo prints the tenant token and where to look: the API (with fwctl), Grafana on http://localhost:3000, Prometheus and Jaeger. The tutorial walks through it, and Run the failure tests covers the suite.

On a device, build the snap (make snap, snapcraft with LXD) and install it; it is not in the Snap Store yet:

$ sudo snap install --dangerous ./fleetwire-agent_*.snap
$ sudo snap set fleetwire-agent enroll.url=https://api.example.com:8444 enroll.token=fwe_...

On Kubernetes, the Juju charms deploy the backend with Charmed PostgreSQL and Charmed Kafka: Deploy with Juju.

Tagged releases attach Linux binaries, fwctl for Linux and macOS, SPDX SBOMs and a signed checksum file, and push the API, bridge and ingest images to GHCR. Verify a release shows how to check the signatures.

What is in the repository

Path What
cmd/fleetwire-agent, internal/agent, internal/wal the device agent, its local log and uplink
cmd/fleetwire-bridge, internal/bridge Mosquitto to Kafka, acking only after Kafka confirms
cmd/fleetwire-ingest, internal/ingest, internal/coverage exactly-once storage, encryption, acks
cmd/fleetwire-api, internal/api, internal/jobs, api/openapi.yaml tenant, operator and device API; retention, exports, destroy
internal/store PostgreSQL schema, row-level security, migrations
cmd/fwctl the CLI
cmd/fleetwire-loadgen, -checker, -chaos, scripts/throughput.sh load generator, checker, failure suite, throughput search
snap/, deploy/ubuntu-core/ the agent snap and the VM scripts for the power-off test
charms/ Juju charms, the bundle and its integration test
deploy/compose/, deploy/prometheus/, deploy/grafana/ development stack, SLO rules, dashboard
docs/ Sphinx docs (Diátaxis) and the ADRs

Limitations

  • 10,000 devices are more than the test VM serves on time. Every reading was stored once, but with the load generator, the stack and the observability tools on 4 vCPUs and 8 GB, the p99 delay was about 30 s. Even that needs the devices' state on tmpfs: each simulated device fsyncs its local log and state file, as a real device does on its own disk, and on one VM those fsyncs, about 3,000 a second, share the disk with PostgreSQL's commits. With the state on disk, ingest stored about 770 of the 1,000 readings/s offered. The tmpfs runs do not test power loss; the power-off test does.
  • The power-off test ran on Ubuntu Server 24.04, not Ubuntu Core. Ubuntu Core's first boot needs an Ubuntu One account, so it could not be automated. The agent ran as the same strict snap on a real kernel and ext4, under QEMU without KVM; Ubuntu Core's own boot and partition layout were not tested.
  • The agent snap is not in the Snap Store. Build it with make snap and install it with --dangerous. The release publishes binaries and container images only.
  • One API unit on Kubernetes. The local keyring keeps the tenant KEKs on the unit's storage. A Vault or KMS keyring backend would lift this.
  • Revocation at the broker lags on Kubernetes by up to the update-status interval (5 minutes by default). Ingest drops a revoked device's data at once; in Compose the broker reloads its CRL within seconds.
  • Charmed PostgreSQL must be dedicated to fleetwire: the runtime logins' charmed_dml role can read and write every database of the cluster.
  • Row-level security guards against tenant-scoping mistakes, not a compromised service: any session of the runtime role can choose a tenant. What such a service cannot do is change the schema, drop the policies or rewrite the audit log.
  • Destroying a tenant deletes its KEK file, which is not a secure erase on an SSD; production should use a KMS with real key destruction.
  • The database cannot aggregate readings: they are encrypted with tenant keys, so the API decrypts them for every query.
  • Latency uses the device's clock (collection time to commit), so a device with a wrong clock skews the delay SLO; fleetwire_ingest_clock_skew_seconds shows how far off devices are.
  • The load generator's devices share one kernel, network stack and disk, and their reading values are synthetic; see how it differs from a real device.

Future work

  • A Vault Transit or cloud KMS keyring backend: real key destruction, and more than one API unit on Kubernetes. The Keyring interface is ready.
  • Over-the-air agent updates beyond what snap refreshes give.
  • A web frontend; aggregation and downsampling of readings.
  • Rocks for the workloads and deb packages for non-snap systems.
  • Multi-region replication.

License

Apache License 2.0. Copyright Reda Alaarabi.

Directories

Path Synopsis
Package openapi embeds the API description, so tests and tools use the exact file that is published.
Package openapi embeds the API description, so tests and tools use the exact file that is published.
cmd
fleetwire-agent command
Command fleetwire-agent is the device agent.
Command fleetwire-agent is the device agent.
fleetwire-api command
Command fleetwire-api runs the tenant, operator and device API, the background job worker, and the CRL publisher.
Command fleetwire-api runs the tenant, operator and device API, the background job worker, and the CRL publisher.
fleetwire-bridge command
Command fleetwire-bridge moves device messages from Mosquitto to Kafka.
Command fleetwire-bridge moves device messages from Mosquitto to Kafka.
fleetwire-chaos command
Command fleetwire-chaos runs the failure scenarios against the Compose stack and writes the results table into docs/results/.
Command fleetwire-chaos runs the failure scenarios against the Compose stack and writes the results table into docs/results/.
fleetwire-checker command
Command fleetwire-checker reads stored data back and proves that every seq of every device is stored exactly once or covered by a reported gap.
Command fleetwire-checker reads stored data back and proves that every seq of every device is stored exactly once or covered by a reported gap.
fleetwire-ingest command
Command fleetwire-ingest stores uplink batches from Kafka in PostgreSQL exactly once and publishes end-to-end acks.
Command fleetwire-ingest stores uplink batches from Kafka in PostgreSQL exactly once and publishes end-to-end acks.
fleetwire-loadgen command
Command fleetwire-loadgen runs many real agent instances in one process.
Command fleetwire-loadgen runs many real agent instances in one process.
fwctl command
Command fwctl is the command-line client for the fleetwire API.
Command fwctl is the command-line client for the fleetwire API.
internal
agent
Package agent is the device runtime: it wires the collectors, the local log, the uplink, the MQTT connection, enrollment and certificate renewal.
Package agent is the device runtime: it wires the collectors, the local log, the uplink, the MQTT connection, enrollment and certificate renewal.
agent/collect
Package collect holds the agent's reading sources.
Package collect holds the agent's reading sources.
agent/config
Package config is the agent's configuration: one set of keys, read from `snapctl get -d` inside the snap, or from a JSON file and -set flags outside it, and checked by one validation path in both cases (R10.4).
Package config is the agent's configuration: one set of keys, read from `snapctl get -d` inside the snap, or from a JSON file and -set flags outside it, and checked by one validation path in both cases (R10.4).
agent/uplink
Package uplink sends durable readings from the local log and handles end-to-end acks (design 6.3, R3).
Package uplink sends durable readings from the local log and handles end-to-end acks (design 6.3, R3).
api
Package api is fleetwire's HTTP API: the tenant and operator API on the public listener, and enrollment and renewal on the device listener.
Package api is fleetwire's HTTP API: the tenant and operator API on the public listener, and enrollment and renewal on the device listener.
api/apitest
Package apitest runs a real fleetwire API for tests: real PostgreSQL, the real dev PKI, real TLS listeners, and the real job worker.
Package apitest runs a real fleetwire API for tests: real PostgreSQL, the real dev PKI, real TLS listeners, and the real job worker.
backoff
Package backoff implements exponential backoff with full jitter.
Package backoff implements exponential backoff with full jitter.
bridge
Package bridge moves device messages from Mosquitto into Kafka (R5).
Package bridge moves device messages from Mosquitto into Kafka (R5).
buildinfo
Package buildinfo holds version information stamped into binaries at link time.
Package buildinfo holds version information stamped into binaries at link time.
chaos
Package chaos runs the failure scenarios against the Compose stack and writes the results table (R12.2, R12.4, design 15.3).
Package chaos runs the failure scenarios against the Compose stack and writes the results table (R12.2, R12.4, design 15.3).
checker
Package checker proves the delivery guarantee by reading the stored data back (R12.1, design 15.2).
Package checker proves the delivery guarantee by reading the stored data back (R12.1, design 15.2).
chunks
Package chunks seals readings into chunk rows and opens them again.
Package chunks seals readings into chunk rows and opens them again.
config
Package config loads service settings from environment variables and command-line flags into a tagged struct.
Package config loads service settings from environment variables and command-line flags into a tagged struct.
coverage
Package coverage holds the interval logic behind exactly-once storage.
Package coverage holds the interval logic behind exactly-once storage.
crl
Package crl publishes the device certificate revocation list.
Package crl publishes the device certificate revocation list.
crypto/envelope
Package envelope seals stored readings with AES-256-GCM.
Package envelope seals stored readings with AES-256-GCM.
crypto/keyring
Package keyring holds the per-tenant key-encryption keys (KEKs) that wrap tenant data keys.
Package keyring holds the per-tenant key-encryption keys (KEKs) that wrap tenant data keys.
fsutil
Package fsutil writes files so that a crash or power cut leaves either the old content or the new, never a mix.
Package fsutil writes files so that a crash or power cut leaves either the old content or the new, never a mix.
identity
Package identity is the device's key, certificate and enrollment state.
Package identity is the device's key, certificate and enrollment state.
ingest
Package ingest stores uplink batches exactly once (R6, ADR-0005).
Package ingest stores uplink batches exactly once (R6, ADR-0005).
jobs
Package jobs runs fleetwire's background jobs inside fleetwire-api: retention, exports, device purges and tenant destroys.
Package jobs runs fleetwire's background jobs inside fleetwire-api: retention, exports, device purges and tenant destroys.
kafkahdr
Package kafkahdr names the Kafka record headers shared by the bridge and ingest, and adapts them for OpenTelemetry context propagation.
Package kafkahdr names the Kafka record headers shared by the bridge and ingest, and adapts them for OpenTelemetry context propagation.
loadgen
Package loadgen runs many devices in one process (R11).
Package loadgen runs many devices in one process (R11).
lru
Package lru is a small size-bounded cache with optional expiry, safe for concurrent use.
Package lru is a small size-bounded cache with optional expiry, safe for concurrent use.
mqttconn
Package mqttconn sets up MQTT v5 connections the same way for the agent, the bridge and the ingest service: TLS client certificates, a persistent session, reconnects with full-jitter backoff, and connection metrics.
Package mqttconn sets up MQTT v5 connections the same way for the agent, the bridge and the ingest service: TLS client certificates, a persistent session, reconnects with full-jitter backoff, and connection metrics.
pki
Package pki issues device certificates and certificate revocation lists.
Package pki issues device certificates and certificate revocation lists.
pki/devpki
Package devpki creates the development certificate authorities and certificates for the Compose stack and the tests:
Package devpki creates the development certificate authorities and certificates for the Compose stack and the tests:
store
Package store is the only code that talks SQL to PostgreSQL.
Package store is the only code that talks SQL to PostgreSQL.
store/storetest
Package storetest starts a real PostgreSQL for integration tests.
Package storetest starts a real PostgreSQL for integration tests.
svc
Package svc holds the start-up code shared by the backend binaries: signal handling, logging, tracing, the admin server, and mTLS client configs for the broker.
Package svc holds the start-up code shared by the backend binaries: signal handling, logging, tracing, the admin server, and mTLS client configs for the broker.
telemetry
Package telemetry sets up logging, metrics and tracing the same way for every fleetwire binary: JSON logs through log/slog, a Prometheus registry, and OpenTelemetry traces exported over OTLP/HTTP.
Package telemetry sets up logging, metrics and tracing the same way for every fleetwire binary: JSON logs through log/slog, a Prometheus registry, and OpenTelemetry traces exported over OTLP/HTTP.
tenantkey
Package tenantkey manages tenant data keys (DEKs): creating them, picking the one that seals new chunks, rotating it, and caching unwrapped keys for a short time so that every chunk does not cost a keyring call.
Package tenantkey manages tenant data keys (DEKs): creating them, picking the one that seals new chunks, rotating it, and caching unwrapped keys for a short time so that every chunk does not cost a keyring call.
tokens
Package tokens creates and parses fleetwire's bearer tokens.
Package tokens creates and parses fleetwire's bearer tokens.
uplinkpb
Package uplinkpb decodes and validates uplink batches.
Package uplinkpb decodes and validates uplink batches.
wal
Package wal is the device-side write-ahead log.
Package wal is the device-side write-ahead log.
scripts
dev-ca command
Command dev-ca creates the development PKI for the Compose stack:
Command dev-ca creates the development PKI for the Compose stack:

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL