-
Notifications
You must be signed in to change notification settings - Fork 55
Feat/events socket #352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
GeoffChurch
wants to merge
10
commits into
shell-pool:master
Choose a base branch
from
GeoffChurch:feat/events-socket
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Feat/events socket #352
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7cb4e22
feat(events): define push-event JSON schema
GeoffChurch 3b466d9
feat(events): add EventBus and sibling events socket listener
GeoffChurch 2cdf4a3
feat(events): publish deltas from session lifecycle mutations
GeoffChurch 4448865
feat(events): add `shpool events` subcommand
GeoffChurch ecb5c3b
test(events): integration tests for the events socket
GeoffChurch d225ec7
fix(events): de-duplicate lifecycle deltas; clean socket on signal exit
GeoffChurch 12a8bc4
refactor(events): trim event payloads to type fields only
GeoffChurch 997d424
docs(events): add EVENTS.md describing the events protocol
GeoffChurch c1a03f2
Merge branch 'shell-pool:master' into feat/events-socket
GeoffChurch d418ffd
EVENTS.md: fix main socket description and remove "Ordering" section
GeoffChurch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| # Events | ||
|
|
||
| `shpool` exposes an event stream so that external programs can react to changes | ||
| without polling. This way, a program (e.g. a TUI) can call `shpool list` (or the | ||
| equivalent `ConnectHeader::List` request over the main socket; see the | ||
| [`shpool-protocol`](./shpool-protocol) crate) after each event so that its model | ||
| is always consistent with shpool's state. | ||
|
|
||
| ## The events socket | ||
|
|
||
| The daemon binds a sibling Unix socket next to the main shpool socket: | ||
|
|
||
| ```bash | ||
| <runtime_dir>/shpool/shpool.socket # main socket | ||
| <runtime_dir>/shpool/events.socket # events socket (this protocol) | ||
| ``` | ||
|
|
||
| A subscriber connects to `events.socket` and reads events. The daemon ignores anything written to the events socket, so for subscribers it's effectively read-only. | ||
|
|
||
| ## Event types | ||
|
|
||
| | `type` | Meaning | | ||
| | ------------------ | -------------------------------------------------------- | | ||
| | `session.created` | A new session was added to the table. | | ||
| | `session.attached` | A client attached or reattached to a session. | | ||
| | `session.detached` | A client disconnected from a still-running session. | | ||
| | `session.removed` | A session was removed (shell exited, killed, or reaped). | | ||
|
|
||
| Subscribers should ignore unknown `type` values so that future event types do | ||
| not break older consumers. | ||
|
|
||
| ## Wire format | ||
|
|
||
| The daemon writes one JSON object per line (JSONL). Each event looks like: | ||
|
|
||
| ```json | ||
| {"type":"<event-type>"} | ||
| ``` | ||
|
|
||
| There are no other fields. To learn what the event refers to (which session, | ||
| when, etc.), call `shpool list` (or use `ConnectHeader::List`). | ||
|
|
||
| ## Subscribing | ||
|
|
||
| For ad-hoc use, `shpool events` connects to the events socket and prints each | ||
| event line to stdout, flushing after each line: | ||
|
|
||
| ```bash | ||
| shpool events | while read -r ev; do | ||
| echo "got: $ev" | ||
| shpool list | ||
| done | ||
|
|
||
| shpool events | jq . | ||
| ``` | ||
|
|
||
| ## Slow subscribers | ||
|
|
||
| Each subscriber has a bounded outbound queue. A subscriber that falls too far | ||
| behind is dropped by the daemon (in which case the subscriber can always reconnect). | ||
| There is no replay, so events that fired while a subscriber was disconnected are | ||
| lost. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we should document a knob in the config.toml that tunes how large this queue is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want the config knob added in this PR?
The queues currently use
std::sync::mpsc::sync_channelhere, pre-allocating allSUBSCRIBER_QUEUE_DEPTHslots.Would you want to use something slightly slower that allocates on-demand and has something like
shrink_to_fitto return memory after a spike? I'm just imagining if someone sets their queue depth to 1 billion not expecting it to pre-allocate for each subscriber. If it instead allocates on-demand you could maybe set the queue depth to something large like 100K by default anyway, at which point maybe it wouldn't be worth offering a config knob.