diff --git a/Gemfile b/Gemfile index 58bc4852..b3237c2e 100644 --- a/Gemfile +++ b/Gemfile @@ -21,6 +21,8 @@ gem 'dalli' gem 'pry' gem 'metriks', '0.9.9.5' +gem 'skylight', github: 'henrikhodne/skylight-ruby', branch: 'sinatra-support' + group :test do gem 'rspec', '~> 2.13' gem 'factory_girl', '~> 2.4.0' diff --git a/Gemfile.lock b/Gemfile.lock index 3dfced19..9668f4bb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,6 +7,14 @@ GIT hashie (>= 1.1.0) uuidtools +GIT + remote: git://github.com/henrikhodne/skylight-ruby.git + revision: 44904fe824e202deb6389fb9b547bd4345abdc2d + branch: sinatra-support + specs: + skylight (0.3.10) + activesupport (>= 3.0.0) + GIT remote: git://github.com/rack/rack-contrib.git revision: 951760b1710634623ebbccef8d65df9139bb41c2 @@ -53,7 +61,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-support.git - revision: d2cce5dbbee64fb1574386b16da3768feadb372a + revision: d37220d766a3fb218f0f8e60ab8764034f6b376f specs: travis-support (0.0.1) @@ -69,7 +77,6 @@ PATH travis-api (0.0.1) backports (~> 2.5) memcachier - newrelic_rpm (~> 3.6.6) pg (~> 0.13.2) rack-contrib (~> 1.1) rack-ssl (~> 1.3, >= 1.3.3) @@ -175,7 +182,6 @@ GEM multipart-post (2.0.0) net-http-persistent (2.9.4) net-http-pipeline (1.0.1) - newrelic_rpm (3.6.9.171) pg (0.13.2) polyglot (0.3.4) proxies (0.2.1) @@ -299,6 +305,7 @@ DEPENDENCIES sentry-raven! sinatra sinatra-contrib + skylight! travis-api! travis-core! travis-sidekiqs! diff --git a/config/newrelic.yml b/config/newrelic.yml deleted file mode 100644 index d1ab9cd0..00000000 --- a/config/newrelic.yml +++ /dev/null @@ -1,39 +0,0 @@ ---- -staging: - error_collector: - capture_source: true - enabled: true - ignore_errors: ActionController::RoutingError - apdex_t: 0.5 - ssl: false - monitor_mode: true - license_key: <%= ENV["NEW_RELIC_LICENSE_KEY"] %> - developer_mode: false - app_name: <%= ENV["NEW_RELIC_APP_NAME"] %> - transaction_tracer: - record_sql: obfuscated - enabled: true - stack_trace_threshold: 0.5 - transaction_threshold: apdex_f - capture_params: false - log_level: info - -production: - error_collector: - capture_source: true - enabled: true - ignore_errors: ActionController::RoutingError - apdex_t: 0.5 - ssl: false - monitor_mode: true - license_key: <%= ENV["NEW_RELIC_LICENSE_KEY"] %> - developer_mode: false - app_name: <%= ENV["NEW_RELIC_APP_NAME"] %> - transaction_tracer: - record_sql: obfuscated - enabled: true - stack_trace_threshold: 0.5 - transaction_threshold: apdex_f - capture_params: false - log_level: info - diff --git a/lib/travis/api/app/base.rb b/lib/travis/api/app/base.rb index 082be3ea..93ecab1a 100644 --- a/lib/travis/api/app/base.rb +++ b/lib/travis/api/app/base.rb @@ -7,10 +7,12 @@ class Travis::Api::App class Base < Sinatra::Base register Extensions::SmartConstants - configure :production do - require 'newrelic_rpm' - ::NewRelic::Agent.manual_start() - ::NewRelic::Agent.after_fork(:force_reconnect => true) + if ENV['SKYLIGHT_APPLICATION'] + require 'skylight' + require 'travis/api/app/skylight/dalli_probe' + require 'travis/api/app/skylight/redis_probe' + require 'travis/api/app/skylight/service_probe' + register ::Skylight::Sinatra end error NotImplementedError do diff --git a/lib/travis/api/app/skylight/dalli_probe.rb b/lib/travis/api/app/skylight/dalli_probe.rb new file mode 100644 index 00000000..8a63cc95 --- /dev/null +++ b/lib/travis/api/app/skylight/dalli_probe.rb @@ -0,0 +1,24 @@ +require 'skylight' +require 'travis/api/app' + +class Travis::Api::App + module Skylight + class DalliProbe + def install + %w[get get_multi set add incr decr delete replace append prepend].each do |method_name| + next unless Dalli::Client.method_defined?(method_name.to_sym) + Dalli::Client.class_eval <<-EOD + alias #{method_name}_without_sk #{method_name} + def #{method_name}(*args, &block) + ::Skylight.instrument(category: "api.memcache.#{method_name}", title: "Memcache #{method_name}") do + #{method_name}_without_sk(*args, &block) + end + end + EOD + end + end + end + + ::Skylight::Probes.register("Dalli::Client", "dalli", DalliProbe.new) + end +end diff --git a/lib/travis/api/app/skylight/redis_probe.rb b/lib/travis/api/app/skylight/redis_probe.rb new file mode 100644 index 00000000..491e6886 --- /dev/null +++ b/lib/travis/api/app/skylight/redis_probe.rb @@ -0,0 +1,31 @@ +require 'skylight' +require 'travis/api/app' + +class Travis::Api::App + module Skylight + class RedisProbe + def install + ::Redis::Client.class_eval do + alias call_without_sk call + + def call(command_parts, &block) + command = command_parts[0].upcase + + opts = { + category: "api.redis.#{command.downcase}", + title: "Redis #{command}", + annotations: { + command: command.to_s + } + } + + ::Skylight.instrument(opts) do + call_without_sk(command_parts, &block) + end + end + end + end + end + ::Skylight::Probes.register("Redis", "redis", RedisProbe.new) + end +end diff --git a/lib/travis/api/app/skylight/service_probe.rb b/lib/travis/api/app/skylight/service_probe.rb new file mode 100644 index 00000000..b71dc661 --- /dev/null +++ b/lib/travis/api/app/skylight/service_probe.rb @@ -0,0 +1,51 @@ +require 'skylight' +require 'travis/api/app' + +class Travis::Api::App + module Skylight + class ServiceProbe + class ServiceProxy < Delegator + def initialize(key, service) + super(service) + @key = key + @service = service + end + + def __getobj__ + @service + end + + def __setobj__(obj) + @service = obj + end + + def run(*args) + opts = { + category: "api.service.#{@key}", + title: "Service #{@key}", + annotations: { + service: @key.to_s + } + } + + ::Skylight.instrument(opts) do + @service.run(*args) + end + end + end + + def install + Travis::Services::Helpers.class_eval do + alias service_without_sk service + + def service(key, *args) + s = service_without_sk(key, *args) + ServiceProxy.new(key, s) + end + end + end + end + + ::Skylight::Probes.register("Travis::Services::Helpers", "travis/services/helpers", ServiceProbe.new) + end +end diff --git a/script/console b/script/console index 3d9291dd..fd1fd99c 100755 --- a/script/console +++ b/script/console @@ -1,8 +1,6 @@ #!/usr/bin/env ruby # encoding: UTF-8 -ENV["NEWRELIC_ENABLE"] = "false" - require 'bundler/setup' require 'travis/api/app' require 'pry' diff --git a/tmp/.gitkeep b/tmp/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/travis-api.gemspec b/travis-api.gemspec index 58460613..43570731 100644 --- a/travis-api.gemspec +++ b/travis-api.gemspec @@ -55,7 +55,6 @@ Gem::Specification.new do |s| "bin/start-nginx", "config.ru", "config/database.yml", - "config/newrelic.yml", "config/nginx.conf.erb", "config/puma-config.rb", "config/unicorn.rb", @@ -174,7 +173,6 @@ Gem::Specification.new do |s| s.add_dependency 'backports', '~> 2.5' s.add_dependency 'pg', '~> 0.13.2' - s.add_dependency 'newrelic_rpm', '~> 3.6.6' s.add_dependency 'thin', '~> 1.4' s.add_dependency 'sinatra', '~> 1.3' s.add_dependency 'sinatra-contrib', '~> 1.3'