Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docker/catalog/services/forward-migration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ hardcoded_env:
POSTGRES_HOST: postgres
POSTGRES_PORT: '5432'
POSTGRES_DB: omnibase_infra
NODE_POSTGRES_DB: omnidash_analytics
MIGRATIONS_DIR: /migrations/forward
operational_defaults:
POSTGRES_USER: postgres
Expand Down
2 changes: 2 additions & 0 deletions docker/catalog/services/migration-gate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ hardcoded_env:
POSTGRES_HOST: postgres
POSTGRES_PORT: '5432'
POSTGRES_DB: omnibase_infra
NODE_POSTGRES_DB: omnidash_analytics
REQUIRED_PROJECTION_TABLES: delegation_events node_service_registry
operational_defaults:
POSTGRES_USER: postgres
ports: null
Expand Down
3 changes: 3 additions & 0 deletions docker/docker-compose.infra.yml
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@ services:
POSTGRES_HOST: postgres
POSTGRES_PORT: "5432"
POSTGRES_DB: omnibase_infra
NODE_POSTGRES_DB: omnidash_analytics
MIGRATIONS_DIR: /migrations/forward
volumes:
- ../scripts/run-forward-migrations.sh:/run-forward-migrations.sh:ro
Expand Down Expand Up @@ -617,6 +618,8 @@ services:
POSTGRES_HOST: postgres
POSTGRES_PORT: "5432"
POSTGRES_DB: omnibase_infra
NODE_POSTGRES_DB: omnidash_analytics
REQUIRED_PROJECTION_TABLES: "delegation_events node_service_registry"
# Stay alive so healthcheck can run; no actual workload.
entrypoint: ["sh", "-c", "while true; do sleep 3600; done"]
volumes:
Expand Down
8 changes: 8 additions & 0 deletions docker/docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ services:
container_name: omninode-prod-runtime
restart: unless-stopped
depends_on:
migration-gate:
condition: service_healthy
intelligence-migration:
condition: service_completed_successfully
redpanda-partition-cap:
Expand Down Expand Up @@ -142,6 +144,9 @@ services:
runtime-effects:
container_name: omninode-prod-runtime-effects
restart: unless-stopped
depends_on:
migration-gate:
condition: service_healthy
environment:
OMNIMEMORY_ENABLED: ${PROD_RUNTIME_EFFECTS_OMNIMEMORY_ENABLED:?runtime policy contract must set PROD_RUNTIME_EFFECTS_OMNIMEMORY_ENABLED}
OMNIMEMORY_MEMGRAPH_HOST: ${PROD_RUNTIME_EFFECTS_OMNIMEMORY_MEMGRAPH_HOST?runtime policy contract must set PROD_RUNTIME_EFFECTS_OMNIMEMORY_MEMGRAPH_HOST}
Expand Down Expand Up @@ -184,6 +189,9 @@ services:
runtime-worker:
container_name: omninode-prod-runtime-worker
restart: unless-stopped
depends_on:
migration-gate:
condition: service_healthy
environment:
OMNIMEMORY_ENABLED: ${PROD_RUNTIME_WORKER_OMNIMEMORY_ENABLED:?runtime policy contract must set PROD_RUNTIME_WORKER_OMNIMEMORY_ENABLED}
OMNIMEMORY_MEMGRAPH_HOST: ${PROD_RUNTIME_WORKER_OMNIMEMORY_MEMGRAPH_HOST?runtime policy contract must set PROD_RUNTIME_WORKER_OMNIMEMORY_MEMGRAPH_HOST}
Expand Down
8 changes: 8 additions & 0 deletions docker/docker-compose.stability-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ services:
container_name: omninode-stability-test-runtime
restart: unless-stopped
depends_on:
migration-gate:
condition: service_healthy
intelligence-migration:
condition: service_completed_successfully
redpanda-partition-cap:
Expand Down Expand Up @@ -130,6 +132,9 @@ services:
runtime-effects:
container_name: omninode-stability-test-runtime-effects
restart: unless-stopped
depends_on:
migration-gate:
condition: service_healthy
environment:
OMNIMEMORY_ENABLED: ${STABILITY_TEST_RUNTIME_EFFECTS_OMNIMEMORY_ENABLED:?runtime policy contract must set STABILITY_TEST_RUNTIME_EFFECTS_OMNIMEMORY_ENABLED}
OMNIMEMORY_MEMGRAPH_HOST: ${STABILITY_TEST_RUNTIME_EFFECTS_OMNIMEMORY_MEMGRAPH_HOST?runtime policy contract must set STABILITY_TEST_RUNTIME_EFFECTS_OMNIMEMORY_MEMGRAPH_HOST}
Expand Down Expand Up @@ -179,6 +184,9 @@ services:
runtime-worker:
container_name: omninode-stability-test-runtime-worker
restart: unless-stopped
depends_on:
migration-gate:
condition: service_healthy
environment:
OMNIMEMORY_ENABLED: ${STABILITY_TEST_RUNTIME_WORKER_OMNIMEMORY_ENABLED:?runtime policy contract must set STABILITY_TEST_RUNTIME_WORKER_OMNIMEMORY_ENABLED}
OMNIMEMORY_MEMGRAPH_HOST: ${STABILITY_TEST_RUNTIME_WORKER_OMNIMEMORY_MEMGRAPH_HOST?runtime policy contract must set STABILITY_TEST_RUNTIME_WORKER_OMNIMEMORY_MEMGRAPH_HOST}
Expand Down
7 changes: 4 additions & 3 deletions docker/migrations/forward/nodes/.synced-nodes
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
# generation_events), additive columns, and the dashboard read views (0010).
node_projection_delegation

