Update cube proxy load endpoint to return 404 when no database exists
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.
- Enable the feature flag:
echo "Feature.enable(:cube_api_proxy)" | rails c
. - Set up the devkit and start it running using
docker-compose up
. - Visit admin settings and make sure that the settings have been set:
/admin/application_settings/general#js-product-analytics-settings
. - 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
- Confirm that the response is the
404
. - 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
}
}
- Remake the first API call and confirm that the response is the
404
. - 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
).
- 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
- 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.
-
I have evaluated the MR acceptance checklist for this MR.