-
Notifications
You must be signed in to change notification settings - Fork 9
Telemetry deamon 😈 #338
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
Merged
Merged
Telemetry deamon 😈 #338
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
e4b02a8
Add telemetry server daemon
wtgee 643f8e3
Move telemetry under Typer CLI
wtgee 091c4b8
Add telemetry Python client
wtgee 5e486d9
Add a note about the `start_run`.
wtgee 8f5e081
Stamp run IDs on telemetry events
wtgee 94d3cec
Refine telemetry run defaults and site naming
wtgee 1fb06e3
Refine telemetry docs and CLI output
wtgee 2adeb68
Apply suggestions from code review
wtgee 82efa10
Polish merged telemetry review changes
wtgee e03e957
Simplify telemetry public API
wtgee 28a7616
Add telemetry current CLI
wtgee d57b2da
Polish telemetry CLI output and logging
wtgee d1268a0
Cleanup of changelog.
wtgee bf4faa2
Fix telemetry sequence gaps on write failure
wtgee aedb271
Apply suggestions from code review
wtgee 4a3ef2e
Cleanup of changelog.
wtgee 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
Some comments aren't visible on the classic Files Changed page.
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,187 @@ | ||
| ================ | ||
| Telemetry Server | ||
| ================ | ||
|
|
||
| The telemetry server provides a lightweight local HTTP API plus a Python client | ||
| for recording observatory telemetry. | ||
|
|
||
| Public telemetry model | ||
| ---------------------- | ||
|
|
||
| The public model is intentionally simple: | ||
|
|
||
| * There is one telemetry feed. | ||
| * ``start_run()`` activates an optional run context. | ||
| * While a run is active, new events are automatically associated with that run. | ||
| * Run-scoped events are stamped with ``meta.run_id``. | ||
|
|
||
| Internally, the server stores always-on site telemetry separately from | ||
| run-specific telemetry, but callers normally do not need to choose between | ||
| those storage targets explicitly. | ||
|
|
||
| CLI usage | ||
| --------- | ||
|
|
||
| Start the telemetry server: | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| panoptes-utils telemetry run | ||
|
|
||
| Enable verbose server logging, including one debug log line per incoming event: | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| panoptes-utils telemetry run --verbose | ||
|
|
||
| Stop it cleanly: | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| panoptes-utils telemetry stop | ||
|
|
||
| Inspect the current reading: | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| panoptes-utils telemetry current | ||
|
|
||
| Follow live updates by polling for changes: | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| panoptes-utils telemetry current --follow | ||
|
|
||
| This uses a live Rich display that refreshes in place when the current reading | ||
| changes. | ||
|
|
||
| Fetch one event type only: | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| panoptes-utils telemetry current status | ||
|
|
||
| Python client example | ||
| --------------------- | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| from panoptes.utils.telemetry import TelemetryClient | ||
|
|
||
| client = TelemetryClient() | ||
|
|
||
| client.post_event("weather", {"sky": "clear"}) | ||
| client.start_run(run_id="001") | ||
| client.post_event("status", {"state": "running"}) | ||
| print(client.current()["current"]) | ||
| client.stop_run() | ||
|
|
||
| HTTP API | ||
| -------- | ||
|
|
||
| The server listens on ``localhost:6562`` by default. | ||
|
|
||
| Endpoints | ||
| ~~~~~~~~~ | ||
|
|
||
| * ``GET /health`` - liveness check | ||
| * ``GET /ready`` - readiness plus run-active status | ||
| * ``GET /run`` - active run metadata | ||
| * ``POST /run/start`` - start a run context | ||
| * ``POST /run/stop`` - stop the active run context | ||
| * ``POST /event`` - record an event in the current context | ||
| * ``GET /current`` - latest telemetry values keyed by event type | ||
| * ``GET /current/{event_type}`` - latest telemetry value for one type | ||
| * ``POST /shutdown`` - ask the server to exit | ||
|
|
||
| ``httpie`` examples | ||
| ~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| # Check readiness. | ||
| http :6562/ready | ||
|
|
||
| # Record telemetry before a run is active. | ||
| http POST :6562/event type=weather data:='{"sky":"clear","wind_mps":2.1}' | ||
|
|
||
| # Start a run explicitly. | ||
| http POST :6562/run/start run_id=001 | ||
|
|
||
| # Or let the server derive the next numeric run automatically. | ||
| http POST :6562/run/start | ||
|
|
||
| # Events are now associated with the active run and stamped with meta.run_id. | ||
| http POST :6562/event type=status data:='{"state":"running"}' | ||
|
|
||
| # Inspect the materialized current view. | ||
| http :6562/current | ||
|
|
||
| ``curl`` examples | ||
| ~~~~~~~~~~~~~~~~~ | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| curl -s http://localhost:6562/ready | ||
|
|
||
| curl -s \ | ||
| -X POST http://localhost:6562/event \ | ||
| -H 'Content-Type: application/json' \ | ||
| -d '{"type":"weather","data":{"sky":"clear","wind_mps":2.1}}' | ||
|
|
||
| curl -s \ | ||
| -X POST http://localhost:6562/run/start \ | ||
| -H 'Content-Type: application/json' \ | ||
| -d '{"run_id":"001"}' | ||
|
|
||
| curl -s \ | ||
| -X POST http://localhost:6562/event \ | ||
| -H 'Content-Type: application/json' \ | ||
| -d '{"type":"status","data":{"state":"running"}}' | ||
|
|
||
| Response shape | ||
| -------------- | ||
|
|
||
| Successful event responses include: | ||
|
|
||
| * ``seq`` - monotonically increasing sequence number within the storage target | ||
| * ``ts`` - UTC timestamp | ||
| * ``type`` - event type | ||
| * ``data`` - event payload | ||
| * ``meta`` - caller metadata plus ``run_id`` when a run is active | ||
|
|
||
| Example response: | ||
|
|
||
| .. code-block:: json | ||
|
|
||
| { | ||
| "seq": 1, | ||
| "ts": "2026-03-18T00:05:48.955Z", | ||
| "type": "status", | ||
| "data": {"state": "running"}, | ||
| "meta": {"run_id": "001"} | ||
| } | ||
|
|
||
| Run handling | ||
| ------------ | ||
|
|
||
| ``start_run()`` and ``POST /run/start`` accept optional ``run_dir`` and | ||
| ``run_id`` values. | ||
|
|
||
| * If ``run_dir`` is relative, it is resolved under the configured site | ||
| telemetry directory. | ||
| * If ``run_dir`` is omitted, the server uses ``site_dir/run_id``. | ||
| * If both ``run_dir`` and ``run_id`` are omitted, the server derives the next | ||
| numeric run directory under the site telemetry directory (for example | ||
| ``001``, ``002``, ``003``). | ||
|
|
||
| Environment variables | ||
| --------------------- | ||
|
|
||
| =============================== ====================================== ============ | ||
| Variable Description Default | ||
| =============================== ====================================== ============ | ||
| ``PANOPTES_TELEMETRY_HOST`` Host address for the telemetry server. ``localhost`` | ||
| ``PANOPTES_TELEMETRY_PORT`` Port number for the telemetry server. ``6562`` | ||
| ``PANOPTES_TELEMETRY_SITE_DIR`` Directory for telemetry storage. ``telemetry/`` | ||
| =============================== ====================================== ============ |
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.
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.
Uh oh!
There was an error while loading. Please reload this page.