# Savings dashboard read view only. The savings_estimates base table is already
# owned by infra's flat migration 074; we vendor just the OMN-12489 view here.
node_projection_savings:076_*
# Savings dashboard projection: base table, additive columns, and the
# OMN-12489 read view. Node-owned migrations apply to omnidash_analytics,
# not the infra database that carries the historical flat 074 migration.
node_projection_savings

# Registration projection read model. Prod currently lacks node_service_registry;
# vendor the node-owned, idempotent migrations so the forward runner owns the fix.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ CREATE TABLE IF NOT EXISTS node_service_registry (
health_status TEXT DEFAULT 'unknown',
last_health_check TIMESTAMPTZ,
last_heartbeat_at TIMESTAMPTZ,
uptime_seconds BIGINT NOT NULL DEFAULT 0,
uptime_seconds BIGINT DEFAULT 0,
health_check_interval_seconds INT DEFAULT 60,
metadata JSONB DEFAULT '{}'::jsonb,
is_active BOOLEAN DEFAULT true,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
-- OMN-10340: deterministic savings estimate projection table.

CREATE EXTENSION IF NOT EXISTS pgcrypto;

CREATE TABLE IF NOT EXISTS savings_estimates (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
event_timestamp TIMESTAMPTZ NOT NULL,
session_id TEXT NOT NULL,
model_local TEXT NOT NULL,
model_cloud_baseline TEXT NOT NULL,
local_cost_usd NUMERIC(18, 6) NOT NULL CHECK (local_cost_usd >= 0),
cloud_cost_usd NUMERIC(18, 6) NOT NULL CHECK (cloud_cost_usd >= 0),
savings_usd NUMERIC(18, 6) NOT NULL,
repo_name TEXT,
machine_id TEXT,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
CONSTRAINT savings_estimates_amounts_match
CHECK (savings_usd = cloud_cost_usd - local_cost_usd)
);

CREATE UNIQUE INDEX IF NOT EXISTS ux_savings_estimates_identity
ON savings_estimates (
session_id,
event_timestamp,
model_local,
model_cloud_baseline
);

CREATE OR REPLACE FUNCTION refresh_savings_estimates_updated_at()
RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = NOW();
RETURN NEW;
END;
$$ LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS trg_savings_estimates_updated_at ON savings_estimates;
CREATE TRIGGER trg_savings_estimates_updated_at
BEFORE UPDATE ON savings_estimates
FOR EACH ROW
EXECUTE FUNCTION refresh_savings_estimates_updated_at();
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- OMN-11299: repair existing savings_estimates projections missing updated_at.

ALTER TABLE savings_estimates
ADD COLUMN IF NOT EXISTS updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW();
18 changes: 15 additions & 3 deletions scripts/check_migrations_complete.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,33 @@
# POSTGRES_HOST (default: localhost)
# POSTGRES_PORT (default: 5432)
# POSTGRES_DB (default: omnibase_infra)
# NODE_POSTGRES_DB (default: omnidash_analytics)
# REQUIRED_PROJECTION_TABLES (default: delegation_events node_service_registry)

set -e

PGUSER="${POSTGRES_USER:-postgres}"
PGHOST="${POSTGRES_HOST:?POSTGRES_HOST required}"
PGPORT="${POSTGRES_PORT:-5432}"
PGDB="${POSTGRES_DB:-omnibase_infra}"
NODE_PGDB="${NODE_POSTGRES_DB:-omnidash_analytics}"
REQUIRED_PROJECTION_TABLES="${REQUIRED_PROJECTION_TABLES:-delegation_events node_service_registry}"

export PGPASSWORD="${POSTGRES_PASSWORD}"

result=$(psql -h "$PGHOST" -p "$PGPORT" -U "$PGUSER" -d "$PGDB" \
-tAc "SELECT migrations_complete FROM public.db_metadata WHERE id = TRUE" 2>/dev/null)

