Skip to content

fix(events): gitlab_saas_duo_pro_namespace_ids bad events

Michał Wielich requested to merge michold-fix-string-namespaces into main

What does this merge request do and why?

Related to gitlab-org/gitlab#499082 (closed)

We're emitting events that don't pass Snowplow validations. This MR fixes it so that the events can pass the validations.

How to set up and validate locally

The steps are largely copied from: !1402 (merged)

  1. Set up Snowplow Micro using the instructions in the docs.
  2. It is possible that triggered events won't surface in Snowplow Micro UI in ai-gateway, if that's the case, you can use the work-around as per this suggestion from the #g_monitor_analytics_instrumentation slack channel but ensure you first set up Snowplow Micro as per step 1. For the workaround, hardcode the values in the emitter in gitlab-ai-gateway/ai_gateway/tracking/snowplow.py as such:
emitter = AsyncEmitter(
            batch_size=1,
            thread_count=1,
            endpoint="http://localhost:9092", // replace 9092 with snowplow micro port from your machine
        )
  1. Make a request to the v2/code/completions endpoint using:
curl "localhost:5052/v2/code/completions" \
  -X POST \
  -H "Content-Type: application/json" \
  -H "X-Gitlab-Realm: saas" \
  -H "X-Gitlab-Saas-Duo-Pro-Namespace-Ids: 4,5,6" \
  -d '{
  "current_file": {
    "file_name": "utils.ts",
    "content_above_cursor": "\nfunction calculator(a: number, b: number, operation: string): number {\n    // operation can be +, -, * or /\n    \n",
    "content_below_cursor": ""
  },
  "prompt_version": 2,
  "model_provider": "vertex-ai",
  "model_name": "codestral@2405"
}'
  1. Check Snowplow Micro UI or "http://localhost:9092/micro/good" to see the triggered event (i.e. a good event should surface).
  2. Expand and check the JSON object (i.e. root > event > context > data) of the good event to confirm the gitlab_saas_duo_pro_namespace_ids attribute being an array of integers:

image

  1. Check out main branch and send the same curl request again.
  2. Check out the new event in Snowplow UI: this should be categorized as a bad event, including gitlab_saas_duo_pro_namespace_ids errors in the payload: image

Merge request checklist

  • Tests added for new functionality. If not, please raise an issue to follow up.
  • Documentation added/updated, if needed.
Edited by Michał Wielich

Merge request reports

Loading