httpcli, actor: propagate actor on all internal requests
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
Related changes
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
-
split out into https://github.com/sourcegraph/sourcegraph/pull/28151api.InternalClient
->api/internal_api.Client
: I had to do this becauseactor.WithActor
importstrace
, which importsapi
, which importshttpcli
. This extracts thehttpcli
import fromapi
to avoid the import cycle -
superseded by https://github.com/sourcegraph/sourcegraph/pull/28143trace.URL
andtrace.HTTPTraceMiddleware
now require external URL to be injected. This removes theactor
->conf
->httpcli
import cycle -
Hydrated user is now stored separately fromsplit out into https://github.com/sourcegraph/sourcegraph/pull/28149Actor
- it's still tracked in the context as before, but under a separate key. This removes anactor
->types
-> .... ->httpcli
import cycle