Commit 7998725e authored by Robert Speicher's avatar Robert Speicher

Merge branch 'banzai-metrics' into 'master'

Instrument Banzai code

See merge request !3659
parents 8b7ce2ad 935f9131
...@@ -75,6 +75,29 @@ if Gitlab::Metrics.enabled? ...@@ -75,6 +75,29 @@ if Gitlab::Metrics.enabled?
config.instrument_methods(const) config.instrument_methods(const)
config.instrument_instance_methods(const) config.instrument_instance_methods(const)
end end
# Instruments all Banzai filters
Dir[Rails.root.join('lib', 'banzai', 'filter', '*.rb')].each do |file|
klass = File.basename(file, File.extname(file)).camelize
const = Banzai::Filter.const_get(klass)
config.instrument_methods(const)
config.instrument_instance_methods(const)
end
config.instrument_methods(Banzai::ReferenceExtractor)
config.instrument_instance_methods(Banzai::ReferenceExtractor)
config.instrument_methods(Banzai::Renderer)
config.instrument_methods(Banzai::Querying)
[Issuable, Mentionable, Participable].each do |klass|
config.instrument_instance_methods(klass)
config.instrument_instance_methods(klass::ClassMethods)
end
config.instrument_methods(Gitlab::ReferenceExtractor)
config.instrument_instance_methods(Gitlab::ReferenceExtractor)
end end
GC::Profiler.enable GC::Profiler.enable
......
...@@ -19,8 +19,10 @@ module Banzai ...@@ -19,8 +19,10 @@ module Banzai
cache_key = full_cache_key(cache_key, context[:pipeline]) cache_key = full_cache_key(cache_key, context[:pipeline])
if cache_key if cache_key
Rails.cache.fetch(cache_key) do Gitlab::Metrics.measure(:banzai_cached_render) do
cacheless_render(text, context) Rails.cache.fetch(cache_key) do
cacheless_render(text, context)
end
end end
else else
cacheless_render(text, context) cacheless_render(text, context)
...@@ -64,13 +66,15 @@ module Banzai ...@@ -64,13 +66,15 @@ module Banzai
private private
def self.cacheless_render(text, context = {}) def self.cacheless_render(text, context = {})
result = render_result(text, context) Gitlab::Metrics.measure(:banzai_cacheless_render) do
result = render_result(text, context)
output = result[:output] output = result[:output]
if output.respond_to?(:to_html) if output.respond_to?(:to_html)
output.to_html output.to_html
else else
output.to_s output.to_s
end
end end
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