diff --git a/ee/lib/api/code_suggestions.rb b/ee/lib/api/code_suggestions.rb index b1e09d1f1f254b2a483d8be27ca3d51d7501dc46..6d32dc804e873c38b2403f6644a976743967c78a 100644 --- a/ee/lib/api/code_suggestions.rb +++ b/ee/lib/api/code_suggestions.rb @@ -30,6 +30,8 @@ def model_gateway_headers(headers, gateway_token) { 'X-Gitlab-Host-Name' => Gitlab.config.gitlab.host, 'X-Gitlab-Authentication-Type' => 'oidc', + # Forward the request time on to the model gateway to calculate latency + 'X-Gitlab-Rails-Send-Start' => Time.now.to_f.to_s, 'Authorization' => "Bearer #{gateway_token}", 'Content-Type' => 'application/json', 'User-Agent' => headers["User-Agent"] # Forward the User-Agent on to the model gateway diff --git a/ee/spec/requests/api/code_suggestions_spec.rb b/ee/spec/requests/api/code_suggestions_spec.rb index 7b71dd8d9eccb7f9535b90b5e10f1325d02146ed..e6e6e747bd5763306ab9dbccf6384d1dcc72dc2c 100644 --- a/ee/spec/requests/api/code_suggestions_spec.rb +++ b/ee/spec/requests/api/code_suggestions_spec.rb @@ -506,7 +506,7 @@ def get_user(session): post_api end - it 'includes additional headers for SaaS' do + it 'includes additional headers for SaaS', :freeze_time do group = create(:group) group.add_developer(authorized_user) @@ -515,7 +515,8 @@ def get_user(session): _, params = workhorse_send_data expect(params['Header']).to include( 'X-Gitlab-Saas-Namespace-Ids' => [''], - 'X-Gitlab-Saas-Duo-Pro-Namespace-Ids' => [add_on_purchase.namespace.id.to_s] + 'X-Gitlab-Saas-Duo-Pro-Namespace-Ids' => [add_on_purchase.namespace.id.to_s], + 'X-Gitlab-Rails-Send-Start' => [Time.now.to_f.to_s] ) end @@ -721,13 +722,14 @@ def get_user(session): context 'when user is authorized' do let(:current_user) { authorized_user } - it 'does not include additional headers, which are for SaaS only' do + it 'does not include additional headers, which are for SaaS only', :freeze_time do post_api expect(response.status).to be(200) expect(response.body).to eq("".to_json) _, params = workhorse_send_data expect(params['Header']).not_to have_key('X-Gitlab-Saas-Namespace-Ids') + expect(params['Header']).to include('X-Gitlab-Rails-Send-Start' => [Time.now.to_f.to_s]) end end