Commit 42f70ce8 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'sh-improve-api-marginalia-comments' into 'master'

Improve Marginalia comments for API requests

See merge request gitlab-org/gitlab!55564
parents 8cc69ea9 ae9d6916
...@@ -313,7 +313,7 @@ gem 'pg_query', '~> 1.3.0' ...@@ -313,7 +313,7 @@ gem 'pg_query', '~> 1.3.0'
gem 'premailer-rails', '~> 1.10.3' gem 'premailer-rails', '~> 1.10.3'
# LabKit: Tracing and Correlation # LabKit: Tracing and Correlation
gem 'gitlab-labkit', '0.14.0' gem 'gitlab-labkit', '~> 0.16.0'
# I18n # I18n
gem 'ruby_parser', '~> 3.15', require: false gem 'ruby_parser', '~> 3.15', require: false
......
...@@ -446,19 +446,18 @@ GEM ...@@ -446,19 +446,18 @@ GEM
fog-json (~> 1.2.0) fog-json (~> 1.2.0)
mime-types mime-types
ms_rest_azure (~> 0.12.0) ms_rest_azure (~> 0.12.0)
gitlab-labkit (0.14.0) gitlab-labkit (0.16.0)
actionpack (>= 5.0.0, < 7.0.0) actionpack (>= 5.0.0, < 7.0.0)
activesupport (>= 5.0.0, < 7.0.0) activesupport (>= 5.0.0, < 7.0.0)
gitlab-pg_query (~> 1.3)
grpc (~> 1.19) grpc (~> 1.19)
jaeger-client (~> 1.1) jaeger-client (~> 1.1)
opentracing (~> 0.4) opentracing (~> 0.4)
pg_query (~> 1.3)
redis (> 3.0.0, < 5.0.0) redis (> 3.0.0, < 5.0.0)
gitlab-license (1.3.1) gitlab-license (1.3.1)
gitlab-mail_room (0.0.8) gitlab-mail_room (0.0.8)
gitlab-markup (1.7.1) gitlab-markup (1.7.1)
gitlab-net-dns (0.9.1) gitlab-net-dns (0.9.1)
gitlab-pg_query (1.3.1)
gitlab-pry-byebug (3.9.0) gitlab-pry-byebug (3.9.0)
byebug (~> 11.0) byebug (~> 11.0)
pry (~> 0.13.0) pry (~> 0.13.0)
...@@ -1220,7 +1219,7 @@ GEM ...@@ -1220,7 +1219,7 @@ GEM
rack (>= 1, < 3) rack (>= 1, < 3)
thor (1.1.0) thor (1.1.0)
thread_safe (0.3.6) thread_safe (0.3.6)
thrift (0.13.0) thrift (0.14.0)
tilt (2.0.10) tilt (2.0.10)
timecop (0.9.1) timecop (0.9.1)
timeliness (0.3.10) timeliness (0.3.10)
...@@ -1416,7 +1415,7 @@ DEPENDENCIES ...@@ -1416,7 +1415,7 @@ DEPENDENCIES
gitlab-chronic (~> 0.10.5) gitlab-chronic (~> 0.10.5)
gitlab-experiment (~> 0.4.12) gitlab-experiment (~> 0.4.12)
gitlab-fog-azure-rm (~> 1.0.1) gitlab-fog-azure-rm (~> 1.0.1)
gitlab-labkit (= 0.14.0) gitlab-labkit (~> 0.16.0)
gitlab-license (~> 1.3) gitlab-license (~> 1.3)
gitlab-mail_room (~> 0.0.8) gitlab-mail_room (~> 0.0.8)
gitlab-markup (~> 1.7.1) gitlab-markup (~> 1.7.1)
......
---
title: Improve Marginalia comments for API
merge_request: 55564
author:
type: changed
...@@ -13,7 +13,7 @@ require 'marginalia' ...@@ -13,7 +13,7 @@ require 'marginalia'
# matching against the raw SQL, and prepending the comment prevents color # matching against the raw SQL, and prepending the comment prevents color
# coding from working in the development log. # coding from working in the development log.
Marginalia::Comment.prepend_comment = true if Rails.env.production? Marginalia::Comment.prepend_comment = true if Rails.env.production?
Marginalia::Comment.components = [:application, :controller, :action, :correlation_id, :jid, :job_class] Marginalia::Comment.components = [:application, :controller, :action, :correlation_id, :jid, :job_class, :endpoint_id]
# As mentioned in https://github.com/basecamp/marginalia/pull/93/files, # As mentioned in https://github.com/basecamp/marginalia/pull/93/files,
# adding :line has some overhead because a regexp on the backtrace has # adding :line has some overhead because a regexp on the backtrace has
......
...@@ -37,6 +37,10 @@ module Gitlab ...@@ -37,6 +37,10 @@ module Gitlab
job job
end end
end end
def endpoint_id
Labkit::Context.current&.get_attribute(:caller_id)
end
end end
end end
end end
...@@ -133,6 +133,28 @@ RSpec.describe API::API do ...@@ -133,6 +133,28 @@ RSpec.describe API::API do
end end
end end
describe 'Marginalia comments' do
context 'GET /user/:id' do
let_it_be(:user) { create(:user) }
let(:component_map) do
{
"application" => "test",
"endpoint_id" => "/api/:version/users/:id"
}
end
subject { ActiveRecord::QueryRecorder.new { get api("/users/#{user.id}", user) } }
it 'generates a query that includes the expected annotations' do
expect(subject.log.last).to match(/correlation_id:.*/)
component_map.each do |component, value|
expect(subject.log.last).to include("#{component}:#{value}")
end
end
end
end
describe 'supported content-types' do describe 'supported content-types' do
context 'GET /user/:id.txt' do context 'GET /user/:id.txt' do
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment