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
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 = {
'ETag' => etag,
......
......@@ -3,23 +3,24 @@
module Gitlab
module EtagCaching
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 :cache_key, to: :router
end
module Helpers
def build_route(attrs)
EtagCaching::Router::Route.new(*attrs, self)
EtagCaching::Router::Route.new(self, *attrs)
end
def build_rails_route(attrs)
regexp, name, controller, action_name = *attrs
EtagCaching::Router::Route.new(
self,
regexp,
name,
controller.feature_category_for_action(action_name).to_s,
self
controller.endpoint_id_for_action(action_name).to_s
)
end
end
......
......@@ -174,7 +174,8 @@ RSpec.describe Gitlab::EtagCaching::Middleware, :clean_gitlab_redis_shared_state
it "pushes route's feature category to the context" do
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))
......
......@@ -114,6 +114,12 @@ RSpec.describe Gitlab::EtagCaching::Router::Rails do
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)
described_class.match(double(path_info: path))
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