Add Webhook GUID for Downstream Validation Checks
<!-- The first four sections: "Problem to solve", "Intended users", "User experience goal", and "Proposal", are strongly recommended, while the rest of the sections can be filled out during the problem validation or breakdown phase. However, keep in mind that providing complete and relevant information early helps our product team validate the problem and start working on a solution. --> ### Problem to solve <!-- What problem do we solve? Try to define the who/what/why of the opportunity as a user story. For example, "As a (who), I want (what), so I can (why/value)." --> As a developer writing an application that receives webhooks from GitLab, there is no unique identifier that is captured to help debug and correlate downstream actions that ought to be performed based on a given webhook. ### Intended users * [Devon (DevOps Engineer)](https://about.gitlab.com/handbook/marketing/product-marketing/roles-personas/#devon-devops-engineer) ### User experience goal <!-- What is the single user experience workflow this problem addresses? For example, "The user should be able to use the UI/API/.gitlab-ci.yml with GitLab to <perform a specific task>" https://about.gitlab.com/handbook/engineering/ux/ux-research-training/user-story-mapping/ --> For every webhook event that comes from GitLab, there ought to be a unique identification of that webhook to help correlate what events have been processed or not processed to aid in the troubleshooting and debugging of webhooks. ### Proposal <!-- How are we going to solve the problem? Try to include the user journey! https://about.gitlab.com/handbook/journeys/#user-journey --> Very similar to a competing product, we ought to [introduce a simple GUID as a header](https://developer.github.com/webhooks/event-payloads/#delivery-headers) in the form of `X-GitLab-Delivery` or something like this that provides downstream services relying on webhooks to help troubleshoot. ### Documentation <!-- See the Feature Change Documentation Workflow https://docs.gitlab.com/ee/development/documentation/workflow.html#for-a-product-change * Add all known Documentation Requirements in this section. See https://docs.gitlab.com/ee/development/documentation/feature-change-workflow.html#documentation-requirements * If this feature requires changing permissions, update the permissions document. See https://docs.gitlab.com/ee/user/permissions.html --> * [x] [Add the Request Header to the webhook documentation](https://docs.gitlab.com/ee/user/project/integrations/webhooks.html#events) ### Availability & Testing <!-- This section needs to be retained and filled in during the workflow planning breakdown phase of this feature proposal, if not earlier. What risks does this change pose to our availability? How might it affect the quality of the product? What additional test coverage or changes to tests will be needed? Will it require cross-browser testing? Please list the test areas (unit, integration and end-to-end) that needs to be added or updated to ensure that this feature will work as intended. Please use the list below as guidance. * Unit test changes * Integration test changes * End-to-end test change See the test engineering planning process and reach out to your counterpart Software Engineer in Test for assistance: https://about.gitlab.com/handbook/engineering/quality/test-engineering/#test-planning --> ### What does success look like, and how can we measure that? <!-- Define both the success metrics and acceptance criteria. Note that success metrics indicate the desired business outcomes, while acceptance criteria indicate when the solution is working correctly. If there is no way to measure success, link to an issue that will implement a way to measure this. --> ### What is the type of buyer? <!-- What is the buyer persona for this feature? See https://about.gitlab.com/handbook/marketing/product-marketing/roles-personas/buyer-persona/ In which enterprise tier should this feature go? See https://about.gitlab.com/handbook/product/pricing/#four-tiers --> ### Is this a cross-stage feature? <!-- Communicate if this change will affect multiple Stage Groups or product areas. We recommend always start with the assumption that a feature request will have an impact into another Group. Loop in the most relevant PM and Product Designer from that Group to provide strategic support to help align the Group's broader plan and vision, as well as to avoid UX and technical debt. https://about.gitlab.com/handbook/product/#cross-stage-features --> ### Links / references ### Implementation guide Recommended, the patch below plus updating specs in `spec/services/web_hook_service_spec.rb`, and update https://docs.gitlab.com/ee/user/project/integrations/webhooks.html#delivery-headers. ```patch diff --git a/app/services/web_hook_service.rb b/app/services/web_hook_service.rb index 9ab6fcc98321..78ccae1d45e8 100644 --- a/app/services/web_hook_service.rb +++ b/app/services/web_hook_service.rb @@ -189,7 +189,8 @@ def build_headers 'Content-Type' => 'application/json', 'User-Agent' => "GitLab/#{Gitlab::VERSION}", Gitlab::WebHooks::GITLAB_EVENT_HEADER => self.class.hook_to_event(hook_name), - Gitlab::WebHooks::GITLAB_INSTANCE_HEADER => Gitlab.config.gitlab.base_url + Gitlab::WebHooks::GITLAB_INSTANCE_HEADER => Gitlab.config.gitlab.base_url, + Gitlab::WebHooks::GITLAB_GUID_HEADER => SecureRandom.uuid } headers['X-Gitlab-Token'] = Gitlab::Utils.remove_line_breaks(hook.token) if hook.token.present? diff --git a/lib/gitlab/web_hooks.rb b/lib/gitlab/web_hooks.rb index 8c6de56292a0..e8f4ea0c9e1c 100644 --- a/lib/gitlab/web_hooks.rb +++ b/lib/gitlab/web_hooks.rb @@ -4,5 +4,6 @@ module Gitlab module WebHooks GITLAB_EVENT_HEADER = 'X-Gitlab-Event' GITLAB_INSTANCE_HEADER = 'X-Gitlab-Instance' + GITLAB_GUID_HEADER = 'X-GitLab-Webhook-UUID' end end ```
issue