Skip to content

Prevent push_package event if Maven package file creation fails

What does this MR do and why?

Prevents creating a push_package tracking event when there's an error while uploading a Maven package via the PUT /api/v4/projects/:id/packages/maven/*path/:file_name endpoint.

Currently, the push_package event is created before the call to ::Packages::CreatePackageFileService#execute (which would create the package file). So, the event would be recorded even if the package file is not actually created because of an error.

This addresses the Maven package format for #330475 (closed).

Screenshots or screen recordings

💻🐈

How to set up and validate locally

Setup

  1. Follow the Maven packages docs to set up a Maven project that can publish to the GitLab Package Registry.
  2. Follow the Snowplow Guide to set up Snowplow Micro for local testing of Snowplow events.

Validation

Follow these steps to test for creation and non-creation of API::MavenPackages / push_package events:

  1. Checkout the master branch to test current behavior.
  2. Publish a Maven package, and go to http://localhost:9090/micro/all to confirm there is 1 good event. Go to http://localhost:9090/micro/good and see the event created with se_category: "API::MavenPackages", se_action: "push_package".
  3. Go to http://localhost:9090/micro/reset to clear the existing event.
  4. To cause a package file creation failure, cheat 😏 by modifying Packages::CreatePackageFileService#execute to raise an error (e.g. raise StandardError, 'Testing that push_package is not created on package publication failure'). After making this change, try publishing another package and see the operation fail.
  5. Go to http://localhost:9090/micro/all and confirm there is 1 good event. Go to http://localhost:9090/micro/good and see that an event with se_category: "API::MavenPackages", se_action: "push_package" was created even when the package push failed.
  6. Go to http://localhost:9090/micro/reset to clear the existing event.
  7. Checkout this branch (330475-prevent-push_package-event-on-maven-packages-api-error) to test the fixed behavior.
  8. Make sure to add the error-raising line on Packages::CreatePackageFileService#execute
  9. Try publishing another Maven package and see the operation fail.
  10. Go to http://localhost:9090/micro/all and confirm there are no events, meaning the fix worked.
  11. Remove the error-raising line from Packages::CreatePackageFileService#execute
  12. Go to http://localhost:9090/micro/all and confirm there is 1 good event. Go to http://localhost:9090/micro/good and see the event created with se_category: "API::MavenPackages", se_action: "push_package", meaning the success case still works correctly after the fix.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Hugo Ortiz

Merge request reports