Commit 78737f81 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Add caller_id to Etag cache hits

parent effccda7
...@@ -67,7 +67,10 @@ module Gitlab ...@@ -67,7 +67,10 @@ module Gitlab
add_instrument_for_cache_hit(status_code, route, request) add_instrument_for_cache_hit(status_code, route, request)
Gitlab::ApplicationContext.push(feature_category: route.feature_category) Gitlab::ApplicationContext.push(
feature_category: route.feature_category,
caller_id: route.caller_id
)
new_headers = { new_headers = {
'ETag' => etag, 'ETag' => etag,
......
...@@ -3,23 +3,24 @@ ...@@ -3,23 +3,24 @@
module Gitlab module Gitlab
module EtagCaching module EtagCaching
module Router module Router
Route = Struct.new(:regexp, :name, :feature_category, :router) do Route = Struct.new(:router, :regexp, :name, :feature_category, :caller_id) do
delegate :match, to: :regexp delegate :match, to: :regexp
delegate :cache_key, to: :router delegate :cache_key, to: :router
end end
module Helpers module Helpers
def build_route(attrs) def build_route(attrs)
EtagCaching::Router::Route.new(*attrs, self) EtagCaching::Router::Route.new(self, *attrs)
end end
def build_rails_route(attrs) def build_rails_route(attrs)
regexp, name, controller, action_name = *attrs regexp, name, controller, action_name = *attrs
EtagCaching::Router::Route.new( EtagCaching::Router::Route.new(
self,
regexp, regexp,
name, name,
controller.feature_category_for_action(action_name).to_s, controller.feature_category_for_action(action_name).to_s,
self controller.endpoint_id_for_action(action_name).to_s
) )
end end
end end
......
...@@ -174,7 +174,8 @@ RSpec.describe Gitlab::EtagCaching::Middleware, :clean_gitlab_redis_shared_state ...@@ -174,7 +174,8 @@ RSpec.describe Gitlab::EtagCaching::Middleware, :clean_gitlab_redis_shared_state
it "pushes route's feature category to the context" do it "pushes route's feature category to the context" do
expect(Gitlab::ApplicationContext).to receive(:push).with( expect(Gitlab::ApplicationContext).to receive(:push).with(
feature_category: 'team_planning' feature_category: 'team_planning',
caller_id: 'Projects::NotesController#index'
) )
_, _, _ = middleware.call(build_request(path, if_none_match)) _, _, _ = middleware.call(build_request(path, if_none_match))
......
...@@ -114,6 +114,12 @@ RSpec.describe Gitlab::EtagCaching::Router::Rails do ...@@ -114,6 +114,12 @@ RSpec.describe Gitlab::EtagCaching::Router::Rails do
end end
end end
it 'has a caller_id for every route', :aggregate_failures do
described_class::ROUTES.each do |route|
expect(route.caller_id).to include('#'), "#{route.name} has caller_id #{route.caller_id}, which is not valid"
end
end
def match_route(path) def match_route(path)
described_class.match(double(path_info: path)) described_class.match(double(path_info: path))
end end
......
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