Files
arcadia-cloud/config/config.exs
Giuliano Silvestro 445b7b60d4 Phase 2: drift detection
Compares cloud_provisioned.spec (what we asked DO for) against the live
cloud_resources row (what DO actually has). Any divergence becomes an
operator-resolvable drift record.

cloud_drift table: one row per drifted field. status open/accepted/
reverted/stale. Partial unique index keeps at most one OPEN drift per
(resource, field); resolved rows are retained as history.

ArcadiaCloud.Drift context:
- detect_all/0 — sweeps every provisioned resource. Per field in spec,
  resolves the actual value (top-level schema field first, then attrs),
  compares with loose equality (stringified scalars; lists as sets so
  JSON round-trips don't false-positive). Mismatches upsert a cloud_drift
  row + emit a drift_detected event in the resource event log.
- close_stale_drift — an open drift whose field no longer mismatches
  (fixed elsewhere) closes as "stale" on the next sweep.
- accept_drift/2 — the live value becomes the new desired-state: parent
  cloud_provisioned.spec is updated, spec_version bumped, drift closed
  "accepted". Revert (mutating live infra back to spec) is intentionally
  NOT here — it needs a saga and lands with the droplet-resize work.

DriftDetectionWorker — Oban cron at :20 past the hour, offset past the
:15 resource syncs so it compares against fresh inventory.

Provisioning.record_provisioned/3 — populates cloud_provisioned desired-
state (upsert on resource_id, bumps spec_version). Future provisioning
sagas call this; for now it's how drift gets something to detect.

API (platform_admin only):
- GET  /api/v1/drift            — open drift inbox
- POST /api/v1/drift/:id/accept — adopt live value as desired-state

Smoke verified: recorded a droplet's desired spec with a deliberately
wrong size_slug + a correct region; detect_all flagged only size_slug,
wrote the drift_detected event; accept updated the spec to the live
value and closed the drift; re-detect found zero drift.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-20 11:08:27 +10:00

78 lines
2.7 KiB
Elixir

# This file is responsible for configuring your application
# and its dependencies with the aid of the Config module.
#
# This configuration file is loaded before any dependency and
# is restricted to this project.
# General application configuration
import Config
config :arcadia_cloud,
ecto_repos: [ArcadiaCloud.Repo],
generators: [timestamp_type: :utc_datetime, binary_id: true]
# Configure the endpoint
config :arcadia_cloud, ArcadiaCloudWeb.Endpoint,
url: [host: "localhost"],
adapter: Bandit.PhoenixAdapter,
render_errors: [
formats: [json: ArcadiaCloudWeb.ErrorJSON],
layout: false
],
pubsub_server: ArcadiaCloud.PubSub,
live_view: [signing_salt: "4W6q5pDB"]
# Configure Elixir's Logger
config :logger, :default_formatter,
format: "$time $metadata[$level] $message\n",
metadata: [:request_id]
# Use Jason for JSON parsing in Phoenix
config :phoenix, :json_library, Jason
# Guardian — JWTs are issued by arcadia-app. arcadia-cloud only verifies them.
# Issuer and secret_key MUST match arcadia-app's Arcadia.Guardian config.
config :arcadia_cloud, ArcadiaCloud.Guardian,
issuer: "arcadia",
verify_issuer: true
# Oban — provisioning, sync, billing, gateway-event consumption queues
config :arcadia_cloud, Oban,
engine: Oban.Engines.Basic,
queues: [
provisioning: 5,
cloud_sync_fast: 5,
cloud_sync_full: 3,
cloud_sync_slow: 1,
cloud_billing: 1,
metering: 2,
default: 5
],
plugins: [
{Oban.Plugins.Cron,
crontab: [
# ProjectsWorker first so attribution is fresh before resource syncs
{"*/15 * * * *", ArcadiaCloud.Sync.ProjectsWorker},
{"*/15 * * * *", ArcadiaCloud.Sync.DropletsWorker},
{"*/15 * * * *", ArcadiaCloud.Sync.DomainsWorker},
{"*/15 * * * *", ArcadiaCloud.Sync.VolumesWorker},
{"*/15 * * * *", ArcadiaCloud.Sync.FloatingIpsWorker},
{"*/15 * * * *", ArcadiaCloud.Sync.FirewallsWorker},
{"*/15 * * * *", ArcadiaCloud.Sync.LoadBalancersWorker},
# Snapshots change slowly; hourly is enough and reduces API churn
{"33 * * * *", ArcadiaCloud.Sync.SnapshotsWorker},
# Backups also slow-moving; hourly per-droplet walk
{"41 * * * *", ArcadiaCloud.Sync.BackupsWorker},
# Drift sweep — offset past the :15 resource syncs so it sees fresh data
{"20 * * * *", ArcadiaCloud.Sync.DriftDetectionWorker},
# Billing: hourly balance, daily invoice discovery
{"7 * * * *", ArcadiaCloud.Sync.BalanceWorker},
{"23 2 * * *", ArcadiaCloud.Sync.BillingHistoryWorker}
]}
],
repo: ArcadiaCloud.Repo
# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
import_config "#{config_env()}.exs"