Commit bfa3d1fd authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch '326106-NEW-correlation-id-to-validation-service' into 'master'

Add correlation id in X-Request-ID for external pipeline validation

See merge request gitlab-org/gitlab!58741
parents f0e7574b 749399aa
---
title: Add correlation id in X-Request-ID for external pipeline validation
merge_request: 58741
author:
type: other
...@@ -69,8 +69,10 @@ module Gitlab ...@@ -69,8 +69,10 @@ module Gitlab
end end
def validate_service_request def validate_service_request
headers = {} headers = {
headers['X-Gitlab-Token'] = validation_service_token if validation_service_token 'X-Request-ID' => Labkit::Correlation::CorrelationId.current_id,
'X-Gitlab-Token' => validation_service_token
}.compact
Gitlab::HTTP.post( Gitlab::HTTP.post(
validation_service_url, timeout: validation_service_timeout, validation_service_url, timeout: validation_service_timeout,
......
...@@ -57,13 +57,14 @@ RSpec.describe Gitlab::Ci::Pipeline::Chain::Validate::External do ...@@ -57,13 +57,14 @@ RSpec.describe Gitlab::Ci::Pipeline::Chain::Validate::External do
before do before do
stub_env('EXTERNAL_VALIDATION_SERVICE_URL', validation_service_url) stub_env('EXTERNAL_VALIDATION_SERVICE_URL', validation_service_url)
allow(Gitlab).to receive(:com?).and_return(dot_com) allow(Gitlab).to receive(:com?).and_return(dot_com)
allow(Labkit::Correlation::CorrelationId).to receive(:current_id).and_return('correlation-id')
end end
it 'respects the defined payload schema' do it 'respects the defined payload schema' do
expect(::Gitlab::HTTP).to receive(:post) do |_url, params| expect(::Gitlab::HTTP).to receive(:post) do |_url, params|
expect(params[:body]).to match_schema('/external_validation') expect(params[:body]).to match_schema('/external_validation')
expect(params[:timeout]).to eq(described_class::DEFAULT_VALIDATION_REQUEST_TIMEOUT) expect(params[:timeout]).to eq(described_class::DEFAULT_VALIDATION_REQUEST_TIMEOUT)
expect(params[:headers]).to eq({}) expect(params[:headers]).to eq({ 'X-Request-ID' => 'correlation-id' })
end end
perform! perform!
...@@ -127,7 +128,7 @@ RSpec.describe Gitlab::Ci::Pipeline::Chain::Validate::External do ...@@ -127,7 +128,7 @@ RSpec.describe Gitlab::Ci::Pipeline::Chain::Validate::External do
it 'passes token in X-Gitlab-Token header' do it 'passes token in X-Gitlab-Token header' do
expect(::Gitlab::HTTP).to receive(:post) do |_url, params| expect(::Gitlab::HTTP).to receive(:post) do |_url, params|
expect(params[:headers]).to eq({ 'X-Gitlab-Token' => '123' }) expect(params[:headers]).to include({ 'X-Gitlab-Token' => '123' })
end end
perform! perform!
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment