Skip to content

Improve Marginalia comments for API requests

Stan Hu requested to merge sh-improve-api-marginalia-comments into master

This change adds a endpoint_id annotation to the Marginalia comments to help trace SQL queries to their origin. Examples:

  • For Grape API requests, this is the route (e.g. /api/:version/users/:id).
  • For GraphQL requests, this is GraphqlController#execute.
  • For Rails requests, this is in the controller and action (e.g. Projects::BlobController#show).

Relates to #323161 (closed)

Examples:

/*application:web,correlation_id:01EZVN0DAYGJF5XHG9N4VX8FAH,endpoint_id:/api/:version/users/:id*/
SELECT COUNT(*) FROM "users" INNER JOIN "user_follow_users" ON "users"."id" = "user_follow_users"."followee_id" WHERE "user_follow_users"."follower_id" = 1 
/*application:web,controller:graphql,action:execute,correlation_id:01EZVMR925CT6MV569KBD6HG04,endpoint_id:GraphqlController#execute*/
SELECT "ci_pipelines".* FROM "ci_pipelines" WHERE "ci_pipelines"."project_id" = 46 AND "ci_pipelines"."source" != 12 AND "ci_pipelines"."ref" = 'master' AND "ci_pipelines"."sha" = 'a6e0dc509d7d35238dfbb3eccbdcac7608fa1c99' ORDER BY "ci_pipelines"."id" DESC LIMIT 1
/*application:web,controller:blob,action:show,correlation_id:01EZVMR923313VV44ZJDJ7PMEZ,endpoint_id:Projects::BlobController#show*/
SELECT "routes".* FROM "routes" WHERE "routes"."source_id" = 75 AND "routes"."source_type" = 'Namespace' LIMIT 1
/*application:sidekiq,correlation_id:df643992563683313bc0a0288fb55e23,jid:15fbc506590c625d7664b074,job_class:UserStatusCleanup::BatchWorker,endpoint_id:UserStatusCleanup::BatchWorker,line:/app/workers/user_status_cleanup/batch_worker.rb:19:in `perform'*/
SELECT $1 AS one FROM "user_statuses" WHERE "user_statuses"."clear_status_at" <= $2 LIMIT $3

Relates to #323161 (closed)

Edited by Sean McGivern

Merge request reports