Skip to content

Update cube proxy load endpoint to return 404 when no database exists

Robert Hunt requested to merge cube-return-not-found-if-no-db into master

What does this MR do and why?

The cube proxy currently handles errors by returning a 200 status code with a JSON error object. The Cube.js library doesn't know how to handle that and so it continues on and then throws an error when it can't use the input given. This is okay for most failures as we can a return a "something went wrong" type error message and leave it at that.

However, we need a bit more detail to handle the case where we are checking to see if the project has any data in Cube yet. In this case, we need to be able to respond to this specific error and send the user to the onboarding flow rather than a generic failure.

Therefore, this MR adds a specific check for this scenario and in this event it returns a 404 with the message 404 Database Not Found. The Cube.js library handles 4xx|5xx absolute fine and this means that the frontend can then pick this up properly and send the user to the correct user flow.

How to set up and validate locally

Make sure you are on at least GitLab Premium.

  1. Enable the feature flag: echo "Feature.enable(:cube_api_proxy)" | rails c.
  2. Set up the devkit and start it running using docker-compose up.
  3. Visit admin settings and make sure that the settings have been set: /admin/application_settings/general#js-product-analytics-settings.
  4. As an authenticated user who has developer+ access to a particular project, make the following API call:
POST /api/v4/projects/{PROJECT_ID}/product_analytics/request

Content-Type: application/json
  1. Confirm that the response is the 404.
  2. As an authenticated user who has developer+ access to the project, make the following GraphQL call:
mutation {
  projectInitializeProductAnalytics(input: { projectPath: "[PATH_TO_PROJECT]" }) {
    project {
      fullPath
    }
    errors
  }
}
  1. Remake the first API call and confirm that the response is the 404.
  2. Generate some events for the project, in groupproduct analytics we've been using a browser extension like tapermonkey + this userscript to generate events.
    • Using the userscript above you need to change the host to your devkit's Jitsu URL and use your Jitsu key created for the project (under project.project_settings.jitsu_key).
  3. Remake the first API call and confirm you get a 200 response this time.

MR acceptance checklist

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

Merge request reports