add conditional skylight tracking
This commit is contained in:
parent
371d67f900
commit
396a0f756c
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,3 +2,4 @@ config/travis.yml
|
||||||
.yardoc
|
.yardoc
|
||||||
log/
|
log/
|
||||||
vendor
|
vendor
|
||||||
|
config/skylight.yml
|
||||||
|
|
1
Gemfile
1
Gemfile
|
@ -27,6 +27,7 @@ gem 'pry'
|
||||||
gem 'metriks', '0.9.9.6'
|
gem 'metriks', '0.9.9.6'
|
||||||
gem 'metriks-librato_metrics', github: 'eric/metriks-librato_metrics'
|
gem 'metriks-librato_metrics', github: 'eric/metriks-librato_metrics'
|
||||||
gem 'micro_migrations'
|
gem 'micro_migrations'
|
||||||
|
gem 'skylight', '~> 0.6.0.beta.1'
|
||||||
|
|
||||||
group :test do
|
group :test do
|
||||||
gem 'rspec', '~> 2.13'
|
gem 'rspec', '~> 2.13'
|
||||||
|
|
|
@ -81,7 +81,7 @@ GIT
|
||||||
|
|
||||||
GIT
|
GIT
|
||||||
remote: git://github.com/travis-ci/travis-yaml.git
|
remote: git://github.com/travis-ci/travis-yaml.git
|
||||||
revision: f3aa306016a08b66a487f966eb8aa3a60ee9b319
|
revision: 1630d576d221aea2340615e87f402df7889b5176
|
||||||
specs:
|
specs:
|
||||||
travis-yaml (0.2.0)
|
travis-yaml (0.2.0)
|
||||||
|
|
||||||
|
@ -302,6 +302,8 @@ GEM
|
||||||
rack-test
|
rack-test
|
||||||
sinatra (~> 1.4.0)
|
sinatra (~> 1.4.0)
|
||||||
tilt (~> 1.3)
|
tilt (~> 1.3)
|
||||||
|
skylight (0.6.0.beta.1)
|
||||||
|
activesupport (>= 3.0.0)
|
||||||
slop (3.6.0)
|
slop (3.6.0)
|
||||||
sprockets (2.2.3)
|
sprockets (2.2.3)
|
||||||
hike (~> 1.2)
|
hike (~> 1.2)
|
||||||
|
@ -367,6 +369,7 @@ DEPENDENCIES
|
||||||
sentry-raven!
|
sentry-raven!
|
||||||
sinatra
|
sinatra
|
||||||
sinatra-contrib
|
sinatra-contrib
|
||||||
|
skylight (~> 0.6.0.beta.1)
|
||||||
travis-api!
|
travis-api!
|
||||||
travis-config (~> 0.1.0)
|
travis-config (~> 0.1.0)
|
||||||
travis-core!
|
travis-core!
|
||||||
|
|
|
@ -20,6 +20,7 @@ require 'metriks/librato_metrics_reporter'
|
||||||
require 'travis/support/log_subscriber/active_record_metrics'
|
require 'travis/support/log_subscriber/active_record_metrics'
|
||||||
require 'fileutils'
|
require 'fileutils'
|
||||||
require 'travis/api/v2/http'
|
require 'travis/api/v2/http'
|
||||||
|
require 'travis/api/conditional_skylight'
|
||||||
|
|
||||||
# Rack class implementing the HTTP API.
|
# Rack class implementing the HTTP API.
|
||||||
# Instances respond to #call.
|
# Instances respond to #call.
|
||||||
|
|
50
lib/travis/api/conditional_skylight.rb
Normal file
50
lib/travis/api/conditional_skylight.rb
Normal file
|
@ -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
|
Loading…
Reference in New Issue
Block a user