How streamview works
streamview is one program. This page describes its parts, and the reasons for the design.
The parts
Section titled “The parts”| Part | What it is | What it does |
|---|---|---|
| Adapter | A Node.js program, one for Kafka and one for NATS | Reads a broker, and prints each message as one event. |
| Server | A Rust program | Accepts events, puts them in sequence, stores them, and sends them to the pages. |
| Store | A SQLite file | Keeps the events and the settings. |
| Engine | Rust code that the build compiles to WebAssembly | Runs in the browser. Keeps all events in memory, and answers the questions of the page. |
| Page | One HTML file | Draws the timeline, and handles the mouse and the keyboard. |
The streamview program contains the server, the engine, the page, the fonts, and the source code of the two adapters.
The path of one event
Section titled “The path of one event”- A service publishes a message to a broker.
- The adapter reads the message, and prints it as one line of JSON in the CloudEvents format.
- The server reads the line. It rejects the line if it is not an event, and ignores it if it is a duplicate.
- The server holds the event for a short time, and puts it in sequence by time.
- The server writes the event to the SQLite file.
- The server sends the event to each open page, in a compact binary format.
- The engine in the browser adds the event to its memory.
- The page draws the timeline again.
When you click an event, the page gets the full JSON of that event from the server.
Why the engine runs in the browser
Section titled “Why the engine runs in the browser”When you zoom or move, the page must count the events of each lane for each bar, many times each second. If the server did this work, each movement would need a request and an answer.
The engine has all events in the memory of the browser. Thus each frame needs no request. The bottom right of the page shows the time that the engine and the frame use.
This design has a cost: the browser keeps all events in memory.
The --keep option limits the number of events. See Limit how long streamview keeps events.
Why the adapters are separate programs
Section titled “Why the adapters are separate programs”The server knows nothing about Kafka, NATS, or RabbitMQ. It reads lines of JSON from a file, from standard input, or from HTTP.
streamview kafka and streamview nats start the adapter as a child program, and read its output.
The adapter stops when streamview stops.
This design has two effects:
- You can write an adapter for a different broker in any language. It must only print one event on each line.
- The two adapters use the usual client libraries for Node.js. Thus these two commands need Node.js.
Why SQLite
Section titled “Why SQLite”The store must keep events when the server stops, and must need no other program. A SQLite file does both.
The server loads the file at the start. The pages do not read the file directly.
Why one program
Section titled “Why one program”A tool that you use during an incident must start fast. With one program, there is one thing to install, and one command to start.