only run Skylight for 20% of the dynos (rounding up if there are less than five)
This commit is contained in:
parent
267b7eb257
commit
016afceeff
38
lib/conditional_skylight.rb
Normal file
38
lib/conditional_skylight.rb
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
module ConditionalSkylight
|
||||||
|
module DummyMixin
|
||||||
|
def self.included(object)
|
||||||
|
object.extend(self)
|
||||||
|
super
|
||||||
|
end
|
||||||
|
|
||||||
|
def instrument_method(*)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
extend self
|
||||||
|
|
||||||
|
def enabled?
|
||||||
|
authenticated? and lucky_dyno?
|
||||||
|
end
|
||||||
|
|
||||||
|
def authenticated?
|
||||||
|
ENV['SKYLIGHT_AUTHENTICATION'.freeze]
|
||||||
|
end
|
||||||
|
|
||||||
|
def lucky_dyno?
|
||||||
|
return @lucky_dyno if instance_variable_defined? :@lucky_dyno
|
||||||
|
if ENV['DYNO'.freeze] and ENV['DYNO_COUNT'.freeze]
|
||||||
|
dyno = Integer ENV['DYNO'.freeze][/\d+/]
|
||||||
|
@lucky_dyno = dyno % 5 == 1
|
||||||
|
else
|
||||||
|
@lucky_dyno = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if enabled?
|
||||||
|
require 'skylight'
|
||||||
|
Mixin = Skylight::Helpers
|
||||||
|
else
|
||||||
|
Mixin = DummyMixin
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,3 +1,4 @@
|
||||||
|
require 'conditional_skylight'
|
||||||
require 'travis'
|
require 'travis'
|
||||||
require 'travis/model'
|
require 'travis/model'
|
||||||
require 'travis/support/amqp'
|
require 'travis/support/amqp'
|
||||||
|
|
|
@ -3,7 +3,7 @@ require 'securerandom'
|
||||||
|
|
||||||
class Travis::Api::App
|
class Travis::Api::App
|
||||||
class AccessToken
|
class AccessToken
|
||||||
include Skylight::Helpers
|
include ConditionalSkylight::Mixin
|
||||||
|
|
||||||
DEFAULT_SCOPES = [:public, :private]
|
DEFAULT_SCOPES = [:public, :private]
|
||||||
attr_reader :token, :scopes, :user_id, :app_id, :expires_in, :extra
|
attr_reader :token, :scopes, :user_id, :app_id, :expires_in, :extra
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
if ENV['SKYLIGHT_AUTHENTICATION']
|
require 'conditional_skylight'
|
||||||
|
|
||||||
|
if ConditionalSkylight.enabled?
|
||||||
require_relative 'skylight/actual'
|
require_relative 'skylight/actual'
|
||||||
else
|
else
|
||||||
require_relative 'skylight/dummy'
|
require_relative 'skylight/dummy'
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
module Travis::Api::App::Responders
|
module Travis::Api::App::Responders
|
||||||
class Base
|
class Base
|
||||||
include Skylight::Helpers
|
include ConditionalSkylight::Mixin
|
||||||
attr_reader :endpoint, :resource, :options
|
attr_reader :endpoint, :resource, :options
|
||||||
|
|
||||||
def initialize(endpoint, resource, options = {})
|
def initialize(endpoint, resource, options = {})
|
||||||
|
|
|
@ -18,7 +18,7 @@ class Travis::Api::App
|
||||||
end
|
end
|
||||||
|
|
||||||
def instrument?
|
def instrument?
|
||||||
defined? ::Skylight
|
ConditionalSkylight.enabled?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
require 'skylight'
|
require 'conditional_skylight'
|
||||||
|
|
||||||
Travis.services.send(:services).each_value do |service|
|
if ConditionalSkylight.enabled?
|
||||||
service.send(:include, Skylight::Helpers)
|
Travis.services.send(:services).each_value do |service|
|
||||||
service.send(:instrument_method, :run)
|
service.send(:include, ConditionalSkylight::Mixin)
|
||||||
|
service.send(:instrument_method, :run)
|
||||||
|
end
|
||||||
end
|
end
|
|
@ -17,10 +17,11 @@ Gem::Specification.new do |s|
|
||||||
"Josh Kalderimis",
|
"Josh Kalderimis",
|
||||||
"Henrik Hodne",
|
"Henrik Hodne",
|
||||||
"Andre Arko",
|
"Andre Arko",
|
||||||
"Erik Michaels-Ober",
|
|
||||||
"Dan Buch",
|
"Dan Buch",
|
||||||
|
"Erik Michaels-Ober",
|
||||||
"Steve Richert",
|
"Steve Richert",
|
||||||
"Brian Ford",
|
"Brian Ford",
|
||||||
|
"Patrick Williams",
|
||||||
"Bryan Goldstein",
|
"Bryan Goldstein",
|
||||||
"Puneeth Chaganti",
|
"Puneeth Chaganti",
|
||||||
"Thais Camilo and Konstantin Haase",
|
"Thais Camilo and Konstantin Haase",
|
||||||
|
@ -29,8 +30,7 @@ Gem::Specification.new do |s|
|
||||||
"James Dennes",
|
"James Dennes",
|
||||||
"rainsun",
|
"rainsun",
|
||||||
"Dan Rice",
|
"Dan Rice",
|
||||||
"Nick Schonning",
|
"Nick Schonning"
|
||||||
"Patrick Williams"
|
|
||||||
]
|
]
|
||||||
|
|
||||||
s.email = [
|
s.email = [
|
||||||
|
@ -45,21 +45,22 @@ Gem::Specification.new do |s|
|
||||||
"konstantin.haase@gmail.com",
|
"konstantin.haase@gmail.com",
|
||||||
"andre@arko.net",
|
"andre@arko.net",
|
||||||
"svenfuchs@artweb-design.de",
|
"svenfuchs@artweb-design.de",
|
||||||
"sferik@gmail.com",
|
|
||||||
"dan@travis-ci.org",
|
"dan@travis-ci.org",
|
||||||
|
"sferik@gmail.com",
|
||||||
"steve.richert@gmail.com",
|
"steve.richert@gmail.com",
|
||||||
"bford@engineyard.com",
|
"bford@engineyard.com",
|
||||||
"henrik@travis-ci.com",
|
"henrik@travis-ci.com",
|
||||||
"punchagan@muse-amuse.in",
|
"brysgo@gmail.com",
|
||||||
|
"jdennes@gmail.com",
|
||||||
"rainsuner@gmail.com",
|
"rainsuner@gmail.com",
|
||||||
"dev+narwen+rkh@rkh.im",
|
"dev+narwen+rkh@rkh.im",
|
||||||
"tim@spork.in",
|
"tim@spork.in",
|
||||||
"e@zzak.io",
|
"e@zzak.io",
|
||||||
"jdennes@gmail.com",
|
"punchagan@muse-amuse.in",
|
||||||
"dan@zoombody.com",
|
"dan@zoombody.com",
|
||||||
|
"dan@meatballhat.com",
|
||||||
"nschonni@gmail.com",
|
"nschonni@gmail.com",
|
||||||
"patrick@bittorrent.com",
|
"patrick@bittorrent.com"
|
||||||
"brysgo@gmail.com"
|
|
||||||
]
|
]
|
||||||
|
|
||||||
s.files = [
|
s.files = [
|
||||||
|
@ -116,6 +117,9 @@ Gem::Specification.new do |s|
|
||||||
"lib/travis/api/app/middleware/metriks.rb",
|
"lib/travis/api/app/middleware/metriks.rb",
|
||||||
"lib/travis/api/app/middleware/rewrite.rb",
|
"lib/travis/api/app/middleware/rewrite.rb",
|
||||||
"lib/travis/api/app/middleware/scope_check.rb",
|
"lib/travis/api/app/middleware/scope_check.rb",
|
||||||
|
"lib/travis/api/app/middleware/skylight.rb",
|
||||||
|
"lib/travis/api/app/middleware/skylight/actual.rb",
|
||||||
|
"lib/travis/api/app/middleware/skylight/dummy.rb",
|
||||||
"lib/travis/api/app/middleware/user_agent_tracker.rb",
|
"lib/travis/api/app/middleware/user_agent_tracker.rb",
|
||||||
"lib/travis/api/app/responders.rb",
|
"lib/travis/api/app/responders.rb",
|
||||||
"lib/travis/api/app/responders/atom.rb",
|
"lib/travis/api/app/responders/atom.rb",
|
||||||
|
@ -127,6 +131,8 @@ Gem::Specification.new do |s|
|
||||||
"lib/travis/api/app/responders/service.rb",
|
"lib/travis/api/app/responders/service.rb",
|
||||||
"lib/travis/api/app/responders/xml.rb",
|
"lib/travis/api/app/responders/xml.rb",
|
||||||
"lib/travis/api/app/services/schedule_request.rb",
|
"lib/travis/api/app/services/schedule_request.rb",
|
||||||
|
"lib/travis/api/app/stack_instrumentation.rb",
|
||||||
|
"lib/travis/api/instruments.rb",
|
||||||
"lib/travis/api/serializer.rb",
|
"lib/travis/api/serializer.rb",
|
||||||
"lib/travis/api/v2.rb",
|
"lib/travis/api/v2.rb",
|
||||||
"lib/travis/api/v2/http.rb",
|
"lib/travis/api/v2/http.rb",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user