FEATURE: anon cache reports data to loggers

This allows custom plugins such as prometheus exporter to log how many
requests are stored in the anon cache vs used by the anon cache.

This metric allows us to fine tune cache behaviors
This commit is contained in:
Sam Saffron
2019-09-02 18:45:35 +10:00
parent afeb7e4b55
commit 08743e8ac0
3 changed files with 25 additions and 3 deletions

View File

@ -272,6 +272,19 @@ describe Middleware::RequestTracker do
Middleware::RequestTracker.unregister_detailed_request_logger(logger)
end
it "can report data from anon cache" do
cache = Middleware::AnonymousCache.new(app([200, {}, ["i am a thing"]]))
tracker = Middleware::RequestTracker.new(cache)
uri = "/path?#{SecureRandom.hex}"
tracker.call(env("REQUEST_URI" => uri, "ANON_CACHE_DURATION" => 60))
expect(@data[:cache]).to eq("store")
tracker.call(env("REQUEST_URI" => uri, "ANON_CACHE_DURATION" => 60))
expect(@data[:cache]).to eq("true")
end
it "can correctly log detailed data" do
global_setting :enable_performance_http_headers, true