Created by: bobheadxi
Propagates actor ID on all outgoing internal requests and adds middleware that services can use to pick up actors from incoming requests and add it to the request context. The middleware is currently only applied to frontend
's internal API handler, which already has something similar. Also adds metrics to see the number of requests that are user-authenticated vs internal-authenticated.
This more generalized actor handling replaces all existing usage of X-Sourcegraph-User-ID
. The header is also renamed to X-Sourcegraph-Actor-ID
to more accurately reflect actor.ID
, though backcompat is retained mostly with the old behaviour (though drops support for setting the ID to 0 to imply an internal user)
The plan is to also apply this to searcher
separately in https://github.com/sourcegraph/sourcegraph/issues/28412 (in the scope of PD 503 #27916 (closed))
Closes https://github.com/sourcegraph/sourcegraph/issues/27918
Turned out to require a number of changes because of import cycles, now that httpcli
imports actor
to add actor propagation to the default internal HTTP client
api.InternalClient
-> api/internal_api.Client
: I had to do this because actor.WithActor
imports trace
, which imports api
, which imports httpcli
. This extracts the httpcli
import from api
to avoid the import cycletrace.URL
and trace.HTTPTraceMiddleware
now require external URL to be injected. This removes the actor
-> conf
-> httpcli
import cycleActor
- it's still tracked in the context as before, but under a separate key. This removes an actor
-> types
-> .... -> httpcli
import cycle