Skip to main content

Drift and adopt

Both sides are administrable, so drift is certain, not probable. The product detects it, shows it readably, and lets you repair it — or take over what already runs.

Drift detection​

Every APIM_DRIFT_INTERVAL_MS (one minute by default), and on demand, the product compares what should run with what the gateway holds:

  • APIs: the Api entity computed from the deployed snapshot against the actual one — name, domain, context path, state, the ownership marker, the snapshot id, and every route (path, methods, matching, backend, flow), backend (targets, root), flow (plugins and their configuration) and plan (status, kind, rate limits, restrictions).
  • Subscriptions: the ApiSubscription (status, plan, API) and each active key (present, enabled, apiRef.plan, secret); for a subscription that shares the key of its application, that key too (present, enabled, secret) and the sharing itself.

Each object gets a report:

StatusMeaning
in_syncthe gateway holds exactly what was deployed
driftedsomething changed on the gateway; the report lists the changes
missingthe entity is deployed but absent from the gateway
unmanagedan Otoroshi Api without the product's marker — a candidate for adopt mode

Reports show in Gateway → Drift, on the deployment tab of each API, in the subscription review and from the CLI. The banner at the top of an API says it too, from the last detection since its deployment: no longer on the gateway — the gateway lost it, a restart without storage, a hand in its console — or changed on the gateway, each with Deploy #n again, which deploys the snapshot that ran. What the product put on the gateway is not taken for what the gateway holds:

otoroshi-apim drift default
STATUS KIND OBJECT CHANGES
drifted Api Atlas 1.0.0 plans[Starter].rate_limiting.window, routes[Search].methods
in_sync ApiSubscription sub_01a1…

Repairing​

  • An API: re-apply the running snapshot (a deployment of the same snapshot). The dry run shows the gateway changes it will revert. Accepting the change instead means editing the draft and publishing.
  • A subscription: replay the projection.

Adopt mode​

A product that can only manage what it created is unusable for anyone already in production. APIs → Adopt from gateway lists the Otoroshi APIs the product does not manage and turns one into a draft — routes, backends, flows and plans converted, with their ids kept — without writing anything to the gateway. The first deployment then updates the entity in place, marking it as managed.

curl -X POST http://localhost:9000/api/workspaces/default/adopt \
-H 'Authorization: Bearer apim-admin-token' -H 'Content-Type: application/json' \
-d '{"otoroshi_api_id": "api_4b28c494-…"}'

Its subscriptions and their keys are taken over too, as they are. Each owner on the gateway — its owner_ref, and the client id on token and certificate plans — becomes an application of the product (or the one its keys already name with id_ref), in the team of the API or the one given (application_team_id); each ApiSubscription becomes a subscription of the product with the same id, active or suspended; each key a credential with the same client id and secret. A subscription that shares a credential of its owner keeps sharing it: the credential becomes its application's, which calls every API with one key from then on. The first deployment updates them in place: the consumers keep calling with the keys they have. Adopt the API alone with "subscriptions": false. The trusted CAs of an mtls plan are read from the certificates it names; the selection, the counter failure strategy, the circuit breaker, the issuer and the audiences of the plans come with them.