Common Cloud Connector request config
There is some code duplication around how requests into the AI gateway (or potentially other services) are configured and which is specific to changes we made for Cloud Connector.
We should provide a helper that encapsulates these specifics so that Ruby code can call into these and just merge them into their own request config.
So far the only example of this I spotted is the set of request headers we send into the AI gateway, which currently duplicated across https://gitlab.com/gitlab-org/gitlab/-/blob/06530d162c71cb3130fa78881a3cea3ca164a2cb/ee/lib/api/code_suggestions.rb#L31 and https://gitlab.com/gitlab-org/gitlab/-/blob/5c78271b045e226bb7a7adf314f2dde3b628c0c9/ee/lib/gitlab/llm/ai_gateway/client.rb#L86.
The following headers are specific to Cloud Connector, were introduced by us, and are important to always be present (most likely even in requests to other backends):
-
X-Gitlab-Instance-Id
: Used to count unique instances in service telemetry -
X-Gitlab-Global-User-Id
: Used to count unique global users in service telemetry -
X-Gitlab-Realm
: Used to segment traffic into SaaS vs SM (and possibly Dedicated in the future)
We should factor these out into a factory method client code can use. For example, we could:
- Introduce
CloudConnector::Http.required_header_fields
- Refactor both call sites to merge
required_header_fields
into their own request headers specific to the endpoint they are calling
We can evolve this further as needed from there.