if [ "$result" = "t" ]; then
exit 0
else
if [ "$result" != "t" ]; then
exit 1
fi

for table_name in $REQUIRED_PROJECTION_TABLES; do
table_exists=$(psql -h "$PGHOST" -p "$PGPORT" -U "$PGUSER" -d "$NODE_PGDB" \
-tAc "SELECT to_regclass('public.${table_name}') IS NOT NULL" 2>/dev/null)
if [ "$table_exists" != "t" ]; then
exit 1
fi
done

exit 0
119 changes: 96 additions & 23 deletions scripts/deploy-agent/deploy_agent/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@
("omninode-runtime", 8085),
("runtime-effects", 8086),
)
RUNTIME_MIGRATION_SERVICES: tuple[str, ...] = (
"forward-migration",
"migration-gate",
)
REQUIRED_PROJECTION_TABLES: tuple[str, ...] = (
"delegation_events",
"node_service_registry",
)

_BUILD_SOURCE_ALLOWED = ", ".join(source.value for source in BuildSource)

Expand Down Expand Up @@ -1104,6 +1112,8 @@ def _compose_up(
config = lane_config_for(lane)
profile = "core" if scope == Scope.CORE else "runtime"
requested_services = _requested_services_for_up(scope, services)
if scope == Scope.RUNTIME:
self._ensure_runtime_migrations_ready(lane=lane, timeout=timeout)
cmd = [
"docker",
"compose",
Expand Down Expand Up @@ -1189,6 +1199,68 @@ def _compose_up(

on_phase_update(phase, PhaseStatus.SUCCESS)

def _ensure_runtime_migrations_ready(
self,
*,
lane: EnumRuntimeLane = EnumRuntimeLane.DEV,
timeout: int = 300,
) -> None:
"""Run bounded migration services before a runtime-only restart.

Runtime deploys intentionally use ``--no-deps`` so compose cannot walk
into core infra and recreate Postgres/Redpanda/Valkey. The migration
one-shots are not core infra; they are the boot-order contract that
applies pending projection DDL and exposes the migration health gate.
"""
config = lane_config_for(lane)
base_cmd = [
"docker",
"compose",
*_compose_file_args(lane),
"-p",
config.compose_project,
"--profile",
"runtime",
"up",
"-d",
"--no-deps",
"--force-recreate",
]
for service in RUNTIME_MIGRATION_SERVICES:
cmd = [*base_cmd, service]
result = _run(cmd, timeout=timeout, env=_compose_env())
if result.returncode != 0:
raise RuntimeError(
f"Runtime migration preflight failed for {service}: "
f"{result.stderr.strip() or result.stdout.strip()}"
)
ok, stuck = verify_containers_up([service], timeout_s=120, lane=lane)
if not ok:
raise RuntimeError(
f"Runtime migration preflight did not satisfy {service}: {stuck}"
)
for table_name in REQUIRED_PROJECTION_TABLES:
result = _run(
[
"docker",
"exec",
config.postgres_container,
"psql",
"-U",
"postgres",
"-d",
"omnidash_analytics",
"-tAc",
f"SELECT to_regclass('public.{table_name}') IS NOT NULL",
],
timeout=timeout,
)
if result.stdout.strip() != "t":
raise RuntimeError(
"Runtime migration preflight failed: missing "
f"omnidash_analytics.{table_name}"
)

def verify(
self,
on_phase_update: PhaseCallback,
Expand Down Expand Up @@ -1249,30 +1321,31 @@ def verify(
)
)

# Check psql registration count
result = _run(
[
"docker",
"exec",
lane_config_for(lane).postgres_container,
"psql",
"-U",
"postgres",
"-d",
"omnibase_infra",
"-tAc",
"SELECT to_regclass('public.node_service_registry') IS NOT NULL",
],
timeout=timeout,
)
checks.append(
ModelHealthCheck(
service="postgres",
endpoint="node_service_registry exists",
status="pass" if result.stdout.strip() == "t" else "fail",
latency_ms=0,
# Check projection tables in the database used by runtime DB injection.
for table_name in REQUIRED_PROJECTION_TABLES:
result = _run(
[
"docker",
"exec",
lane_config_for(lane).postgres_container,
"psql",
"-U",
"postgres",
"-d",
"omnidash_analytics",
"-tAc",
f"SELECT to_regclass('public.{table_name}') IS NOT NULL",
],
timeout=timeout,
)
checks.append(
ModelHealthCheck(
service="postgres",
endpoint=f"omnidash_analytics.{table_name} exists",
status="pass" if result.stdout.strip() == "t" else "fail",
latency_ms=0,
)
)
)

# Runtime health endpoint checks.
#
Expand Down
Loading
Loading