Include Cloudflare Ray ID in logs
Ask
The .com registry now sits behind Cloudflare. It would be valuable to add a key/value pair to the registry logs for the Cloudflare Ray ID of each inbound API request.
Implementation Guide
This can be done by sourcing the value from the CF-ray
header on each API request (if any).
We can then add a cf_ray
key/value pair to the request context.
The registry implements two separate APIs, the Distribution V2 API, which is the normal docker registry API, and the GitLab V1 API, which provides additional functionality.
We do not have a unified dispatcher for these APIs, so we'll need to add the header key in two places.
For example, we add the auth.UserNameKey
on each request for the GitLab V1 API and the Distribution V2 API.
We can use the same function call in the same places, replacing auth.UserNameKey
with a constant with the value of "CF-RAY"
Testing
We already have tests that sniff for the proper headers in requests such as this one for the GitLab V1 API.
Much of the setup for the new tests will be the same as the ones above.
For the Distribution V2 API, we'll need to call a different method on the builder
, such as BuildBaseURL
.
Additionally, the corresponding method for the GitLab V1 API URL is BuildGitlabV1BaseURL
.
These URLs should require the least amount of setup to make successful HTTP requests against.
Unlike the example test, we'll need to seed the requests with an appropriate CF-ray
header.
This can be accomplished by calling req.Header.Set
, as in this example, before making the request. Using the same key as in app.go
and setting an arbitrary test value.
For full coverage, we'll need to test for the presence and absence of the header against both APIs.
Verification
Once the corresponding MR for this issue is merged, the production logs (internal) for the registry can be searched, confirming the presence of the header.