Skip to content

Feature/2 probe loop - #12

Open
gaida123 wants to merge 4 commits into
mainfrom
feature/2-probe-loop
Open

gaida123 wants to merge 4 commits into
mainfrom
feature/2-probe-loop

Conversation

@gaida123

Copy link
Copy Markdown

Summary

Turns the probe from a config check into the actual probe loop. After validating config, python -m probe now keeps doing this:

  1. POST /functions/v1/probe-check-in with probe_id and X-Probe-Token.
  2. If there's an assignment, download run.sh and test.json from the signed paths (appended to BACKEND_URL) and check each against its sha256. If either doesn't match, nothing runs.
  3. Run bash run.sh from a temp dir with a 30s deadline and read the one JSON object it prints.
  4. POST /functions/v1/probe-measurements with the record, using the test_revision_id that actually ran and a fresh uuid4 run ID.
  5. Check in again right away. If check-in returns {"assignment":null}, wait 30s and try again.

The upload finishes before the next check-in, so an assignment change takes effect on the next pass.

How results are reported:

  • Exit 0 with a valid {"result_data": {...}} is completed. That includes 100% loss with rtt_avg_ms: null.
  • A non-zero exit or bad output is failed, with the exit code and empty result_data.
  • Running past the deadline is timeout. The whole process group gets killed, so ping doesn't keep running, and result_code is null.

Script stderr goes to the probe's own logs.

Token handling: X-Probe-Token is only sent on check-in and upload. It's left off the downloads, PROBE_TOKEN is stripped from the script's environment, and it never shows up in logs or error messages.

Errors: any non-2xx response, network error, malformed response, or hash mismatch stops the probe with a short message and exit code 1.

Shutdown: SIGTERM and Ctrl-C let the current pass finish, upload included, then exit 0. I set stop_grace_period: 1m in compose.yaml so Docker doesn't kill a pass partway through.

No new dependencies; it's all stdlib.

Files:

  • probe/src/probe/runner.py: new, the loop itself.
  • probe/src/probe/__main__.py: starts the loop after config validation, plus signal handling.
  • probe/tests/test_runner.py: new tests against a fake HTTP backend.
  • probe/compose.yaml, probe/README.md, AGENTS.md: stop grace period and docs.

Status codes: this matches what #9 (check-in) and #10 (measurements) currently return. The probe treats any 2xx as success and anything else as a stop.

Related issue

Closes #2

Testing

From probe/:

  • uv run --locked --extra test python -m pytest: 16 passed. The new tests use a fake backend and a fixed-output script. They cover:
    • two runs in order with different run IDs and a new revision on the second pass
    • a bad hash stopping execution
    • an empty assignment followed by a clean shutdown
    • no token on downloads or in the script environment
    • a newline-suffixed token not leaking
    • completed (incl. 100% loss), failed and timeout results
  • docker compose --env-file .env.example config --quiet: OK.

Docker check with the real Ping script: I built the image and ran it against a small local fake backend that served the real ping/run.sh and ping/test.json. Their sha256s matched the ones in the issue (9552c9a3…, b478fc86…).

  • Two passes ran in order, both completed:
    • rev dddddddd…, run 3afc8f3a…: 24.69 ms, 0% loss
    • rev eeeeeeee…, run 3c63d797…: 16.57 ms, 0% loss
  • The third check-in got null and nothing ran.
  • None of the downloads had an X-Probe-Token header.
  • Bad hash: the probe stopped with download …/run.sh failed its hash check, exit code 1. It never ran the script and nothing was uploaded.
  • docker stop during the idle wait: exit 0 in under a second.
  • docker stop mid-ping: the run finished and uploaded, there was no further check-in, exit 0 in about 3s.

Checklist

  • I ran all tests and they passed, and I have recorded the results above.
  • I have updated all docs where necessary.
  • I have reviewed the code and can explain the changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Run the probe loop

1 participant