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/model'
|
||||
require 'travis/support/amqp'
|
||||
|
|
|
@ -3,7 +3,7 @@ require 'securerandom'
|
|||
|
||||
class Travis::Api::App
|
||||
class AccessToken
|
||||
include Skylight::Helpers
|
||||
include ConditionalSkylight::Mixin
|
||||
|
||||
DEFAULT_SCOPES = [:public, :private]
|
||||
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'
|
||||
else
|
||||
require_relative 'skylight/dummy'
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
module Travis::Api::App::Responders
|
||||
class Base
|
||||
include Skylight::Helpers
|
||||
include ConditionalSkylight::Mixin
|
||||
attr_reader :endpoint, :resource, :options
|
||||
|
||||
def initialize(endpoint, resource, options = {})
|
||||
|
|
|
@ -18,7 +18,7 @@ class Travis::Api::App
|
|||
end
|
||||
|
||||
def instrument?
|
||||
defined? ::Skylight
|
||||
ConditionalSkylight.enabled?
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
require 'skylight'
|
||||
require 'conditional_skylight'
|
||||
|
||||
Travis.services.send(:services).each_value do |service|
|
||||
service.send(:include, Skylight::Helpers)
|
||||
service.send(:instrument_method, :run)
|
||||
if ConditionalSkylight.enabled?
|
||||
Travis.services.send(:services).each_value do |service|
|
||||
service.send(:include, ConditionalSkylight::Mixin)
|
||||
service.send(:instrument_method, :run)
|
||||
end
|
||||
end
|
|
@ -17,10 +17,11 @@ Gem::Specification.new do |s|
|
|||
"Josh Kalderimis",
|
||||
"Henrik Hodne",
|
||||
"Andre Arko",
|
||||
"Erik Michaels-Ober",
|
||||
"Dan Buch",
|
||||
"Erik Michaels-Ober",
|
||||
"Steve Richert",
|
||||
"Brian Ford",
|
||||
"Patrick Williams",
|
||||
"Bryan Goldstein",
|
||||
"Puneeth Chaganti",
|
||||
"Thais Camilo and Konstantin Haase",
|
||||
|
@ -29,8 +30,7 @@ Gem::Specification.new do |s|
|
|||
"James Dennes",
|
||||
"rainsun",
|
||||
"Dan Rice",
|
||||
"Nick Schonning",
|
||||
"Patrick Williams"
|
||||
"Nick Schonning"
|
||||
]
|
||||
|
||||
s.email = [
|
||||
|
@ -45,21 +45,22 @@ Gem::Specification.new do |s|
|
|||
"konstantin.haase@gmail.com",
|
||||
"andre@arko.net",
|
||||
"svenfuchs@artweb-design.de",
|
||||
"sferik@gmail.com",
|
||||
"dan@travis-ci.org",
|
||||
"sferik@gmail.com",
|
||||
"steve.richert@gmail.com",
|
||||
"bford@engineyard.com",
|
||||
"henrik@travis-ci.com",
|
||||
"punchagan@muse-amuse.in",
|
||||
"brysgo@gmail.com",
|
||||
"jdennes@gmail.com",
|
||||
"rainsuner@gmail.com",
|
||||
"dev+narwen+rkh@rkh.im",
|
||||
"tim@spork.in",
|
||||
"e@zzak.io",
|
||||
"jdennes@gmail.com",
|
||||
"punchagan@muse-amuse.in",
|
||||
"dan@zoombody.com",
|
||||
"dan@meatballhat.com",
|
||||
"nschonni@gmail.com",
|
||||
"patrick@bittorrent.com",
|
||||
"brysgo@gmail.com"
|
||||
"patrick@bittorrent.com"
|
||||
]
|
||||
|
||||
s.files = [
|
||||
|
@ -116,6 +117,9 @@ Gem::Specification.new do |s|
|
|||
"lib/travis/api/app/middleware/metriks.rb",
|
||||
"lib/travis/api/app/middleware/rewrite.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/responders.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/xml.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/v2.rb",
|
||||
"lib/travis/api/v2/http.rb",
|
||||
|
|
Loading…
Reference in New Issue
Block a user