Add x-gitlab-global-user-id. into X Ray scan request to AI Gateway
Background
In a slack thread @mkaeppler pointed out
I noticed is that the headers we send to the AIGW in this module do not include x-gitlab-global-user-id. Visible in logs too: https://log.gprd.gitlab.net/app/r/s/cW4qI We should always send this so we can properly count usage across features globally i.e. including self-managed
We should also not hand-craft these values here, there are shared helpers that provide instance ID and hashed user IDs
and from @rzwambag
As for this, it is rather straightforward, we have a new helper module that we include (already done), and then we should merge that in the >
model_gateway_headers
inscan.rb
!142193 (merged)diffs like
--- a/ee/lib/api/internal/ai/x_ray/scan.rb
+++ b/ee/lib/api/internal/ai/x_ray/scan.rb
@@ -50,14 +50,12 @@ def code_suggestions_add_on?(namespace)
def model_gateway_headers(headers, gateway_token)
{
- 'X-Gitlab-Instance-Id' => ::Gitlab::CurrentSettings.uuid.presence || GITLAB_INSTANCE_UUID_NOT_SET,
'X-Gitlab-Host-Name' => Gitlab.config.gitlab.host,
- 'X-Gitlab-Realm' => gitlab_realm,
'X-Gitlab-Authentication-Type' => 'oidc',
'Authorization' => "Bearer #{gateway_token}",
'Content-Type' => 'application/json',
'User-Agent' => headers["User-Agent"] # Forward the User-Agent on to the model gateway
- }.merge(saas_headers).transform_values { |v| Array(v) }
+ }.merge(saas_headers).merge(cloud_connector_headers(current_user)).transform_values { |v| Array(v) }
end
Goal
Include necessary telemetry headers into ee/lib/api/internal/ai/x_ray/scan.rb
so the adoption and usage of x ray scans can be properly counted
x-gitlab-global-user-id
header should carry id of user that owns Ci Pipeline runig X Ray CI job