feat!: let checkers and status page servers reach data only through the api

Only cmd/api connects to Postgres and Redis. Agents authenticate with
tokens created by 'api agent create' and use /agent/v1: checkers long
poll for jobs, which doubles as heartbeat, and report results in
batches. Organizations manage monitors through /api/v1/org/monitors.

BREAKING CHANGE: cmd/checker and cmd/statuspage no longer read
UPTIME_DATABASE_URL or UPTIME_REDIS_*; they need UPTIME_API_URL and
UPTIME_AGENT_TOKEN. UPTIME_CHECKER_REGION is replaced by the region bound
to the agent token.

Closes #10
Closes #11
Closes #12
Closes #13
Closes #49

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-22 01:12:53 +01:00
1 parent 56862dce84
commit d9891bb050
23 files changed
+1361 -45

No files matched your search

+29
View File
@@ -0,0 +1,29 @@
package platform
import (
"context"
"errors"
"log/slog"
"time"
"git.zb-server.de/ZB-Server/uptimesebi/internal/agentapi"
)
// Hello waits until the API accepts the agent token, retrying while the API
// is unreachable so agents can start before it. A rejected token is fatal.
func Hello(ctx context.Context, c *agentapi.Client, log *slog.Logger) (agentapi.Hello, error) {
backoff := time.Second
for {
h, err := c.Hello(ctx)
if err == nil || errors.Is(err, agentapi.ErrUnauthorized) || ctx.Err() != nil {
return h, err
}
log.Warn("api not reachable yet", "error", err, "retry_in", backoff)
select {
case <-ctx.Done():
return h, ctx.Err()
case <-time.After(backoff):
}
backoff = min(backoff*2, 30*time.Second)
}
}
+1 -1
View File
@@ -11,7 +11,7 @@ import (
// OpenRedis connects to a single server or, when c.RedisSentinel is enabled,
// to the current master via sentinel with automatic failover.
func OpenRedis(ctx context.Context, c config.Common) (*redis.Client, error) {
func OpenRedis(ctx context.Context, c config.Storage) (*redis.Client, error) {
var rdb *redis.Client
if c.RedisSentinel.Enabled() {
opts, err := failoverOptions(c.RedisURL, c.RedisSentinel)
+1 -1
View File
@@ -47,7 +47,7 @@ func SignalContext() (context.Context, context.CancelFunc) {
// Connect validates c, refuses to start against an outdated schema, and
// opens Postgres and Redis.
func Connect(ctx context.Context, c config.Common, log *slog.Logger) (*Deps, error) {
func Connect(ctx context.Context, c config.Storage, log *slog.Logger) (*Deps, error) {
if err := c.Validate(); err != nil {
return nil, err
}