Merge pull request #119 from travis-ci/hh-skylight

Skylight
This commit is contained in:
Henrik Hodne 2014-04-09 18:08:48 -05:00
commit 26064f95a1
10 changed files with 124 additions and 50 deletions

View File

@ -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'

View File

@ -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!

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -1,8 +1,6 @@
#!/usr/bin/env ruby
# encoding: UTF-8
ENV["NEWRELIC_ENABLE"] = "false"
require 'bundler/setup'
require 'travis/api/app'
require 'pry'

0
tmp/.gitkeep Normal file
View File

View File

@ -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'