From 396a0f756cf9e5dfce511fbf1f261b6843b08e0f Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 12:33:23 +0100 Subject: [PATCH 01/29] add conditional skylight tracking --- .gitignore | 1 + Gemfile | 1 + Gemfile.lock | 5 ++- lib/travis/api/app.rb | 1 + lib/travis/api/conditional_skylight.rb | 50 ++++++++++++++++++++++++++ 5 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 lib/travis/api/conditional_skylight.rb diff --git a/.gitignore b/.gitignore index e5dba86d..68072775 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ config/travis.yml .yardoc log/ vendor +config/skylight.yml diff --git a/Gemfile b/Gemfile index aa41780b..1b0280e0 100644 --- a/Gemfile +++ b/Gemfile @@ -27,6 +27,7 @@ gem 'pry' gem 'metriks', '0.9.9.6' gem 'metriks-librato_metrics', github: 'eric/metriks-librato_metrics' gem 'micro_migrations' +gem 'skylight', '~> 0.6.0.beta.1' group :test do gem 'rspec', '~> 2.13' diff --git a/Gemfile.lock b/Gemfile.lock index f85ae2cf..c12faada 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -81,7 +81,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-yaml.git - revision: f3aa306016a08b66a487f966eb8aa3a60ee9b319 + revision: 1630d576d221aea2340615e87f402df7889b5176 specs: travis-yaml (0.2.0) @@ -302,6 +302,8 @@ GEM rack-test sinatra (~> 1.4.0) tilt (~> 1.3) + skylight (0.6.0.beta.1) + activesupport (>= 3.0.0) slop (3.6.0) sprockets (2.2.3) hike (~> 1.2) @@ -367,6 +369,7 @@ DEPENDENCIES sentry-raven! sinatra sinatra-contrib + skylight (~> 0.6.0.beta.1) travis-api! travis-config (~> 0.1.0) travis-core! diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index 1934ede2..b1aea36b 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -20,6 +20,7 @@ require 'metriks/librato_metrics_reporter' require 'travis/support/log_subscriber/active_record_metrics' require 'fileutils' require 'travis/api/v2/http' +require 'travis/api/conditional_skylight' # Rack class implementing the HTTP API. # Instances respond to #call. diff --git a/lib/travis/api/conditional_skylight.rb b/lib/travis/api/conditional_skylight.rb new file mode 100644 index 00000000..773a316d --- /dev/null +++ b/lib/travis/api/conditional_skylight.rb @@ -0,0 +1,50 @@ +if ENV['SKYLIGHT_AUTHENTICATION'] + + require 'skylight/sinatra' + require 'tool/thread_local' + Skylight.start! + + module Travis + module Api + module ConditionalSkylight + FEATURES = Tool::ThreadLocal.new + CHECK_FREQUENCY = 120 + NOT_JSON = %r(\.(xml|png|txt|atom|svg)$) + + module Middleware + ::Skylight::Middleware.send(:prepend, self) + def call(env) + if ConditionalSkylight.track?(env) + super(env) + else + t { "skipping middleware (condition not met)".freeze } + @app.call(env) + end + end + end + + extend self + + def track?(env) + return false unless feature_active? :skylight + return false if feature_active? :skylight_json_only and env['PATH_INFO'.freeze] =~ NOT_JSON + true + end + + def feature_active?(feature) + last_clear = Time.now.to_i - FEATURES[:last_clear].to_i + + if last_clear > CHECK_FREQUENCY + FEATURES.clear + FEATURES[:last_clear] = Time.now.to_i + end + + FEATURES.fetch(feature) { FEATURES[feature] = Travis::Features.feature_active?(feature) } + end + end + end + end + +else + Travis.logger.info('SKYLIGHT_AUTHENTICATION not set, skipping Skylight.') +end From 14a3ba54081f957f7452574af98fdb08298326b8 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 13:05:09 +0100 Subject: [PATCH 02/29] use patched skylight --- Gemfile | 2 +- Gemfile.lock | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 1b0280e0..8bd41c72 100644 --- a/Gemfile +++ b/Gemfile @@ -27,7 +27,7 @@ gem 'pry' gem 'metriks', '0.9.9.6' gem 'metriks-librato_metrics', github: 'eric/metriks-librato_metrics' gem 'micro_migrations' -gem 'skylight', '~> 0.6.0.beta.1' +gem 'skylight', github: 'rkh/skylight-ruby', branch: 'rkh-script-name-sinatra' group :test do gem 'rspec', '~> 2.13' diff --git a/Gemfile.lock b/Gemfile.lock index c12faada..e0e52375 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -20,6 +20,14 @@ GIT rack-contrib (1.2.0) rack (>= 0.9.1) +GIT + remote: git://github.com/rkh/skylight-ruby.git + revision: 8dbe7270188fd1e0df9497835728c5200cf883dc + branch: rkh-script-name-sinatra + specs: + skylight (0.6.0.beta.1) + activesupport (>= 3.0.0) + GIT remote: git://github.com/rkh/yard-sinatra.git revision: 00774d355123617ff0faa7e0ebd54c4cdcfcdf93 @@ -302,8 +310,6 @@ GEM rack-test sinatra (~> 1.4.0) tilt (~> 1.3) - skylight (0.6.0.beta.1) - activesupport (>= 3.0.0) slop (3.6.0) sprockets (2.2.3) hike (~> 1.2) @@ -369,7 +375,7 @@ DEPENDENCIES sentry-raven! sinatra sinatra-contrib - skylight (~> 0.6.0.beta.1) + skylight! travis-api! travis-config (~> 0.1.0) travis-core! From 0aebede82dfe76a5ae3c9095be6860f2d0b1d782 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 13:11:46 +0100 Subject: [PATCH 03/29] update skylight --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index e0e52375..ec0c0a9d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -22,7 +22,7 @@ GIT GIT remote: git://github.com/rkh/skylight-ruby.git - revision: 8dbe7270188fd1e0df9497835728c5200cf883dc + revision: 287673533ee47e10fd75adb78bae1e732b8f3c30 branch: rkh-script-name-sinatra specs: skylight (0.6.0.beta.1) From ea4a1c5bc4ee35284715e0f93b3e3ed8f8a2bc90 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 13:41:31 +0100 Subject: [PATCH 04/29] use skylight without their sinatra code --- Gemfile | 2 +- Gemfile.lock | 12 +-- lib/travis/api/app.rb | 1 + lib/travis/api/app/middleware/skylight.rb | 5 + .../api/app/middleware/skylight/actual.rb | 26 +++++ .../api/app/middleware/skylight/dummy.rb | 7 ++ lib/travis/api/conditional_skylight.rb | 100 +++++++++--------- 7 files changed, 93 insertions(+), 60 deletions(-) create mode 100644 lib/travis/api/app/middleware/skylight.rb create mode 100644 lib/travis/api/app/middleware/skylight/actual.rb create mode 100644 lib/travis/api/app/middleware/skylight/dummy.rb diff --git a/Gemfile b/Gemfile index 8bd41c72..e433a477 100644 --- a/Gemfile +++ b/Gemfile @@ -27,7 +27,7 @@ gem 'pry' gem 'metriks', '0.9.9.6' gem 'metriks-librato_metrics', github: 'eric/metriks-librato_metrics' gem 'micro_migrations' -gem 'skylight', github: 'rkh/skylight-ruby', branch: 'rkh-script-name-sinatra' +gem 'skylight' group :test do gem 'rspec', '~> 2.13' diff --git a/Gemfile.lock b/Gemfile.lock index ec0c0a9d..3f38a26c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -20,14 +20,6 @@ GIT rack-contrib (1.2.0) rack (>= 0.9.1) -GIT - remote: git://github.com/rkh/skylight-ruby.git - revision: 287673533ee47e10fd75adb78bae1e732b8f3c30 - branch: rkh-script-name-sinatra - specs: - skylight (0.6.0.beta.1) - activesupport (>= 3.0.0) - GIT remote: git://github.com/rkh/yard-sinatra.git revision: 00774d355123617ff0faa7e0ebd54c4cdcfcdf93 @@ -310,6 +302,8 @@ GEM rack-test sinatra (~> 1.4.0) tilt (~> 1.3) + skylight (0.6.0.beta.1) + activesupport (>= 3.0.0) slop (3.6.0) sprockets (2.2.3) hike (~> 1.2) @@ -375,7 +369,7 @@ DEPENDENCIES sentry-raven! sinatra sinatra-contrib - skylight! + skylight travis-api! travis-config (~> 0.1.0) travis-core! diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index b1aea36b..cf4e3bc5 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -113,6 +113,7 @@ module Travis::Api use Travis::Api::App::Middleware::ScopeCheck use Travis::Api::App::Middleware::Logging + use Travis::Api::App::Middleware::Skylight use Travis::Api::App::Middleware::Metriks use Travis::Api::App::Middleware::Rewrite use Travis::Api::App::Middleware::UserAgentTracker diff --git a/lib/travis/api/app/middleware/skylight.rb b/lib/travis/api/app/middleware/skylight.rb new file mode 100644 index 00000000..ccd2c527 --- /dev/null +++ b/lib/travis/api/app/middleware/skylight.rb @@ -0,0 +1,5 @@ +if ENV['SKYLIGHT_AUTHENTICATION'] + require_relative 'skylight/actual' +else + require_relative 'skylight/dummy' +end diff --git a/lib/travis/api/app/middleware/skylight/actual.rb b/lib/travis/api/app/middleware/skylight/actual.rb new file mode 100644 index 00000000..a7a59696 --- /dev/null +++ b/lib/travis/api/app/middleware/skylight/actual.rb @@ -0,0 +1,26 @@ +require 'travis/api/app' +require 'skylight' +require 'skylight/probes/tilt' +require 'skylight/probes/redis' + +class Travis::Api::App + class Middleware + class Skylight < Middleware + set(:setup) { ::Skylight.start! } + use ::Skylight::Middleware + + after do + instrumenter = Skylight::Instrumenter.instance + trace = instrumenter.current_trace if instrumenter + trace.endpoint = endpoint if trace and endpoint + end + + def endpoint + return @endpoint if defined? @endpoint and @endpoint + return unless headers['X-Pattern'].present? and headers['X-Endpoint'].present? + @endpoint = Object.const_get(headers['X-Endpoint']) + headers['X-Pattern'] + rescue NameError + end + end + end +end diff --git a/lib/travis/api/app/middleware/skylight/dummy.rb b/lib/travis/api/app/middleware/skylight/dummy.rb new file mode 100644 index 00000000..d4309f23 --- /dev/null +++ b/lib/travis/api/app/middleware/skylight/dummy.rb @@ -0,0 +1,7 @@ +class Travis::Api::App + class Middleware + module Skylight + def self.new(app) app end + end + end +end diff --git a/lib/travis/api/conditional_skylight.rb b/lib/travis/api/conditional_skylight.rb index 773a316d..d4a2de37 100644 --- a/lib/travis/api/conditional_skylight.rb +++ b/lib/travis/api/conditional_skylight.rb @@ -1,50 +1,50 @@ -if ENV['SKYLIGHT_AUTHENTICATION'] - - require 'skylight/sinatra' - require 'tool/thread_local' - Skylight.start! - - module Travis - module Api - module ConditionalSkylight - FEATURES = Tool::ThreadLocal.new - CHECK_FREQUENCY = 120 - NOT_JSON = %r(\.(xml|png|txt|atom|svg)$) - - module Middleware - ::Skylight::Middleware.send(:prepend, self) - def call(env) - if ConditionalSkylight.track?(env) - super(env) - else - t { "skipping middleware (condition not met)".freeze } - @app.call(env) - end - end - end - - extend self - - def track?(env) - return false unless feature_active? :skylight - return false if feature_active? :skylight_json_only and env['PATH_INFO'.freeze] =~ NOT_JSON - true - end - - def feature_active?(feature) - last_clear = Time.now.to_i - FEATURES[:last_clear].to_i - - if last_clear > CHECK_FREQUENCY - FEATURES.clear - FEATURES[:last_clear] = Time.now.to_i - end - - FEATURES.fetch(feature) { FEATURES[feature] = Travis::Features.feature_active?(feature) } - end - end - end - end - -else - Travis.logger.info('SKYLIGHT_AUTHENTICATION not set, skipping Skylight.') -end +# if ENV['SKYLIGHT_AUTHENTICATION'] +# +# # require 'skylight/sinatra' +# # require 'tool/thread_local' +# # Skylight.start! +# # +# # module Travis +# # module Api +# # module ConditionalSkylight +# # FEATURES = Tool::ThreadLocal.new +# # CHECK_FREQUENCY = 120 +# # NOT_JSON = %r(\.(xml|png|txt|atom|svg)$) +# # +# # module Middleware +# # ::Skylight::Middleware.send(:prepend, self) +# # def call(env) +# # if ConditionalSkylight.track?(env) +# # super(env) +# # else +# # t { "skipping middleware (condition not met)".freeze } +# # @app.call(env) +# # end +# # end +# # end +# # +# # extend self +# # +# # def track?(env) +# # return false unless feature_active? :skylight +# # return false if feature_active? :skylight_json_only and env['PATH_INFO'.freeze] =~ NOT_JSON +# # true +# # end +# # +# # def feature_active?(feature) +# # last_clear = Time.now.to_i - FEATURES[:last_clear].to_i +# # +# # if last_clear > CHECK_FREQUENCY +# # FEATURES.clear +# # FEATURES[:last_clear] = Time.now.to_i +# # end +# # +# # FEATURES.fetch(feature) { FEATURES[feature] = Travis::Features.feature_active?(feature) } +# # end +# # end +# # end +# # end +# +# else +# Travis.logger.info('SKYLIGHT_AUTHENTICATION not set, skipping Skylight.') +# end From 690c59820568bedf38e8a9fd8cc890a85c49ba6b Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 13:43:55 +0100 Subject: [PATCH 05/29] remove obsolete file --- lib/travis/api/app.rb | 1 - lib/travis/api/conditional_skylight.rb | 50 -------------------------- 2 files changed, 51 deletions(-) delete mode 100644 lib/travis/api/conditional_skylight.rb diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index cf4e3bc5..1bf44abe 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -20,7 +20,6 @@ require 'metriks/librato_metrics_reporter' require 'travis/support/log_subscriber/active_record_metrics' require 'fileutils' require 'travis/api/v2/http' -require 'travis/api/conditional_skylight' # Rack class implementing the HTTP API. # Instances respond to #call. diff --git a/lib/travis/api/conditional_skylight.rb b/lib/travis/api/conditional_skylight.rb deleted file mode 100644 index d4a2de37..00000000 --- a/lib/travis/api/conditional_skylight.rb +++ /dev/null @@ -1,50 +0,0 @@ -# if ENV['SKYLIGHT_AUTHENTICATION'] -# -# # require 'skylight/sinatra' -# # require 'tool/thread_local' -# # Skylight.start! -# # -# # module Travis -# # module Api -# # module ConditionalSkylight -# # FEATURES = Tool::ThreadLocal.new -# # CHECK_FREQUENCY = 120 -# # NOT_JSON = %r(\.(xml|png|txt|atom|svg)$) -# # -# # module Middleware -# # ::Skylight::Middleware.send(:prepend, self) -# # def call(env) -# # if ConditionalSkylight.track?(env) -# # super(env) -# # else -# # t { "skipping middleware (condition not met)".freeze } -# # @app.call(env) -# # end -# # end -# # end -# # -# # extend self -# # -# # def track?(env) -# # return false unless feature_active? :skylight -# # return false if feature_active? :skylight_json_only and env['PATH_INFO'.freeze] =~ NOT_JSON -# # true -# # end -# # -# # def feature_active?(feature) -# # last_clear = Time.now.to_i - FEATURES[:last_clear].to_i -# # -# # if last_clear > CHECK_FREQUENCY -# # FEATURES.clear -# # FEATURES[:last_clear] = Time.now.to_i -# # end -# # -# # FEATURES.fetch(feature) { FEATURES[feature] = Travis::Features.feature_active?(feature) } -# # end -# # end -# # end -# # end -# -# else -# Travis.logger.info('SKYLIGHT_AUTHENTICATION not set, skipping Skylight.') -# end From 73f55b8243cd6c4cf0301594ef9b2234849a97db Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 14:07:44 +0100 Subject: [PATCH 06/29] fix name issue --- lib/travis/api/app/middleware/skylight/actual.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/travis/api/app/middleware/skylight/actual.rb b/lib/travis/api/app/middleware/skylight/actual.rb index a7a59696..66d0df13 100644 --- a/lib/travis/api/app/middleware/skylight/actual.rb +++ b/lib/travis/api/app/middleware/skylight/actual.rb @@ -10,7 +10,7 @@ class Travis::Api::App use ::Skylight::Middleware after do - instrumenter = Skylight::Instrumenter.instance + instrumenter = ::Skylight::Instrumenter.instance trace = instrumenter.current_trace if instrumenter trace.endpoint = endpoint if trace and endpoint end From f5b3349d89a5300001a0f63c8f78190847dc8396 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 14:12:54 +0100 Subject: [PATCH 07/29] trying out things --- lib/travis/api/app/middleware/skylight/actual.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/travis/api/app/middleware/skylight/actual.rb b/lib/travis/api/app/middleware/skylight/actual.rb index 66d0df13..98d87828 100644 --- a/lib/travis/api/app/middleware/skylight/actual.rb +++ b/lib/travis/api/app/middleware/skylight/actual.rb @@ -12,7 +12,7 @@ class Travis::Api::App after do instrumenter = ::Skylight::Instrumenter.instance trace = instrumenter.current_trace if instrumenter - trace.endpoint = endpoint if trace and endpoint + trace.endpoint = "#{request.method} #{endpoint}" || "unknown" if trace end def endpoint From 301880b60060e7ecdf2dfa768924bdd3e67d6c0e Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 14:16:28 +0100 Subject: [PATCH 08/29] fix method name --- lib/travis/api/app/middleware/skylight/actual.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/travis/api/app/middleware/skylight/actual.rb b/lib/travis/api/app/middleware/skylight/actual.rb index 98d87828..8ea53fd3 100644 --- a/lib/travis/api/app/middleware/skylight/actual.rb +++ b/lib/travis/api/app/middleware/skylight/actual.rb @@ -12,7 +12,7 @@ class Travis::Api::App after do instrumenter = ::Skylight::Instrumenter.instance trace = instrumenter.current_trace if instrumenter - trace.endpoint = "#{request.method} #{endpoint}" || "unknown" if trace + trace.endpoint = "#{request.request_method} #{endpoint}" || "unknown" if trace end def endpoint From 50457104877e11574647e86d745900ec293f57ae Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 14:19:43 +0100 Subject: [PATCH 09/29] do not rescue --- lib/travis/api/app/middleware/skylight/actual.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/travis/api/app/middleware/skylight/actual.rb b/lib/travis/api/app/middleware/skylight/actual.rb index 8ea53fd3..082cb34c 100644 --- a/lib/travis/api/app/middleware/skylight/actual.rb +++ b/lib/travis/api/app/middleware/skylight/actual.rb @@ -19,7 +19,6 @@ class Travis::Api::App return @endpoint if defined? @endpoint and @endpoint return unless headers['X-Pattern'].present? and headers['X-Endpoint'].present? @endpoint = Object.const_get(headers['X-Endpoint']) + headers['X-Pattern'] - rescue NameError end end end From b03e9c55591c945032fe92b5f8e2deaaef93c2f6 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 14:22:10 +0100 Subject: [PATCH 10/29] fix prefix detection --- lib/travis/api/app/middleware/skylight/actual.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/travis/api/app/middleware/skylight/actual.rb b/lib/travis/api/app/middleware/skylight/actual.rb index 082cb34c..eb140a0d 100644 --- a/lib/travis/api/app/middleware/skylight/actual.rb +++ b/lib/travis/api/app/middleware/skylight/actual.rb @@ -18,7 +18,7 @@ class Travis::Api::App def endpoint return @endpoint if defined? @endpoint and @endpoint return unless headers['X-Pattern'].present? and headers['X-Endpoint'].present? - @endpoint = Object.const_get(headers['X-Endpoint']) + headers['X-Pattern'] + @endpoint = Object.const_get(headers['X-Endpoint']).prefix + headers['X-Pattern'] end end end From fb74fcc711be0f23b8191258f258b75a2c73c2f1 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 14:28:07 +0100 Subject: [PATCH 11/29] debug that --- lib/travis/api/app/middleware/skylight/actual.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/travis/api/app/middleware/skylight/actual.rb b/lib/travis/api/app/middleware/skylight/actual.rb index eb140a0d..6ca906c1 100644 --- a/lib/travis/api/app/middleware/skylight/actual.rb +++ b/lib/travis/api/app/middleware/skylight/actual.rb @@ -12,7 +12,7 @@ class Travis::Api::App after do instrumenter = ::Skylight::Instrumenter.instance trace = instrumenter.current_trace if instrumenter - trace.endpoint = "#{request.request_method} #{endpoint}" || "unknown" if trace + p trace.endpoint = "#{request.request_method} #{endpoint}" || "unknown" if trace end def endpoint From f5f6b9d771c14a548a20e42deff6e9ec836d4e6b Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 15:52:19 +0100 Subject: [PATCH 12/29] I HAVE NO IDEA WHAT I'M DOING --- lib/travis/api/app/middleware/skylight/actual.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/travis/api/app/middleware/skylight/actual.rb b/lib/travis/api/app/middleware/skylight/actual.rb index 6ca906c1..3a77fa10 100644 --- a/lib/travis/api/app/middleware/skylight/actual.rb +++ b/lib/travis/api/app/middleware/skylight/actual.rb @@ -12,7 +12,8 @@ class Travis::Api::App after do instrumenter = ::Skylight::Instrumenter.instance trace = instrumenter.current_trace if instrumenter - p trace.endpoint = "#{request.request_method} #{endpoint}" || "unknown" if trace + x = trace.endpoint = "#{request.request_method} #{endpoint}" || "unknown" if trace + puts env.inspect unless x end def endpoint From 831549a17347cd18c85f79b2f563273de75cda08 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 15:56:44 +0100 Subject: [PATCH 13/29] use path info if we don't have a pattern --- lib/travis/api/app/middleware/skylight/actual.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/travis/api/app/middleware/skylight/actual.rb b/lib/travis/api/app/middleware/skylight/actual.rb index 3a77fa10..3e0d736c 100644 --- a/lib/travis/api/app/middleware/skylight/actual.rb +++ b/lib/travis/api/app/middleware/skylight/actual.rb @@ -12,8 +12,7 @@ class Travis::Api::App after do instrumenter = ::Skylight::Instrumenter.instance trace = instrumenter.current_trace if instrumenter - x = trace.endpoint = "#{request.request_method} #{endpoint}" || "unknown" if trace - puts env.inspect unless x + trace.endpoint = "#{request.request_method} #{endpoint || request.path_info}" if trace end def endpoint From decf338a38fa35abe72933e5434eb03eeef78244 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 16:15:03 +0100 Subject: [PATCH 14/29] automated middleware instrumentation --- lib/travis/api/app.rb | 2 + lib/travis/api/app/stack_instrumentation.rb | 42 +++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 lib/travis/api/app/stack_instrumentation.rb diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index 1bf44abe..b092aee8 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -20,6 +20,7 @@ require 'metriks/librato_metrics_reporter' require 'travis/support/log_subscriber/active_record_metrics' require 'fileutils' require 'travis/api/v2/http' +require 'travis/api/stack_instrumentation' # Rack class implementing the HTTP API. # Instances respond to #call. @@ -75,6 +76,7 @@ module Travis::Api def initialize @app = Rack::Builder.app do + extend StackInstrumentation use(Rack::Config) { |env| env['metriks.request.start'] ||= Time.now.utc } Rack::Utils::HTTP_STATUS_CODES[420] = "Enhance Your Calm" diff --git a/lib/travis/api/app/stack_instrumentation.rb b/lib/travis/api/app/stack_instrumentation.rb new file mode 100644 index 00000000..f6fdec78 --- /dev/null +++ b/lib/travis/api/app/stack_instrumentation.rb @@ -0,0 +1,42 @@ +require 'travis/api/app' + +class Travis::Api::App + module StackInstrumentation + class Middleware + def initialize(app, title = nil) + @app = app + @title = title || "Rack: use #{app.class.name}" + end + + def call(env) + instrument { @app.call(env) } + end + + def instrument(&block) + return yield unless instrument? + ::Skylight.instrument(title: title, &block) + end + + def instrument? + defined? ::Skylight + end + end + + def use(*) + super(Middleware) + super + end + + def run(app) + super Middleware.new(app, "Rack: run %p" % app.class) + end + + def map(path, &block) + super(path) do + use(Middleware, "Rack: map %p" % path) + extend StackInstrumentation + instance_eval(&block) + end + end + end +end From 784ca8479f929ada0fd3f4622c23a149cca3d262 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 16:18:24 +0100 Subject: [PATCH 15/29] fix require --- lib/travis/api/app.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index b092aee8..bb72a075 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -20,7 +20,7 @@ require 'metriks/librato_metrics_reporter' require 'travis/support/log_subscriber/active_record_metrics' require 'fileutils' require 'travis/api/v2/http' -require 'travis/api/stack_instrumentation' +require 'travis/api/app/stack_instrumentation' # Rack class implementing the HTTP API. # Instances respond to #call. From 4a6dabaa0eca63cf5f4ca17b69006b7b3e7153e8 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 16:21:07 +0100 Subject: [PATCH 16/29] fix typo --- lib/travis/api/app/stack_instrumentation.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/travis/api/app/stack_instrumentation.rb b/lib/travis/api/app/stack_instrumentation.rb index f6fdec78..51b28fb2 100644 --- a/lib/travis/api/app/stack_instrumentation.rb +++ b/lib/travis/api/app/stack_instrumentation.rb @@ -14,7 +14,7 @@ class Travis::Api::App def instrument(&block) return yield unless instrument? - ::Skylight.instrument(title: title, &block) + ::Skylight.instrument(title: @title, &block) end def instrument? From 4c2d1b89b3a8c6dd4117fac23589c41b953dbb02 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 16:30:04 +0100 Subject: [PATCH 17/29] better titles --- lib/travis/api/app/stack_instrumentation.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/travis/api/app/stack_instrumentation.rb b/lib/travis/api/app/stack_instrumentation.rb index 51b28fb2..7e8e9a63 100644 --- a/lib/travis/api/app/stack_instrumentation.rb +++ b/lib/travis/api/app/stack_instrumentation.rb @@ -5,7 +5,7 @@ class Travis::Api::App class Middleware def initialize(app, title = nil) @app = app - @title = title || "Rack: use #{app.class.name}" + @title = title || StackInstrumentation.title_for(app, :use) end def call(env) @@ -22,18 +22,28 @@ class Travis::Api::App end end + def self.title_for(verb, object) + object &&= case object + when ::Sinatra::Wrapper then object.settings.inspect + when Class, Module then object.inspect + when String then object + else object.class.inspect + end + "Rack: #{verb} #{object}" + end + def use(*) super(Middleware) super end def run(app) - super Middleware.new(app, "Rack: run %p" % app.class) + super Middleware.new(app, StackInstrumentation.title_for(app, :run)) end def map(path, &block) super(path) do - use(Middleware, "Rack: map %p" % path) + use(Middleware, StackInstrumentation.title_for(path, :map)) extend StackInstrumentation instance_eval(&block) end From e11733527f46a642eabf6a56f5bead0db478262c Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 16:31:49 +0100 Subject: [PATCH 18/29] downgrade ruby --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index e433a477..7a2f174e 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ source 'https://rubygems.org' gemspec -ruby "2.1.5" +ruby '2.1.2' if ENV.key?('DYNO') gem 's3', github: 'travis-ci/s3' From 89aaff401c941a73060d109dd916f7686861955f Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 16:33:58 +0100 Subject: [PATCH 19/29] switcheroo --- lib/travis/api/app/stack_instrumentation.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/travis/api/app/stack_instrumentation.rb b/lib/travis/api/app/stack_instrumentation.rb index 7e8e9a63..0307b6b3 100644 --- a/lib/travis/api/app/stack_instrumentation.rb +++ b/lib/travis/api/app/stack_instrumentation.rb @@ -22,7 +22,7 @@ class Travis::Api::App end end - def self.title_for(verb, object) + def self.title_for(object, verb) object &&= case object when ::Sinatra::Wrapper then object.settings.inspect when Class, Module then object.inspect From 81b0019f14f84a3f88e159541e6c87df5c7821b1 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 16:52:56 +0100 Subject: [PATCH 20/29] move skylight up --- lib/travis/api/app.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index bb72a075..07682455 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -77,6 +77,7 @@ module Travis::Api def initialize @app = Rack::Builder.app do extend StackInstrumentation + use Travis::Api::App::Middleware::Skylight use(Rack::Config) { |env| env['metriks.request.start'] ||= Time.now.utc } Rack::Utils::HTTP_STATUS_CODES[420] = "Enhance Your Calm" @@ -114,7 +115,6 @@ module Travis::Api use Travis::Api::App::Middleware::ScopeCheck use Travis::Api::App::Middleware::Logging - use Travis::Api::App::Middleware::Skylight use Travis::Api::App::Middleware::Metriks use Travis::Api::App::Middleware::Rewrite use Travis::Api::App::Middleware::UserAgentTracker From 7d5d6b578cf90b63b74b9576e382b8e47dd442b8 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 17:00:16 +0100 Subject: [PATCH 21/29] instrument access token --- lib/travis/api/app.rb | 1 + lib/travis/api/app/access_token.rb | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index 07682455..8c0c86f3 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -1,3 +1,4 @@ +require 'skylight' require 'travis' require 'travis/model' require 'travis/support/amqp' diff --git a/lib/travis/api/app/access_token.rb b/lib/travis/api/app/access_token.rb index 99a70ad5..13219b3b 100644 --- a/lib/travis/api/app/access_token.rb +++ b/lib/travis/api/app/access_token.rb @@ -3,6 +3,8 @@ require 'securerandom' class Travis::Api::App class AccessToken + include Skylight::Helpers + DEFAULT_SCOPES = [:public, :private] attr_reader :token, :scopes, :user_id, :app_id, :expires_in, :extra @@ -22,6 +24,7 @@ class Travis::Api::App new(token: token, scopes: scopes, user_id: user_id, app_id: app_id, extra: extra) if user_id end + instrument_method def initialize(options = {}) raise ArgumentError, 'must supply either user_id or user' unless options.key?(:user) ^ options.key?(:user_id) raise ArgumentError, 'must supply app_id' unless options.key?(:app_id) @@ -40,6 +43,7 @@ class Travis::Api::App @extra = options[:extra] end + instrument_method def save key = key(token) redis.del(key) @@ -90,6 +94,7 @@ class Travis::Api::App private + instrument_method def reuse_token redis.get(reuse_key) unless expires_in end From a42afd5180630d23cd3b1f74bfbbab005510f4ae Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 17:06:25 +0100 Subject: [PATCH 22/29] fail nicely when not able to figure out endpoint --- lib/travis/api/app/middleware/skylight/actual.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/travis/api/app/middleware/skylight/actual.rb b/lib/travis/api/app/middleware/skylight/actual.rb index 3e0d736c..f15ad8ee 100644 --- a/lib/travis/api/app/middleware/skylight/actual.rb +++ b/lib/travis/api/app/middleware/skylight/actual.rb @@ -19,6 +19,7 @@ class Travis::Api::App return @endpoint if defined? @endpoint and @endpoint return unless headers['X-Pattern'].present? and headers['X-Endpoint'].present? @endpoint = Object.const_get(headers['X-Endpoint']).prefix + headers['X-Pattern'] + rescue NameError end end end From a8b1ccfc4a6e093f23880bb2d2a590bf6bdd8032 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 17:07:38 +0100 Subject: [PATCH 23/29] instrument responders --- lib/travis/api/app/responders/atom.rb | 1 + lib/travis/api/app/responders/badge.rb | 1 + lib/travis/api/app/responders/base.rb | 1 + lib/travis/api/app/responders/image.rb | 1 + lib/travis/api/app/responders/json.rb | 1 + lib/travis/api/app/responders/plain.rb | 1 + lib/travis/api/app/responders/service.rb | 1 + lib/travis/api/app/responders/xml.rb | 1 + 8 files changed, 8 insertions(+) diff --git a/lib/travis/api/app/responders/atom.rb b/lib/travis/api/app/responders/atom.rb index 163cf7a3..8bdd3e44 100644 --- a/lib/travis/api/app/responders/atom.rb +++ b/lib/travis/api/app/responders/atom.rb @@ -44,6 +44,7 @@ module Travis::Api::App::Responders super && resource.is_a?(ActiveRecord::Relation) && resource.first.is_a?(Build) end + instrument_method def apply super diff --git a/lib/travis/api/app/responders/badge.rb b/lib/travis/api/app/responders/badge.rb index 6c759b85..ec348228 100644 --- a/lib/travis/api/app/responders/badge.rb +++ b/lib/travis/api/app/responders/badge.rb @@ -4,6 +4,7 @@ module Travis::Api::App::Responders 'svg' end + instrument_method def apply set_headers send_file(filename, type: :svg, last_modified: last_modified) diff --git a/lib/travis/api/app/responders/base.rb b/lib/travis/api/app/responders/base.rb index 5f463d9c..525779a2 100644 --- a/lib/travis/api/app/responders/base.rb +++ b/lib/travis/api/app/responders/base.rb @@ -1,5 +1,6 @@ module Travis::Api::App::Responders class Base + include Skylight::Helpers attr_reader :endpoint, :resource, :options def initialize(endpoint, resource, options = {}) diff --git a/lib/travis/api/app/responders/image.rb b/lib/travis/api/app/responders/image.rb index df126d55..5ce73814 100644 --- a/lib/travis/api/app/responders/image.rb +++ b/lib/travis/api/app/responders/image.rb @@ -10,6 +10,7 @@ module Travis::Api::App::Responders headers['Content-Disposition'] = %(inline; filename="#{File.basename(filename)}") end + instrument_method def apply set_headers send_file(filename, type: :png, last_modified: last_modified) diff --git a/lib/travis/api/app/responders/json.rb b/lib/travis/api/app/responders/json.rb index 8d8b0314..441039a9 100644 --- a/lib/travis/api/app/responders/json.rb +++ b/lib/travis/api/app/responders/json.rb @@ -7,6 +7,7 @@ class Travis::Api::App super && !resource.is_a?(String) && !resource.nil? && accepts_log? end + instrument_method def apply super diff --git a/lib/travis/api/app/responders/plain.rb b/lib/travis/api/app/responders/plain.rb index 236bfdcf..df27b210 100644 --- a/lib/travis/api/app/responders/plain.rb +++ b/lib/travis/api/app/responders/plain.rb @@ -13,6 +13,7 @@ module Travis::Api::App::Responders super && (resource.is_a?(Log) || resource.is_a?(String)) end + instrument_method def apply super diff --git a/lib/travis/api/app/responders/service.rb b/lib/travis/api/app/responders/service.rb index 57942234..5f6f5655 100644 --- a/lib/travis/api/app/responders/service.rb +++ b/lib/travis/api/app/responders/service.rb @@ -10,6 +10,7 @@ module Travis::Api resource.respond_to?(:run) end + instrument_method def apply cache_control result = normalize(resource.run) diff --git a/lib/travis/api/app/responders/xml.rb b/lib/travis/api/app/responders/xml.rb index 7db0a964..871dbc22 100644 --- a/lib/travis/api/app/responders/xml.rb +++ b/lib/travis/api/app/responders/xml.rb @@ -37,6 +37,7 @@ module Travis::Api::App::Responders super && @resource.first.is_a?(Repository) end + instrument_method def apply super From 327da14def596c259bc0de27b847d49bcf7a316a Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 17:22:10 +0100 Subject: [PATCH 24/29] instrument services --- lib/travis/api/app.rb | 2 +- lib/travis/api/instruments.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 lib/travis/api/instruments.rb diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index 8c0c86f3..e5f18631 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -1,4 +1,3 @@ -require 'skylight' require 'travis' require 'travis/model' require 'travis/support/amqp' @@ -20,6 +19,7 @@ require 'metriks/reporter/logger' require 'metriks/librato_metrics_reporter' require 'travis/support/log_subscriber/active_record_metrics' require 'fileutils' +require 'travis/api/instruments' require 'travis/api/v2/http' require 'travis/api/app/stack_instrumentation' diff --git a/lib/travis/api/instruments.rb b/lib/travis/api/instruments.rb new file mode 100644 index 00000000..a6973f8d --- /dev/null +++ b/lib/travis/api/instruments.rb @@ -0,0 +1,6 @@ +require 'skylight' + +Travis.services.send(:services).each_value do |service| + service.send(:include, Skylight::Helpers) + service.send(:instrument_method, :run) +end \ No newline at end of file From 6681d160c1621587a2f88e40878b805cdad4e48a Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 17:39:59 +0100 Subject: [PATCH 25/29] Revert "instrument services" This reverts commit 327da14def596c259bc0de27b847d49bcf7a316a. --- lib/travis/api/app.rb | 2 +- lib/travis/api/instruments.rb | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) delete mode 100644 lib/travis/api/instruments.rb diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index e5f18631..8c0c86f3 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -1,3 +1,4 @@ +require 'skylight' require 'travis' require 'travis/model' require 'travis/support/amqp' @@ -19,7 +20,6 @@ require 'metriks/reporter/logger' require 'metriks/librato_metrics_reporter' require 'travis/support/log_subscriber/active_record_metrics' require 'fileutils' -require 'travis/api/instruments' require 'travis/api/v2/http' require 'travis/api/app/stack_instrumentation' diff --git a/lib/travis/api/instruments.rb b/lib/travis/api/instruments.rb deleted file mode 100644 index a6973f8d..00000000 --- a/lib/travis/api/instruments.rb +++ /dev/null @@ -1,6 +0,0 @@ -require 'skylight' - -Travis.services.send(:services).each_value do |service| - service.send(:include, Skylight::Helpers) - service.send(:instrument_method, :run) -end \ No newline at end of file From 01ec5e152a3996d9925d7d3b141f8f555e9f2fa0 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 18:07:40 +0100 Subject: [PATCH 26/29] Revert "instrument responders" This reverts commit a8b1ccfc4a6e093f23880bb2d2a590bf6bdd8032. --- lib/travis/api/app/responders/atom.rb | 1 - lib/travis/api/app/responders/badge.rb | 1 - lib/travis/api/app/responders/base.rb | 1 - lib/travis/api/app/responders/image.rb | 1 - lib/travis/api/app/responders/json.rb | 1 - lib/travis/api/app/responders/plain.rb | 1 - lib/travis/api/app/responders/service.rb | 1 - lib/travis/api/app/responders/xml.rb | 1 - 8 files changed, 8 deletions(-) diff --git a/lib/travis/api/app/responders/atom.rb b/lib/travis/api/app/responders/atom.rb index 8bdd3e44..163cf7a3 100644 --- a/lib/travis/api/app/responders/atom.rb +++ b/lib/travis/api/app/responders/atom.rb @@ -44,7 +44,6 @@ module Travis::Api::App::Responders super && resource.is_a?(ActiveRecord::Relation) && resource.first.is_a?(Build) end - instrument_method def apply super diff --git a/lib/travis/api/app/responders/badge.rb b/lib/travis/api/app/responders/badge.rb index ec348228..6c759b85 100644 --- a/lib/travis/api/app/responders/badge.rb +++ b/lib/travis/api/app/responders/badge.rb @@ -4,7 +4,6 @@ module Travis::Api::App::Responders 'svg' end - instrument_method def apply set_headers send_file(filename, type: :svg, last_modified: last_modified) diff --git a/lib/travis/api/app/responders/base.rb b/lib/travis/api/app/responders/base.rb index 525779a2..5f463d9c 100644 --- a/lib/travis/api/app/responders/base.rb +++ b/lib/travis/api/app/responders/base.rb @@ -1,6 +1,5 @@ module Travis::Api::App::Responders class Base - include Skylight::Helpers attr_reader :endpoint, :resource, :options def initialize(endpoint, resource, options = {}) diff --git a/lib/travis/api/app/responders/image.rb b/lib/travis/api/app/responders/image.rb index 5ce73814..df126d55 100644 --- a/lib/travis/api/app/responders/image.rb +++ b/lib/travis/api/app/responders/image.rb @@ -10,7 +10,6 @@ module Travis::Api::App::Responders headers['Content-Disposition'] = %(inline; filename="#{File.basename(filename)}") end - instrument_method def apply set_headers send_file(filename, type: :png, last_modified: last_modified) diff --git a/lib/travis/api/app/responders/json.rb b/lib/travis/api/app/responders/json.rb index 441039a9..8d8b0314 100644 --- a/lib/travis/api/app/responders/json.rb +++ b/lib/travis/api/app/responders/json.rb @@ -7,7 +7,6 @@ class Travis::Api::App super && !resource.is_a?(String) && !resource.nil? && accepts_log? end - instrument_method def apply super diff --git a/lib/travis/api/app/responders/plain.rb b/lib/travis/api/app/responders/plain.rb index df27b210..236bfdcf 100644 --- a/lib/travis/api/app/responders/plain.rb +++ b/lib/travis/api/app/responders/plain.rb @@ -13,7 +13,6 @@ module Travis::Api::App::Responders super && (resource.is_a?(Log) || resource.is_a?(String)) end - instrument_method def apply super diff --git a/lib/travis/api/app/responders/service.rb b/lib/travis/api/app/responders/service.rb index 5f6f5655..57942234 100644 --- a/lib/travis/api/app/responders/service.rb +++ b/lib/travis/api/app/responders/service.rb @@ -10,7 +10,6 @@ module Travis::Api resource.respond_to?(:run) end - instrument_method def apply cache_control result = normalize(resource.run) diff --git a/lib/travis/api/app/responders/xml.rb b/lib/travis/api/app/responders/xml.rb index 871dbc22..7db0a964 100644 --- a/lib/travis/api/app/responders/xml.rb +++ b/lib/travis/api/app/responders/xml.rb @@ -37,7 +37,6 @@ module Travis::Api::App::Responders super && @resource.first.is_a?(Repository) end - instrument_method def apply super From de9348a14e0871922cbbadc4fb07b3c9c3422783 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 19:41:37 +0100 Subject: [PATCH 27/29] Revert "Revert "instrument responders"" This reverts commit 01ec5e152a3996d9925d7d3b141f8f555e9f2fa0. --- lib/travis/api/app/responders/atom.rb | 1 + lib/travis/api/app/responders/badge.rb | 1 + lib/travis/api/app/responders/base.rb | 1 + lib/travis/api/app/responders/image.rb | 1 + lib/travis/api/app/responders/json.rb | 1 + lib/travis/api/app/responders/plain.rb | 1 + lib/travis/api/app/responders/service.rb | 1 + lib/travis/api/app/responders/xml.rb | 1 + 8 files changed, 8 insertions(+) diff --git a/lib/travis/api/app/responders/atom.rb b/lib/travis/api/app/responders/atom.rb index 163cf7a3..8bdd3e44 100644 --- a/lib/travis/api/app/responders/atom.rb +++ b/lib/travis/api/app/responders/atom.rb @@ -44,6 +44,7 @@ module Travis::Api::App::Responders super && resource.is_a?(ActiveRecord::Relation) && resource.first.is_a?(Build) end + instrument_method def apply super diff --git a/lib/travis/api/app/responders/badge.rb b/lib/travis/api/app/responders/badge.rb index 6c759b85..ec348228 100644 --- a/lib/travis/api/app/responders/badge.rb +++ b/lib/travis/api/app/responders/badge.rb @@ -4,6 +4,7 @@ module Travis::Api::App::Responders 'svg' end + instrument_method def apply set_headers send_file(filename, type: :svg, last_modified: last_modified) diff --git a/lib/travis/api/app/responders/base.rb b/lib/travis/api/app/responders/base.rb index 5f463d9c..525779a2 100644 --- a/lib/travis/api/app/responders/base.rb +++ b/lib/travis/api/app/responders/base.rb @@ -1,5 +1,6 @@ module Travis::Api::App::Responders class Base + include Skylight::Helpers attr_reader :endpoint, :resource, :options def initialize(endpoint, resource, options = {}) diff --git a/lib/travis/api/app/responders/image.rb b/lib/travis/api/app/responders/image.rb index df126d55..5ce73814 100644 --- a/lib/travis/api/app/responders/image.rb +++ b/lib/travis/api/app/responders/image.rb @@ -10,6 +10,7 @@ module Travis::Api::App::Responders headers['Content-Disposition'] = %(inline; filename="#{File.basename(filename)}") end + instrument_method def apply set_headers send_file(filename, type: :png, last_modified: last_modified) diff --git a/lib/travis/api/app/responders/json.rb b/lib/travis/api/app/responders/json.rb index 8d8b0314..441039a9 100644 --- a/lib/travis/api/app/responders/json.rb +++ b/lib/travis/api/app/responders/json.rb @@ -7,6 +7,7 @@ class Travis::Api::App super && !resource.is_a?(String) && !resource.nil? && accepts_log? end + instrument_method def apply super diff --git a/lib/travis/api/app/responders/plain.rb b/lib/travis/api/app/responders/plain.rb index 236bfdcf..df27b210 100644 --- a/lib/travis/api/app/responders/plain.rb +++ b/lib/travis/api/app/responders/plain.rb @@ -13,6 +13,7 @@ module Travis::Api::App::Responders super && (resource.is_a?(Log) || resource.is_a?(String)) end + instrument_method def apply super diff --git a/lib/travis/api/app/responders/service.rb b/lib/travis/api/app/responders/service.rb index 57942234..5f6f5655 100644 --- a/lib/travis/api/app/responders/service.rb +++ b/lib/travis/api/app/responders/service.rb @@ -10,6 +10,7 @@ module Travis::Api resource.respond_to?(:run) end + instrument_method def apply cache_control result = normalize(resource.run) diff --git a/lib/travis/api/app/responders/xml.rb b/lib/travis/api/app/responders/xml.rb index 7db0a964..871dbc22 100644 --- a/lib/travis/api/app/responders/xml.rb +++ b/lib/travis/api/app/responders/xml.rb @@ -37,6 +37,7 @@ module Travis::Api::App::Responders super && @resource.first.is_a?(Repository) end + instrument_method def apply super From 5c6fe06dfd3ed5862edc7ccba0f72f32fb52b638 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 19:41:47 +0100 Subject: [PATCH 28/29] Revert "Revert "instrument services"" This reverts commit 6681d160c1621587a2f88e40878b805cdad4e48a. --- lib/travis/api/app.rb | 2 +- lib/travis/api/instruments.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 lib/travis/api/instruments.rb diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index 8c0c86f3..e5f18631 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -1,4 +1,3 @@ -require 'skylight' require 'travis' require 'travis/model' require 'travis/support/amqp' @@ -20,6 +19,7 @@ require 'metriks/reporter/logger' require 'metriks/librato_metrics_reporter' require 'travis/support/log_subscriber/active_record_metrics' require 'fileutils' +require 'travis/api/instruments' require 'travis/api/v2/http' require 'travis/api/app/stack_instrumentation' diff --git a/lib/travis/api/instruments.rb b/lib/travis/api/instruments.rb new file mode 100644 index 00000000..a6973f8d --- /dev/null +++ b/lib/travis/api/instruments.rb @@ -0,0 +1,6 @@ +require 'skylight' + +Travis.services.send(:services).each_value do |service| + service.send(:include, Skylight::Helpers) + service.send(:instrument_method, :run) +end \ No newline at end of file From ada71f3eb10d83f5a66253aaa225f413ad3ea7b2 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 20:14:21 +0100 Subject: [PATCH 29/29] do not use path info --- lib/travis/api/app/middleware/skylight/actual.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/travis/api/app/middleware/skylight/actual.rb b/lib/travis/api/app/middleware/skylight/actual.rb index f15ad8ee..8d466b34 100644 --- a/lib/travis/api/app/middleware/skylight/actual.rb +++ b/lib/travis/api/app/middleware/skylight/actual.rb @@ -12,7 +12,7 @@ class Travis::Api::App after do instrumenter = ::Skylight::Instrumenter.instance trace = instrumenter.current_trace if instrumenter - trace.endpoint = "#{request.request_method} #{endpoint || request.path_info}" if trace + trace.endpoint = "#{request.request_method} #{endpoint || '???'}" if trace end def endpoint