Skip to main content

Diagnostics endpoints

Two small endpoints answer questions an operator asks when something looks wrong but the gateway is up. GET /sso/readiness tells you whether the single sign-on provider you configured for the Admin UI has every environment variable it needs, before a user finds out at the sign-in page. GET /debug/asyncio-tasks counts the coroutines running on one worker, grouped by name, so you can see which background job is piling up work when memory or latency grows. Both need a valid key, call no provider and store nothing, and neither returns a secret or any request content.

A real-world scenario​

A platform admin moves the gateway from one Kubernetes namespace to another and rewrites its secrets by hand. The next morning a colleague reports that the Microsoft sign-in button on the Admin UI fails. Instead of reading pod environments, the admin calls GET /sso/readiness, which answers 503 and names MICROSOFT_TENANT as the missing variable. The admin adds it to the secret, the pods restart, and the same call answers 200 with Microsoft SSO is properly configured.

Later the same week one gateway pod shows memory climbing for hours. The admin calls GET /debug/asyncio-tasks against that pod a few times and sees a coroutine count that grows on every call, which points at the background job to look at in the logs. A healthy pod answers with a small, stable number.

Check single sign-on readiness​

The gateway looks for GOOGLE_CLIENT_ID, MICROSOFT_CLIENT_ID and GENERIC_CLIENT_ID in that order, then for any of SAML_IDP_METADATA_URL, SAML_IDP_METADATA_XML and SAML_SP_ENTITY_ID, and treats the first one it finds as the configured provider. A gateway without any of them is healthy, because single sign-on is optional. For the found provider it checks the variables below and answers 503 when one is missing.

ProviderVariables that must be set
GoogleGOOGLE_CLIENT_SECRET
MicrosoftMICROSOFT_CLIENT_SECRET, MICROSOFT_TENANT
Generic OpenID ConnectGENERIC_CLIENT_SECRET, GENERIC_AUTHORIZATION_ENDPOINT, GENERIC_TOKEN_ENDPOINT, GENERIC_USERINFO_ENDPOINT
SAMLSAML_IDP_METADATA_URL or SAML_IDP_METADATA_XML. A missing one is reported as SAML_IDP_METADATA_URL
  1. In the Admin UI open Settings, then Admin Settings. The SSO Settings tab shows the provider the gateway found and its public settings, so you can see which provider the readiness check applies to.

  2. Call the endpoint with any valid key. Behind a load balancer, call each instance, because the check reads the environment of the instance that answers.

    curl http://localhost:4000/sso/readiness -H "Authorization: Bearer $SPANWAY_API_KEY"

    Expected result:

    {
    "status": "healthy",
    "sso_configured": true,
    "provider": "microsoft",
    "message": "Microsoft SSO is properly configured"
    }

    A gateway without single sign-on answers {"status": "healthy", "sso_configured": false, "message": "No SSO provider configured"}.

  3. When the answer is 503, add the variables named in missing_environment_variables to the deployment, restart the instances, and call again. Then open /ui/login and use the single sign-on button to confirm the round trip works, as Admin UI SSO describes.

Use the route in a deployment pipeline as a smoke test after a rollout. It does not contact the identity provider, so a wrong secret value is only found by signing in.

Count the background tasks of a worker​

Each worker runs one event loop with its own tasks, for example the background health checks, spend log writes, cache updates and the requests in flight. The endpoint lists how many unfinished tasks there are and how many of each coroutine, counting at most 5000 tasks, and covers only the worker that answered.

  1. Call the endpoint. Behind a load balancer, call it several times to reach different workers, or call a single pod directly.

    curl http://localhost:4000/debug/asyncio-tasks -H "Authorization: Bearer $SPANWAY_API_KEY"

    Expected result:

    {
    "total_active_tasks": 14,
    "by_name": {
    "get_active_tasks_stats": 1,
    "ProxyLogging._run_background_health_check": 1,
    "DualCache.async_set_cache": 3,
    "update_spend": 1,
    "Server.serve": 1
    }
    }
  2. Call it again a minute later. A name whose count keeps rising is a job that starts tasks faster than they finish. Search the gateway log for that name, and compare with GET /health/backlog, which counts the HTTP requests in flight on the same worker, to tell request load from background work.

  3. In the Admin UI, open Logs to see whether the request volume explains the count, and Models + Endpoints, then the Health Status tab, when the growing name is a health check.

The count includes the endpoint's own task, so an idle worker never reports zero.

Routes​

MethodPathSummary
GET/sso/readinessCheck the single sign-on setup
GET/debug/asyncio-tasksCount the background tasks on this worker

Errors​

StatusRouteMeaningFix
401 Authentication Error, No api key passed in.bothThe request carried no key or an invalid one.Send Authorization: Bearer with the master key or a virtual key.
503 ... SSO is configured but missing required environment variables: ...GET /sso/readinessA provider client id is set but the variables listed in missing_environment_variables are not.Set them on every instance and restart.

Logs​

Neither route writes a log line. The readiness route answers over HTTP only, so wire it to a monitor or a pipeline step instead of watching the log, and the task count is a snapshot you compare between calls.