Refactor passing / handling of user-agent
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 72.1k
- Forks
- 19.2k
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 164
Description
Description
- relates to https://github.com/moby/moby/pull/45185
While working on https://github.com/moby/moby/pull/45185, I found there to be a couple of issues related to how we pass the user-agent.
For context; when making requests to registries, we combine the client's user-agent (e.g. user-agent of the docker CLI) with the user-agent of the daemon itself (version, build, kernel-version).
There's a couple of issues;
- constructing the user-agent of the daemon involves getting kernel-version, which is not "cheap". Assuming the kernel version doesn't change while the daemon is running, we should do this once (could be a
sync.Once) - getting the above information also brings additional dependencies, so we need to be careful where we include that code (to prevent consumers of the API (client) from getting those additional dependencies
- there is no consistent approach "where" to set the user-agent; some endpoints set the information in the API, other parts set it implicitly "deep" in library code
- there is no consistent approach on how to pass the user-agent; some code uses a separate
userAgentargument, whereas others pass it as part of the(meta)Headers(these headers can be custom headers set throughX-Meta-xxx). - Some code pass both
User-AgentandmetaHeadersto the registry, whereas other parts of the code discardmetaHeaders⚠️ ❓ Is there a reason to discardmetaHeaders?; see
We should consider;
- Improve performance (use a
sync.Once?) - Alternatively; set the information when constructing the router and/or backend, and store it on the backend itself.
- Move this code out of library code; don't set it implicitly, but pass it as part of the headers we pass as arguments
- Having a consistent approach (should we append the User-Agent to all requests? if it's a lightweight operation, then perhaps that's an option; even if we're not gonna be using it)
- Find out why
metaHeadersis discarded in some cases (was it (e.g.) to prevent authentication headers from being taken fromX-Meta-headers? Other reason?) See https://github.com/moby/moby/commit/19d48f0b8ba59eea9f2cac4ad1c7977712a6b7ac / https://github.com/moby/moby/pull/24568 for an example wheremetaHeadersis discarded
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing registry/search.go around line 119 and registry/endpoint_v1.go around line 124, then trace how the daemon and client user-agents and metaHeaders reach registry requests. Compare the related PR and commit references to understand why metaHeaders are discarded; done requires an agreed, consistent approach that addresses the listed performance, dependency, and header-handling concerns.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- backend
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100