From 8299129382e59a0b407be8c476b8ae2d0704d688 Mon Sep 17 00:00:00 2001
From: Yorick Peterse <yorickpeterse@gmail.com>
Date: Tue, 12 Apr 2016 12:24:16 +0200
Subject: [PATCH 1/2] Instrument all service classes

Fixes gitlab-org/gitlab-ce#15162
---
 config/initializers/metrics.rb | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/config/initializers/metrics.rb b/config/initializers/metrics.rb
index 1b445bbbd10..9bd43dad0a0 100644
--- a/config/initializers/metrics.rb
+++ b/config/initializers/metrics.rb
@@ -1,4 +1,5 @@
 if Gitlab::Metrics.enabled?
+  require 'pathname'
   require 'influxdb'
   require 'connection_pool'
   require 'method_source'
@@ -98,6 +99,17 @@ if Gitlab::Metrics.enabled?
 
     config.instrument_methods(Gitlab::ReferenceExtractor)
     config.instrument_instance_methods(Gitlab::ReferenceExtractor)
+
+    # Instrument all service classes
+    services = Rails.root.join('app', 'services')
+
+    Dir[services.join('**', '*.rb')].each do |file_path|
+      path = Pathname.new(file_path).relative_path_from(services)
+      const = path.to_s.sub('.rb', '').camelize.constantize
+
+      config.instrument_methods(const)
+      config.instrument_instance_methods(const)
+    end
   end
 
   GC::Profiler.enable
-- 
GitLab


From 435892ed4398afb67043c62be8831df07d2078f2 Mon Sep 17 00:00:00 2001
From: Yorick Peterse <yorickpeterse@gmail.com>
Date: Tue, 12 Apr 2016 16:07:58 +0200
Subject: [PATCH 2/2] Changelog entry for service class instrumentation

[ci skip]
---
 CHANGELOG | 1 +
 1 file changed, 1 insertion(+)

diff --git a/CHANGELOG b/CHANGELOG
index c08b148c3ac..f4f864b301a 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,7 @@
 Please view this file on the master branch, on stable branches it's out of date.
 
 v 8.7.0 (unreleased)
+  - All service classes (those residing in app/services) are now instrumented (Yorick Peterse)
   - Enable gzip for assets, makes the page size significantly smaller. !3544 / !3632 (Connor Shea)
   - Load award emoji images separately unless opening the full picker. Saves several hundred KBs of data for most pages. (Connor Shea)
   - All images in discussions and wikis now link to their source files !3464 (Connor Shea).
-- 
GitLab