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>
120 lines
4.7 KiB
C++
120 lines
4.7 KiB
C++
#include "evo/server/ops.hpp"
|
|
|
|
#include <algorithm>
|
|
#include <cstdio>
|
|
#include <limits>
|
|
#include <set>
|
|
#include <source_location>
|
|
#include <sstream>
|
|
#include <stdexcept>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace {
|
|
using namespace evo::server;
|
|
void check(bool ok, std::source_location at = std::source_location::current()) {
|
|
if (!ok)
|
|
throw std::runtime_error("ops line " + std::to_string(at.line()));
|
|
}
|
|
#define CHECK(...) check(static_cast<bool>(__VA_ARGS__))
|
|
|
|
struct Sample {
|
|
std::string name, labels, value;
|
|
};
|
|
// Parses exposition lines; every family must be introduced by HELP and TYPE.
|
|
std::vector<Sample> parse(const std::string& text) {
|
|
std::vector<Sample> out;
|
|
std::set<std::string> typed, helped;
|
|
std::istringstream in(text);
|
|
for (std::string line; std::getline(in, line);) {
|
|
CHECK(!line.empty());
|
|
if (line.rfind("# HELP ", 0) == 0) {
|
|
helped.insert(line.substr(7, line.find(' ', 7) - 7));
|
|
continue;
|
|
}
|
|
if (line.rfind("# TYPE ", 0) == 0) {
|
|
const auto name = line.substr(7, line.find(' ', 7) - 7);
|
|
const auto type = line.substr(line.rfind(' ') + 1);
|
|
CHECK(type == "gauge" || type == "counter");
|
|
CHECK(helped.contains(name) && !typed.contains(name)); // One family, documented.
|
|
typed.insert(name);
|
|
continue;
|
|
}
|
|
const auto space = line.rfind(' ');
|
|
const auto brace = line.find('{');
|
|
Sample s{line.substr(0, std::min(space, brace)), "", line.substr(space + 1)};
|
|
if (brace < space)
|
|
s.labels = line.substr(brace, space - brace);
|
|
CHECK(typed.contains(s.name));
|
|
CHECK(!s.value.empty() && s.value.find_first_not_of("0123456789") == std::string::npos);
|
|
out.push_back(s);
|
|
}
|
|
return out;
|
|
}
|
|
|
|
void exposition_is_bounded_and_well_formed() {
|
|
HostStatus s;
|
|
s.phase = HostPhase::running;
|
|
s.ready = true;
|
|
s.epoch = 3;
|
|
s.simulated_tick = 50;
|
|
s.committed_tick = 41;
|
|
s.lease_remaining_ms = 1234;
|
|
OpsCounters c;
|
|
c.queue_capacity_inputs = 64;
|
|
c.queue_capacity_bytes = 65536;
|
|
c.dropped[2] = 5;
|
|
const auto text = render_metrics(s, c);
|
|
const auto samples = parse(text);
|
|
const std::set<std::string> label_names{"", "phase", "reason"};
|
|
std::size_t phases_on = 0;
|
|
for (const auto& x : samples) {
|
|
CHECK(x.name.rfind("evo_region_", 0) == 0);
|
|
const auto key =
|
|
x.labels.empty() ? std::string{} : x.labels.substr(1, x.labels.find('=') - 1);
|
|
CHECK(label_names.contains(key)); // No world/region/entity/request labels.
|
|
if (x.name == "evo_region_phase")
|
|
phases_on += x.value == "1";
|
|
}
|
|
CHECK(phases_on == 1);
|
|
CHECK(text.find("evo_region_phase{phase=\"running\"} 1\n") != std::string::npos);
|
|
CHECK(text.find("evo_region_ready 1\n") != std::string::npos);
|
|
CHECK(text.find("evo_region_commit_lag_ticks 9\n") != std::string::npos);
|
|
CHECK(text.find("evo_region_lease_remaining_milliseconds 1234\n") != std::string::npos);
|
|
CHECK(text.find("evo_region_dropped_total{reason=\"fenced\"} 5\n") != std::string::npos);
|
|
// Series count is fixed: 6 phases + 4 reasons + 20 unlabelled families.
|
|
CHECK(samples.size() == 6 + 4 + 20);
|
|
|
|
// Worst-case values keep the size bounded and never underflow the lag.
|
|
HostStatus big;
|
|
big.phase = HostPhase::quarantined;
|
|
constexpr auto most = std::numeric_limits<std::uint64_t>::max();
|
|
big.epoch = big.committed_tick = big.committed_sequence = big.tick_debt = most;
|
|
big.max_tick_debt = big.commits = big.store_failures = big.unknown_outcomes = most;
|
|
big.fences = big.lease_remaining_ms = most;
|
|
big.simulated_tick = 1; // Lag saturates at zero rather than wrapping.
|
|
OpsCounters bigc{most, most, most, most, most, {most, most, most, most}};
|
|
const auto large = render_metrics(big, bigc);
|
|
CHECK(large.size() <= max_metrics_bytes);
|
|
CHECK(large.find("evo_region_commit_lag_ticks 0\n") != std::string::npos);
|
|
CHECK(large.find("evo_region_ready 0\n") != std::string::npos);
|
|
CHECK(parse(large).size() == samples.size());
|
|
for (std::size_t i = 0; i < host_phase_count; ++i)
|
|
CHECK(std::string(phase_name(static_cast<HostPhase>(i))) != "unknown");
|
|
for (std::size_t i = 0; i < unacknowledged_count; ++i)
|
|
CHECK(std::string(unacknowledged_name(static_cast<Unacknowledged>(i))) != "unknown");
|
|
std::printf("ops_metrics_bytes typical=%zu worst=%zu\n", text.size(), large.size());
|
|
}
|
|
} // namespace
|
|
|
|
int main() {
|
|
try {
|
|
exposition_is_bounded_and_well_formed();
|
|
std::puts("ops contracts passed");
|
|
return 0;
|
|
} catch (const std::exception& e) {
|
|
std::fprintf(stderr, "%s\n", e.what());
|
|
return 1;
|
|
}
|
|
}
|