feat(agent): add fly agent run, the base of the monitoring agent - #31
Merged
Merged
Conversation
- Read FLY_AGENT_URL, FLY_AGENT_TOKEN, FLY_AGENT_SERVER_ID and STATE_DIRECTORY. An error names each key that is not set or not valid. - Accept only an https URL. Plain http is accepted only for a loopback host, for tests and local development. - Lock a file in the state directory, so that only one agent operates. - Work at server_id % 60 seconds past each minute, and report after each report interval (1 to 10 samples, saved in state.json). - Stop on SIGTERM. The agent does not need Docker and does not run as root. - Add a client for the control plane and internal/statefile for crash-safe JSON files. The next layers use them. Refs #26
Fixes from the adversarial review of this layer. - The control plane client does not follow redirects. A followed redirect replays a POST as a GET without the body, so a 200 to it would drop samples that were never stored, and a redirect to http would send the token in plain text. A 3xx is now a reply that keeps the data. - A Retry-After value is at most one hour and cannot overflow. - A wall clock that steps back cannot make the same tick run two times. - FLY_AGENT_URL must not hold a user, a password, a query or a fragment, and an error never shows a password. localhost is accepted in any case. - FLY_AGENT_TOKEN may hold only printable ASCII characters. - At start, remove the temporary files that a crash during a write left. Refs #26
Under go test ./... -race, the fake "docker compose version" could take more than the 1 s test timeout, so the test reported the Compose plugin instead of the daemon. Use 3 s. Refs #26
nabil1440
added this pull request to stack #38
September 22, 2026 10:40
This was referenced Sep 22, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Layer 1 of 7 of the monitoring agent (#31 → #37). It follows the FlyWP monitoring agent contract v0.2.1.
Summary
fly agent run. systemd starts it on each server, as the server user.Change
cmd/agent.go:fly agent run. It stops on SIGTERM with exit 0.internal/agent: the configuration (FLY_AGENT_URL,FLY_AGENT_TOKEN,FLY_AGENT_SERVER_ID,STATE_DIRECTORY), the lock, the schedule and the client for the control plane.internal/statefile: JSON files that survive a crash (temporary file, sync, rename, sync of the folder).Adversarial review
The first version was refuted. These items are fixed in this PR:
Retry-Afteris at most one hour.Tests
Retry-After, status errors).testing/synctest.Refs #26 (#32 completes it: the report interval in
state.json)