Complete M7.8 operations endpoints and region server image

ADR-0066: evo-server --ops-listen serves /livez (loop responding, never
authority), /readyz (200 only while the host holds the lease with a
verified recovered head) and /metrics (Prometheus text: 30 fixed
series for readiness, phase, lease epoch/remaining, simulated/committed
ticks, commit lag, checkpoint age, tick debt, queue use and bounds, and
counters; the only labels are a 6-value phase and 4-value drop reason).

The dependency-free OpsServer runs on the host loop with no thread:
GET on exact paths, 405/404/400/431 responses, 8 connections with excess
refused on accept, 4 KiB requests, 1 s deadlines, 16 KiB responses.
HostStatus/phase types moved to the portable evo::ops library with a
Windows-tested renderer. evo-server now refuses to start without its
required identity and connection settings.

Adds the server-runtime Docker target (evo-server + pinned libpq,
UID 10001, no credentials), a CI server-image job with smoke script and
optional publishing, and a Kubernetes example outside Argo.

Validated: Windows CTest 59/59; Linux Debug/Release/clang-tidy/ASan
CTest 59/59; PostgreSQL suites under Release, clang-tidy and ASan with
real process probes; two ops mutations caught. Docker build/smoke and
Gitea CI not executed locally.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-09-28 23:09:28 -04:00
co-authored by Claude Opus 5.5
parent 30411a83f9
commit 7aec68db8e
23 changed files with 1222 additions and 65 deletions
+57
View File
@@ -0,0 +1,57 @@
#pragma once
#include <array>
#include <cstddef>
#include <cstdint>
#include <string>
// Region host status and its bounded operational exposition (M7.8, ADR-0066).
// Portable: no sockets, clocks or persistence types. Liveness is not authority:
// only `ready` means the host may originate output.
namespace evo::server {
enum class HostPhase : std::uint8_t {
acquiring, // Waiting for the lease (busy/unavailable) or recovering.
running, // Authoritative: simulating and committing.
resolving, // A commit outcome is unknown: paused until resolved.
draining, // Shutdown: committing pending work, then releasing.
stopped, // Drained (lease released when possible).
quarantined, // Fail closed: committed state or history cannot be trusted.
};
inline constexpr std::size_t host_phase_count = 6;
// Why an accepted input will never be acknowledged by this host.
enum class Unacknowledged : std::uint8_t {
refused, // The simulation rejected it; no tick consumed it.
drained, // Still queued at shutdown.
fenced, // Authority was lost before its tick committed; the next owner never saw it.
quarantined,
};
inline constexpr std::size_t unacknowledged_count = 4;
struct HostStatus {
HostPhase phase{HostPhase::acquiring};
bool ready{}; // Authoritative now: recovered, running, lease may originate.
std::uint64_t epoch{};
std::uint64_t simulated_tick{}, committed_tick{}, committed_sequence{};
std::size_t queued{}, queued_bytes{};
std::uint64_t tick_debt{}, max_tick_debt{}; // Due minus simulated since running.
std::uint64_t commits{}, store_failures{}, unknown_outcomes{}, fences{};
// Local lease safety: time until this host must stop originating (0 = none).
std::uint64_t lease_remaining_ms{};
};
// Process-level counters and bounds the exposition adds to the host status.
struct OpsCounters {
std::size_t queue_capacity_inputs{}, queue_capacity_bytes{};
std::uint64_t checkpoint_age_ms{}; // Since the last confirmed commit or recovery.
std::uint64_t acks{}, outcomes{};
std::array<std::uint64_t, unacknowledged_count> dropped{}; // Indexed by Unacknowledged.
};
[[nodiscard]] const char* phase_name(HostPhase phase) noexcept;
[[nodiscard]] const char* unacknowledged_name(Unacknowledged reason) noexcept;
// Prometheus text format 0.0.4. Fixed metric names; the only labels are `phase`
// (6 values) and `reason` (4 values), so cardinality is bounded by construction.
// No world/region/entity/request labels: scrape targets carry region identity.
[[nodiscard]] std::string render_metrics(const HostStatus& status, const OpsCounters& counters);
inline constexpr std::size_t max_metrics_bytes = 8192;
} // namespace evo::server
+67
View File
@@ -0,0 +1,67 @@
#pragma once
#include <chrono>
#include <cstddef>
#include <cstdint>
#include <expected>
#include <functional>
#include <memory>
#include <string>
#include <string_view>
#include <vector>
// Minimal operational HTTP/1.1 responder for probes and metrics (M7.8, ADR-0066).
// Linux. Not a general web server: GET only, one request per connection
// (Connection: close), bounded connections, request bytes, response bytes and
// per-connection time. serve() never blocks; it runs on the host's own loop so
// answers always describe the current state and no thread is added.
namespace evo::server {
struct OpsResponse {
int status{200};
std::string body;
std::string content_type{"text/plain; charset=utf-8"};
};
// Receives the request path (no query handling: probes use exact paths).
using OpsHandler = std::function<OpsResponse(std::string_view path)>;
enum class OpsError : std::uint8_t { address, socket };
class OpsServer {
public:
static constexpr std::size_t max_connections = 8;
static constexpr std::size_t max_request_bytes = 4096;
static constexpr std::size_t max_response_bytes = 16384;
static constexpr std::chrono::milliseconds connection_deadline{1000};
// Numeric address only ("127.0.0.1:9100" or "[::1]:9100"); port 0 picks one.
[[nodiscard]] static std::expected<std::unique_ptr<OpsServer>, OpsError>
listen(std::string_view address);
OpsServer(const OpsServer&) = delete;
OpsServer& operator=(const OpsServer&) = delete;
OpsServer(OpsServer&&) = delete;
OpsServer& operator=(OpsServer&&) = delete;
~OpsServer();
[[nodiscard]] std::uint16_t port() const noexcept {
return port_;
}
// Accepts, reads, answers and expires connections without waiting. Connections
// beyond the bound are closed at once; slow or oversized ones are answered or
// dropped without delaying others.
void serve(const OpsHandler& handler);
[[nodiscard]] std::uint64_t refused() const noexcept {
return refused_;
}
private:
struct Connection {
int fd{-1};
std::string in, out;
std::size_t sent{};
std::chrono::steady_clock::time_point deadline{};
};
OpsServer(int fd, std::uint16_t port) : fd_(fd), port_(port) {}
void respond(Connection& c, const OpsHandler& handler);
int fd_;
std::uint16_t port_;
std::vector<Connection> connections_;
std::uint64_t refused_{};
};
} // namespace evo::server
+1 -25
View File
@@ -2,6 +2,7 @@
#include "evo/persistence/checkpoint_store.hpp"
#include "evo/persistence/region_batch.hpp"
#include "evo/persistence/region_lease.hpp"
#include "evo/server/ops.hpp"
#include <chrono>
#include <cstddef>
#include <cstdint>
@@ -45,36 +46,11 @@ struct FinalOutcome {
std::uint64_t commit_sequence{};
friend bool operator==(const FinalOutcome&, const FinalOutcome&) = default;
};
// Why an accepted input will never be acknowledged by this host.
enum class Unacknowledged : std::uint8_t {
refused, // The simulation rejected it; no tick consumed it.
drained, // Still queued at shutdown.
fenced, // Authority was lost before its tick committed; the next owner never saw it.
quarantined,
};
struct Dropped {
TickInput input{};
Unacknowledged reason{};
};
enum class HostPhase : std::uint8_t {
acquiring, // Waiting for the lease (busy/unavailable) or recovering.
running, // Authoritative: simulating and committing.
resolving, // A commit outcome is unknown: paused until resolved.
draining, // Shutdown: committing pending work, then releasing.
stopped, // Drained (lease released when possible).
quarantined, // Fail closed: committed state or history cannot be trusted.
};
struct HostStatus {
HostPhase phase{HostPhase::acquiring};
bool ready{}; // Authoritative now: recovered, running, lease may originate.
std::uint64_t epoch{};
std::uint64_t simulated_tick{}, committed_tick{}, committed_sequence{};
std::size_t queued{}, queued_bytes{};
std::uint64_t tick_debt{}, max_tick_debt{}; // Due minus simulated since running.
std::uint64_t commits{}, store_failures{}, unknown_outcomes{}, fences{};
};
// Commit boundaries for fault injection (M7.7 kill tests).
enum class CrashPoint : std::uint8_t {
before_upload, // Batch sealed; nothing uploaded or sent.