From bd9714dca9cad508bf9a8c49adededb03b2465eb Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Fri, 19 Dec 2014 09:23:54 +0100 Subject: [PATCH 01/43] Use s3 gem from our fork --- Gemfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Gemfile b/Gemfile index d92fda3e..43d10a2b 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,8 @@ source 'https://rubygems.org' gemspec +gem 's3', github: 'travis-ci/s3' + gem 'travis-core', github: 'travis-ci/travis-core' gem 'travis-support', github: 'travis-ci/travis-support' gem 'travis-config', '~> 0.1.0' From 43e20332cf8026a60d3d01d8baa451d5fc9cbfe6 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Fri, 9 Jan 2015 13:05:31 +0100 Subject: [PATCH 02/43] Return removed_at and removed_by if the log was removed --- Gemfile.lock | 10 ++++++++-- lib/travis/api/app/endpoint/jobs.rb | 4 +++- lib/travis/api/app/responders/json.rb | 9 +++++++-- lib/travis/api/v2/http.rb | 1 + lib/travis/api/v2/http/removed_log.rb | 20 ++++++++++++++++++++ spec/integration/v2/jobs_spec.rb | 12 ++++++++++++ 6 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 lib/travis/api/v2/http/removed_log.rb diff --git a/Gemfile.lock b/Gemfile.lock index 72c9eb88..7a96c14a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -34,6 +34,13 @@ GIT rack-cache (1.2) rack (>= 0.4) +GIT + remote: git://github.com/travis-ci/s3.git + revision: 386361c1b0ede19cde0ddaf86e41a16308575f5d + specs: + s3 (0.3.21) + proxies (~> 0.2.0) + GIT remote: git://github.com/travis-ci/travis-core.git revision: 8fa9680a47ab457187ddf3a88461a756a6f4c2a6 @@ -270,8 +277,6 @@ GEM rspec-expectations (2.99.2) diff-lcs (>= 1.1.3, < 2.0) rspec-mocks (2.99.2) - s3 (0.3.21) - proxies (~> 0.2.0) sass (3.4.6) sidekiq (2.5.0) celluloid (~> 0.12.0) @@ -358,6 +363,7 @@ DEPENDENCIES rb-fsevent (~> 0.9.1) rerun rspec (~> 2.13) + s3! sentry-raven! sinatra sinatra-contrib diff --git a/lib/travis/api/app/endpoint/jobs.rb b/lib/travis/api/app/endpoint/jobs.rb index 9a70becf..f14a4d5c 100644 --- a/lib/travis/api/app/endpoint/jobs.rb +++ b/lib/travis/api/app/endpoint/jobs.rb @@ -58,7 +58,9 @@ class Travis::Api::App get '/:job_id/log' do resource = service(:find_log, params).run - if (!resource || resource.archived?) + if (resource && resource.removed_at) && accepts?('application/json') + respond_with resource, type: 'removed_log', root: 'log' + elsif (!resource || resource.archived?) # the way we use responders makes it hard to validate proper format # automatically here, so we need to check it explicitly if accepts?('text/plain') diff --git a/lib/travis/api/app/responders/json.rb b/lib/travis/api/app/responders/json.rb index 3bc3bb8d..8d8b0314 100644 --- a/lib/travis/api/app/responders/json.rb +++ b/lib/travis/api/app/responders/json.rb @@ -23,13 +23,18 @@ class Travis::Api::App return true unless resource.is_a?(Log) chunked = accept_params[:chunked] - chunked ? !resource.aggregated_at : true + if resource.removed_at + true + else + chunked ? !resource.aggregated_at : true + end end def result if builder p = params - p[:root] = options[:type] if options[:type] + p[:root] = options[:root] if options[:root] + p[:root] = options[:type] if options[:type] && !p[:root] builder.new(resource, p).data else basic_type_resource diff --git a/lib/travis/api/v2/http.rb b/lib/travis/api/v2/http.rb index a733b364..2e5427aa 100644 --- a/lib/travis/api/v2/http.rb +++ b/lib/travis/api/v2/http.rb @@ -16,6 +16,7 @@ module Travis require 'travis/api/v2/http/job' require 'travis/api/v2/http/jobs' require 'travis/api/v2/http/log' + require 'travis/api/v2/http/removed_log' require 'travis/api/v2/http/permissions' require 'travis/api/v2/http/repositories' require 'travis/api/v2/http/repository' diff --git a/lib/travis/api/v2/http/removed_log.rb b/lib/travis/api/v2/http/removed_log.rb new file mode 100644 index 00000000..11fa032a --- /dev/null +++ b/lib/travis/api/v2/http/removed_log.rb @@ -0,0 +1,20 @@ +module Travis + module Api + module V2 + module Http + class RemovedLog < Travis::Api::Serializer + attributes :id, :job_id, :body, :removed_at, :removed_by + + def body + object.content + end + + def removed_by + object.removed_by.name || object.removed_by.login if object.removed_by + end + + end + end + end + end +end diff --git a/spec/integration/v2/jobs_spec.rb b/spec/integration/v2/jobs_spec.rb index 1183d619..55cc3ba6 100644 --- a/spec/integration/v2/jobs_spec.rb +++ b/spec/integration/v2/jobs_spec.rb @@ -103,6 +103,18 @@ describe 'Jobs' do response.should deliver_json_for(job.log, version: 'v2') end end + + it 'adds removed info if the log is removed' do + time = Time.new(2015, 1, 9, 12, 57, 31) + job.log.update_attributes(removed_at: time, removed_by: User.first) + headers = { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.2+json' } + response = get "/jobs/#{job.id}/log", {}, headers + body = JSON.parse(response.body) + + body['log']['removed_by'].should == 'Sven Fuchs' + body['log']['removed_at'].should == "2015-01-09T11:57:31Z" + body['log']['id'].should == job.log.id + end end describe 'PATCH /jobs/:job_id/log' do From 6846d2f78305155b0b024461856b5cebda0976f8 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Fri, 9 Jan 2015 14:39:57 +0100 Subject: [PATCH 03/43] Return log with chunks if chunked response is requested for removed log --- lib/travis/api/app/endpoint/jobs.rb | 2 +- lib/travis/api/v2/http.rb | 1 - lib/travis/api/v2/http/log.rb | 33 ++++++++++++++++++--------- lib/travis/api/v2/http/removed_log.rb | 20 ---------------- spec/integration/v2/jobs_spec.rb | 5 +++- 5 files changed, 27 insertions(+), 34 deletions(-) delete mode 100644 lib/travis/api/v2/http/removed_log.rb diff --git a/lib/travis/api/app/endpoint/jobs.rb b/lib/travis/api/app/endpoint/jobs.rb index f14a4d5c..0d65e78e 100644 --- a/lib/travis/api/app/endpoint/jobs.rb +++ b/lib/travis/api/app/endpoint/jobs.rb @@ -59,7 +59,7 @@ class Travis::Api::App get '/:job_id/log' do resource = service(:find_log, params).run if (resource && resource.removed_at) && accepts?('application/json') - respond_with resource, type: 'removed_log', root: 'log' + respond_with resource elsif (!resource || resource.archived?) # the way we use responders makes it hard to validate proper format # automatically here, so we need to check it explicitly diff --git a/lib/travis/api/v2/http.rb b/lib/travis/api/v2/http.rb index 2e5427aa..a733b364 100644 --- a/lib/travis/api/v2/http.rb +++ b/lib/travis/api/v2/http.rb @@ -16,7 +16,6 @@ module Travis require 'travis/api/v2/http/job' require 'travis/api/v2/http/jobs' require 'travis/api/v2/http/log' - require 'travis/api/v2/http/removed_log' require 'travis/api/v2/http/permissions' require 'travis/api/v2/http/repositories' require 'travis/api/v2/http/repository' diff --git a/lib/travis/api/v2/http/log.rb b/lib/travis/api/v2/http/log.rb index 38af5417..96cb408a 100644 --- a/lib/travis/api/v2/http/log.rb +++ b/lib/travis/api/v2/http/log.rb @@ -11,8 +11,14 @@ module Travis end def data + log_hash = options[:chunked] ? chunked_log_data : log_data + if log.removed_at + log_hash['removed_at'] = log.removed_at + log_hash['removed_by'] = log.removed_by.name || object.removed_by.login + end + { - 'log' => options[:chunked] ? chunked_log_data : log_data, + 'log' => log_hash, } end @@ -37,16 +43,21 @@ module Travis end def log_parts - parts = log.parts - parts = parts.where(number: part_numbers) if part_numbers - parts = parts.where(["number > ?", after]) if after - parts.sort_by(&:number).map do |part| - { - 'id' => part.id, - 'number' => part.number, - 'content' => part.content, - 'final' => part.final - } + if log.removed_at + # if log is removed we don't have actual parts + parts = [{ 'number' => 1, 'content' => log.content, 'final' => true }] + else + parts = log.parts + parts = parts.where(number: part_numbers) if part_numbers + parts = parts.where(["number > ?", after]) if after + parts.sort_by(&:number).map do |part| + { + 'id' => part.id, + 'number' => part.number, + 'content' => part.content, + 'final' => part.final + } + end end end diff --git a/lib/travis/api/v2/http/removed_log.rb b/lib/travis/api/v2/http/removed_log.rb deleted file mode 100644 index 11fa032a..00000000 --- a/lib/travis/api/v2/http/removed_log.rb +++ /dev/null @@ -1,20 +0,0 @@ -module Travis - module Api - module V2 - module Http - class RemovedLog < Travis::Api::Serializer - attributes :id, :job_id, :body, :removed_at, :removed_by - - def body - object.content - end - - def removed_by - object.removed_by.name || object.removed_by.login if object.removed_by - end - - end - end - end - end -end diff --git a/spec/integration/v2/jobs_spec.rb b/spec/integration/v2/jobs_spec.rb index 55cc3ba6..128a2a72 100644 --- a/spec/integration/v2/jobs_spec.rb +++ b/spec/integration/v2/jobs_spec.rb @@ -107,13 +107,16 @@ describe 'Jobs' do it 'adds removed info if the log is removed' do time = Time.new(2015, 1, 9, 12, 57, 31) job.log.update_attributes(removed_at: time, removed_by: User.first) - headers = { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.2+json' } + headers = { 'HTTP_ACCEPT' => 'application/json; chunked=true; version=2' } response = get "/jobs/#{job.id}/log", {}, headers body = JSON.parse(response.body) body['log']['removed_by'].should == 'Sven Fuchs' body['log']['removed_at'].should == "2015-01-09T11:57:31Z" body['log']['id'].should == job.log.id + + # make sure we return parts as chunked=true + body['log']['parts'].length.should == 1 end end From 0fdd25725af5f5f4a55af749ea5f98f581793d8f Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Mon, 12 Jan 2015 12:41:37 +0100 Subject: [PATCH 04/43] Bump travis-core --- Gemfile.lock | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 7a96c14a..ec2550c4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -43,7 +43,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: 8fa9680a47ab457187ddf3a88461a756a6f4c2a6 + revision: 0d88007ac35ab7aeb44fb59e95a8873b0a5b69bf specs: travis-core (0.0.1) actionmailer (~> 3.2.19) @@ -106,12 +106,12 @@ PATH GEM remote: https://rubygems.org/ specs: - actionmailer (3.2.19) - actionpack (= 3.2.19) + actionmailer (3.2.21) + actionpack (= 3.2.21) mail (~> 2.5.4) - actionpack (3.2.19) - activemodel (= 3.2.19) - activesupport (= 3.2.19) + actionpack (3.2.21) + activemodel (= 3.2.21) + activesupport (= 3.2.21) builder (~> 3.0.0) erubis (~> 2.7.0) journey (~> 1.0.4) @@ -121,15 +121,15 @@ GEM sprockets (~> 2.2.1) active_model_serializers (0.9.0) activemodel (>= 3.2) - activemodel (3.2.19) - activesupport (= 3.2.19) + activemodel (3.2.21) + activesupport (= 3.2.21) builder (~> 3.0.0) - activerecord (3.2.19) - activemodel (= 3.2.19) - activesupport (= 3.2.19) + activerecord (3.2.21) + activemodel (= 3.2.21) + activesupport (= 3.2.21) arel (~> 3.0.2) tzinfo (~> 0.3.29) - activesupport (3.2.19) + activesupport (3.2.21) i18n (~> 0.6, >= 0.6.4) multi_json (~> 1.0) addressable (2.3.6) @@ -178,7 +178,7 @@ GEM eventmachine (1.0.3) factory_girl (2.4.2) activesupport - faraday (0.9.0) + faraday (0.9.1) multipart-post (>= 1.2, < 3) ffi (1.9.6) foreman (0.64.0) @@ -195,10 +195,10 @@ GEM hike (1.2.3) hitimes (1.2.2) httpclient (2.3.4.1) - i18n (0.6.11) - ice_nine (0.11.0) + i18n (0.7.0) + ice_nine (0.11.1) journey (1.0.4) - json (1.8.1) + json (1.8.2) kgio (2.9.2) listen (1.0.3) rb-fsevent (>= 0.9.3) @@ -244,11 +244,11 @@ GEM rack rack-ssl (1.3.4) rack - rack-test (0.6.2) + rack-test (0.6.3) rack (>= 1.0) - railties (3.2.19) - actionpack (= 3.2.19) - activesupport (= 3.2.19) + railties (3.2.21) + actionpack (= 3.2.21) + activesupport (= 3.2.21) rack-ssl (~> 1.3.2) rake (>= 0.8.7) rdoc (~> 3.4) @@ -263,7 +263,7 @@ GEM rdoc (3.12.2) json (~> 1.4) redcarpet (2.3.0) - redis (3.1.0) + redis (3.2.0) redis-namespace (1.5.1) redis (~> 3.0, >= 3.0.4) rerun (0.8.2) @@ -303,7 +303,7 @@ GEM sinatra (~> 1.4.0) tilt (~> 1.3) slop (3.6.0) - sprockets (2.2.2) + sprockets (2.2.3) hike (~> 1.2) multi_json (~> 1.0) rack (~> 1.0) @@ -333,7 +333,7 @@ GEM raindrops (~> 0.7) useragent (0.10.0) uuidtools (2.1.5) - virtus (1.0.3) + virtus (1.0.4) axiom-types (~> 0.1) coercible (~> 1.0) descendants_tracker (~> 0.0, >= 0.0.3) From 5ca8b29f5aba36fd7fc737fda22063b940d5a1ae Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Mon, 12 Jan 2015 12:49:23 +0100 Subject: [PATCH 05/43] Fix specs --- spec/unit/api/v2/http/log_spec.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spec/unit/api/v2/http/log_spec.rb b/spec/unit/api/v2/http/log_spec.rb index 3907b774..6a9c3064 100644 --- a/spec/unit/api/v2/http/log_spec.rb +++ b/spec/unit/api/v2/http/log_spec.rb @@ -3,6 +3,9 @@ require 'spec_helper' describe Travis::Api::V2::Http::Log do include Travis::Testing::Stubs + let(:log) { + stub_log(removed_at: false) + } let(:data) { described_class.new(log).data } it 'log' do @@ -19,7 +22,7 @@ describe Travis::Api::V2::Http::Log do stub_log(parts: [ stub_log_part(id: 2, number: 2, content: 'bar', final: true), stub_log_part(id: 1, number: 1, content: 'foo') - ]) + ], removed_at: false) end let(:data) { described_class.new(log, chunked: true).data } From 302927bad66b349cc81ec12e17e4a208c1a795f7 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Mon, 12 Jan 2015 12:56:04 +0100 Subject: [PATCH 06/43] removed_at in tests should be in utc --- spec/integration/v2/jobs_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/integration/v2/jobs_spec.rb b/spec/integration/v2/jobs_spec.rb index 128a2a72..bbaabefd 100644 --- a/spec/integration/v2/jobs_spec.rb +++ b/spec/integration/v2/jobs_spec.rb @@ -105,7 +105,7 @@ describe 'Jobs' do end it 'adds removed info if the log is removed' do - time = Time.new(2015, 1, 9, 12, 57, 31) + time = Time.new(2015, 1, 9, 12, 57, 31).utc job.log.update_attributes(removed_at: time, removed_by: User.first) headers = { 'HTTP_ACCEPT' => 'application/json; chunked=true; version=2' } response = get "/jobs/#{job.id}/log", {}, headers From 628b356964027c0950682fc474bba59f30a67487 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Mon, 12 Jan 2015 13:00:07 +0100 Subject: [PATCH 07/43] I can't into timezones --- spec/integration/v2/jobs_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/integration/v2/jobs_spec.rb b/spec/integration/v2/jobs_spec.rb index bbaabefd..a17a4b17 100644 --- a/spec/integration/v2/jobs_spec.rb +++ b/spec/integration/v2/jobs_spec.rb @@ -105,14 +105,14 @@ describe 'Jobs' do end it 'adds removed info if the log is removed' do - time = Time.new(2015, 1, 9, 12, 57, 31).utc + time = Time.utc(2015, 1, 9, 12, 57, 31) job.log.update_attributes(removed_at: time, removed_by: User.first) headers = { 'HTTP_ACCEPT' => 'application/json; chunked=true; version=2' } response = get "/jobs/#{job.id}/log", {}, headers body = JSON.parse(response.body) body['log']['removed_by'].should == 'Sven Fuchs' - body['log']['removed_at'].should == "2015-01-09T11:57:31Z" + body['log']['removed_at'].should == "2015-01-09T12:57:31Z" body['log']['id'].should == job.log.id # make sure we return parts as chunked=true From 2efc2d247b3d4b42bde8dff3f9cd113180e09d39 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Tue, 13 Jan 2015 15:31:01 +0100 Subject: [PATCH 08/43] update travis-yaml --- Gemfile.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index ec2550c4..75aafa91 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -75,15 +75,15 @@ GIT GIT remote: git://github.com/travis-ci/travis-support.git - revision: 40365216662f639d36fc3a0463c4e189ee1563dd + revision: 4fdd220ed7b06a12951e5d74a763c05a80eb0d20 specs: travis-support (0.0.1) GIT remote: git://github.com/travis-ci/travis-yaml.git - revision: 08ec0c4d0cf3366cd971d4acd9aadbc0db68f85d + revision: f3aa306016a08b66a487f966eb8aa3a60ee9b319 specs: - travis-yaml (0.1.0) + travis-yaml (0.2.0) PATH remote: . From d18f825b1593c14f7f27b45d2f2ed6c2cfea1e64 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Tue, 13 Jan 2015 15:43:35 +0100 Subject: [PATCH 09/43] update core --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 75aafa91..f85ae2cf 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -43,7 +43,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: 0d88007ac35ab7aeb44fb59e95a8873b0a5b69bf + revision: cbfb6da8a1c6f4cc80c40b260d4d2708e3acec03 specs: travis-core (0.0.1) actionmailer (~> 3.2.19) From 570602fc92106cdc10f0aa6bcdede03669f1c29b Mon Sep 17 00:00:00 2001 From: Josh Kalderimis Date: Tue, 13 Jan 2015 18:40:05 +0100 Subject: [PATCH 10/43] correct a variable reference 'object' is not used in that method, it should be log --- lib/travis/api/v2/http/log.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/travis/api/v2/http/log.rb b/lib/travis/api/v2/http/log.rb index 96cb408a..1ace5cd8 100644 --- a/lib/travis/api/v2/http/log.rb +++ b/lib/travis/api/v2/http/log.rb @@ -14,7 +14,7 @@ module Travis log_hash = options[:chunked] ? chunked_log_data : log_data if log.removed_at log_hash['removed_at'] = log.removed_at - log_hash['removed_by'] = log.removed_by.name || object.removed_by.login + log_hash['removed_by'] = log.removed_by.name || log.removed_by.login end { From 371d67f9006ecb1b1632f55a5f730799bdde272b Mon Sep 17 00:00:00 2001 From: Josh Kalderimis Date: Tue, 13 Jan 2015 18:57:32 +0100 Subject: [PATCH 11/43] use ruby 2.1.5 --- .ruby-version | 2 +- .travis.yml | 20 ++++++++++++-------- Gemfile | 2 ++ 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/.ruby-version b/.ruby-version index 7d2ed7c7..cd57a8b9 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.1.4 +2.1.5 diff --git a/.travis.yml b/.travis.yml index 4bc87dd6..08c1c58f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,17 +1,21 @@ language: ruby + sudo: false -rvm: -- 2.1.4 + +rvm: 2.1.5 + env: global: - - RUBY_GC_MALLOC_LIMIT=90000000 - - RUBY_GC_HEAP_FREE_SLOTS=200000 + - RUBY_GC_MALLOC_LIMIT=90000000 + - RUBY_GC_HEAP_FREE_SLOTS=200000 + cache: bundler + addons: postgresql: 9.3 + services: -- redis + - redis + before_script: -- 'RAILS_ENV=test bundle exec rake db:create db:migrate --trace' -notifications: - irc: "irc.freenode.org#travis" + - 'RAILS_ENV=test bundle exec rake db:create db:migrate --trace' diff --git a/Gemfile b/Gemfile index 43d10a2b..aa41780b 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,8 @@ source 'https://rubygems.org' gemspec +ruby "2.1.5" + gem 's3', github: 'travis-ci/s3' gem 'travis-core', github: 'travis-ci/travis-core' From 396a0f756cf9e5dfce511fbf1f261b6843b08e0f Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 12:33:23 +0100 Subject: [PATCH 12/43] add conditional skylight tracking --- .gitignore | 1 + Gemfile | 1 + Gemfile.lock | 5 ++- lib/travis/api/app.rb | 1 + lib/travis/api/conditional_skylight.rb | 50 ++++++++++++++++++++++++++ 5 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 lib/travis/api/conditional_skylight.rb diff --git a/.gitignore b/.gitignore index e5dba86d..68072775 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ config/travis.yml .yardoc log/ vendor +config/skylight.yml diff --git a/Gemfile b/Gemfile index aa41780b..1b0280e0 100644 --- a/Gemfile +++ b/Gemfile @@ -27,6 +27,7 @@ gem 'pry' gem 'metriks', '0.9.9.6' gem 'metriks-librato_metrics', github: 'eric/metriks-librato_metrics' gem 'micro_migrations' +gem 'skylight', '~> 0.6.0.beta.1' group :test do gem 'rspec', '~> 2.13' diff --git a/Gemfile.lock b/Gemfile.lock index f85ae2cf..c12faada 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -81,7 +81,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-yaml.git - revision: f3aa306016a08b66a487f966eb8aa3a60ee9b319 + revision: 1630d576d221aea2340615e87f402df7889b5176 specs: travis-yaml (0.2.0) @@ -302,6 +302,8 @@ GEM rack-test sinatra (~> 1.4.0) tilt (~> 1.3) + skylight (0.6.0.beta.1) + activesupport (>= 3.0.0) slop (3.6.0) sprockets (2.2.3) hike (~> 1.2) @@ -367,6 +369,7 @@ DEPENDENCIES sentry-raven! sinatra sinatra-contrib + skylight (~> 0.6.0.beta.1) travis-api! travis-config (~> 0.1.0) travis-core! diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index 1934ede2..b1aea36b 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -20,6 +20,7 @@ require 'metriks/librato_metrics_reporter' require 'travis/support/log_subscriber/active_record_metrics' require 'fileutils' require 'travis/api/v2/http' +require 'travis/api/conditional_skylight' # Rack class implementing the HTTP API. # Instances respond to #call. diff --git a/lib/travis/api/conditional_skylight.rb b/lib/travis/api/conditional_skylight.rb new file mode 100644 index 00000000..773a316d --- /dev/null +++ b/lib/travis/api/conditional_skylight.rb @@ -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 From 14a3ba54081f957f7452574af98fdb08298326b8 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 13:05:09 +0100 Subject: [PATCH 13/43] use patched skylight --- Gemfile | 2 +- Gemfile.lock | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 1b0280e0..8bd41c72 100644 --- a/Gemfile +++ b/Gemfile @@ -27,7 +27,7 @@ gem 'pry' gem 'metriks', '0.9.9.6' gem 'metriks-librato_metrics', github: 'eric/metriks-librato_metrics' gem 'micro_migrations' -gem 'skylight', '~> 0.6.0.beta.1' +gem 'skylight', github: 'rkh/skylight-ruby', branch: 'rkh-script-name-sinatra' group :test do gem 'rspec', '~> 2.13' diff --git a/Gemfile.lock b/Gemfile.lock index c12faada..e0e52375 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -20,6 +20,14 @@ GIT rack-contrib (1.2.0) rack (>= 0.9.1) +GIT + remote: git://github.com/rkh/skylight-ruby.git + revision: 8dbe7270188fd1e0df9497835728c5200cf883dc + branch: rkh-script-name-sinatra + specs: + skylight (0.6.0.beta.1) + activesupport (>= 3.0.0) + GIT remote: git://github.com/rkh/yard-sinatra.git revision: 00774d355123617ff0faa7e0ebd54c4cdcfcdf93 @@ -302,8 +310,6 @@ GEM rack-test sinatra (~> 1.4.0) tilt (~> 1.3) - skylight (0.6.0.beta.1) - activesupport (>= 3.0.0) slop (3.6.0) sprockets (2.2.3) hike (~> 1.2) @@ -369,7 +375,7 @@ DEPENDENCIES sentry-raven! sinatra sinatra-contrib - skylight (~> 0.6.0.beta.1) + skylight! travis-api! travis-config (~> 0.1.0) travis-core! From 0aebede82dfe76a5ae3c9095be6860f2d0b1d782 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 13:11:46 +0100 Subject: [PATCH 14/43] update skylight --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index e0e52375..ec0c0a9d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -22,7 +22,7 @@ GIT GIT remote: git://github.com/rkh/skylight-ruby.git - revision: 8dbe7270188fd1e0df9497835728c5200cf883dc + revision: 287673533ee47e10fd75adb78bae1e732b8f3c30 branch: rkh-script-name-sinatra specs: skylight (0.6.0.beta.1) From ea4a1c5bc4ee35284715e0f93b3e3ed8f8a2bc90 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 13:41:31 +0100 Subject: [PATCH 15/43] use skylight without their sinatra code --- Gemfile | 2 +- Gemfile.lock | 12 +-- lib/travis/api/app.rb | 1 + lib/travis/api/app/middleware/skylight.rb | 5 + .../api/app/middleware/skylight/actual.rb | 26 +++++ .../api/app/middleware/skylight/dummy.rb | 7 ++ lib/travis/api/conditional_skylight.rb | 100 +++++++++--------- 7 files changed, 93 insertions(+), 60 deletions(-) create mode 100644 lib/travis/api/app/middleware/skylight.rb create mode 100644 lib/travis/api/app/middleware/skylight/actual.rb create mode 100644 lib/travis/api/app/middleware/skylight/dummy.rb diff --git a/Gemfile b/Gemfile index 8bd41c72..e433a477 100644 --- a/Gemfile +++ b/Gemfile @@ -27,7 +27,7 @@ gem 'pry' gem 'metriks', '0.9.9.6' gem 'metriks-librato_metrics', github: 'eric/metriks-librato_metrics' gem 'micro_migrations' -gem 'skylight', github: 'rkh/skylight-ruby', branch: 'rkh-script-name-sinatra' +gem 'skylight' group :test do gem 'rspec', '~> 2.13' diff --git a/Gemfile.lock b/Gemfile.lock index ec0c0a9d..3f38a26c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -20,14 +20,6 @@ GIT rack-contrib (1.2.0) rack (>= 0.9.1) -GIT - remote: git://github.com/rkh/skylight-ruby.git - revision: 287673533ee47e10fd75adb78bae1e732b8f3c30 - branch: rkh-script-name-sinatra - specs: - skylight (0.6.0.beta.1) - activesupport (>= 3.0.0) - GIT remote: git://github.com/rkh/yard-sinatra.git revision: 00774d355123617ff0faa7e0ebd54c4cdcfcdf93 @@ -310,6 +302,8 @@ GEM rack-test sinatra (~> 1.4.0) tilt (~> 1.3) + skylight (0.6.0.beta.1) + activesupport (>= 3.0.0) slop (3.6.0) sprockets (2.2.3) hike (~> 1.2) @@ -375,7 +369,7 @@ DEPENDENCIES sentry-raven! sinatra sinatra-contrib - skylight! + skylight travis-api! travis-config (~> 0.1.0) travis-core! diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index b1aea36b..cf4e3bc5 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -113,6 +113,7 @@ module Travis::Api use Travis::Api::App::Middleware::ScopeCheck use Travis::Api::App::Middleware::Logging + use Travis::Api::App::Middleware::Skylight use Travis::Api::App::Middleware::Metriks use Travis::Api::App::Middleware::Rewrite use Travis::Api::App::Middleware::UserAgentTracker diff --git a/lib/travis/api/app/middleware/skylight.rb b/lib/travis/api/app/middleware/skylight.rb new file mode 100644 index 00000000..ccd2c527 --- /dev/null +++ b/lib/travis/api/app/middleware/skylight.rb @@ -0,0 +1,5 @@ +if ENV['SKYLIGHT_AUTHENTICATION'] + require_relative 'skylight/actual' +else + require_relative 'skylight/dummy' +end diff --git a/lib/travis/api/app/middleware/skylight/actual.rb b/lib/travis/api/app/middleware/skylight/actual.rb new file mode 100644 index 00000000..a7a59696 --- /dev/null +++ b/lib/travis/api/app/middleware/skylight/actual.rb @@ -0,0 +1,26 @@ +require 'travis/api/app' +require 'skylight' +require 'skylight/probes/tilt' +require 'skylight/probes/redis' + +class Travis::Api::App + class Middleware + class Skylight < Middleware + set(:setup) { ::Skylight.start! } + use ::Skylight::Middleware + + after do + instrumenter = Skylight::Instrumenter.instance + trace = instrumenter.current_trace if instrumenter + trace.endpoint = endpoint if trace and endpoint + end + + def endpoint + return @endpoint if defined? @endpoint and @endpoint + return unless headers['X-Pattern'].present? and headers['X-Endpoint'].present? + @endpoint = Object.const_get(headers['X-Endpoint']) + headers['X-Pattern'] + rescue NameError + end + end + end +end diff --git a/lib/travis/api/app/middleware/skylight/dummy.rb b/lib/travis/api/app/middleware/skylight/dummy.rb new file mode 100644 index 00000000..d4309f23 --- /dev/null +++ b/lib/travis/api/app/middleware/skylight/dummy.rb @@ -0,0 +1,7 @@ +class Travis::Api::App + class Middleware + module Skylight + def self.new(app) app end + end + end +end diff --git a/lib/travis/api/conditional_skylight.rb b/lib/travis/api/conditional_skylight.rb index 773a316d..d4a2de37 100644 --- a/lib/travis/api/conditional_skylight.rb +++ b/lib/travis/api/conditional_skylight.rb @@ -1,50 +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 +# 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 From 690c59820568bedf38e8a9fd8cc890a85c49ba6b Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 13:43:55 +0100 Subject: [PATCH 16/43] remove obsolete file --- lib/travis/api/app.rb | 1 - lib/travis/api/conditional_skylight.rb | 50 -------------------------- 2 files changed, 51 deletions(-) delete mode 100644 lib/travis/api/conditional_skylight.rb diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index cf4e3bc5..1bf44abe 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -20,7 +20,6 @@ require 'metriks/librato_metrics_reporter' require 'travis/support/log_subscriber/active_record_metrics' require 'fileutils' require 'travis/api/v2/http' -require 'travis/api/conditional_skylight' # Rack class implementing the HTTP API. # Instances respond to #call. diff --git a/lib/travis/api/conditional_skylight.rb b/lib/travis/api/conditional_skylight.rb deleted file mode 100644 index d4a2de37..00000000 --- a/lib/travis/api/conditional_skylight.rb +++ /dev/null @@ -1,50 +0,0 @@ -# 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 From 73f55b8243cd6c4cf0301594ef9b2234849a97db Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 14:07:44 +0100 Subject: [PATCH 17/43] fix name issue --- lib/travis/api/app/middleware/skylight/actual.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/travis/api/app/middleware/skylight/actual.rb b/lib/travis/api/app/middleware/skylight/actual.rb index a7a59696..66d0df13 100644 --- a/lib/travis/api/app/middleware/skylight/actual.rb +++ b/lib/travis/api/app/middleware/skylight/actual.rb @@ -10,7 +10,7 @@ class Travis::Api::App use ::Skylight::Middleware after do - instrumenter = Skylight::Instrumenter.instance + instrumenter = ::Skylight::Instrumenter.instance trace = instrumenter.current_trace if instrumenter trace.endpoint = endpoint if trace and endpoint end From f5b3349d89a5300001a0f63c8f78190847dc8396 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 14:12:54 +0100 Subject: [PATCH 18/43] trying out things --- lib/travis/api/app/middleware/skylight/actual.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/travis/api/app/middleware/skylight/actual.rb b/lib/travis/api/app/middleware/skylight/actual.rb index 66d0df13..98d87828 100644 --- a/lib/travis/api/app/middleware/skylight/actual.rb +++ b/lib/travis/api/app/middleware/skylight/actual.rb @@ -12,7 +12,7 @@ class Travis::Api::App after do instrumenter = ::Skylight::Instrumenter.instance trace = instrumenter.current_trace if instrumenter - trace.endpoint = endpoint if trace and endpoint + trace.endpoint = "#{request.method} #{endpoint}" || "unknown" if trace end def endpoint From 301880b60060e7ecdf2dfa768924bdd3e67d6c0e Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 14:16:28 +0100 Subject: [PATCH 19/43] fix method name --- lib/travis/api/app/middleware/skylight/actual.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/travis/api/app/middleware/skylight/actual.rb b/lib/travis/api/app/middleware/skylight/actual.rb index 98d87828..8ea53fd3 100644 --- a/lib/travis/api/app/middleware/skylight/actual.rb +++ b/lib/travis/api/app/middleware/skylight/actual.rb @@ -12,7 +12,7 @@ class Travis::Api::App after do instrumenter = ::Skylight::Instrumenter.instance trace = instrumenter.current_trace if instrumenter - trace.endpoint = "#{request.method} #{endpoint}" || "unknown" if trace + trace.endpoint = "#{request.request_method} #{endpoint}" || "unknown" if trace end def endpoint From 50457104877e11574647e86d745900ec293f57ae Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 14:19:43 +0100 Subject: [PATCH 20/43] do not rescue --- lib/travis/api/app/middleware/skylight/actual.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/travis/api/app/middleware/skylight/actual.rb b/lib/travis/api/app/middleware/skylight/actual.rb index 8ea53fd3..082cb34c 100644 --- a/lib/travis/api/app/middleware/skylight/actual.rb +++ b/lib/travis/api/app/middleware/skylight/actual.rb @@ -19,7 +19,6 @@ class Travis::Api::App return @endpoint if defined? @endpoint and @endpoint return unless headers['X-Pattern'].present? and headers['X-Endpoint'].present? @endpoint = Object.const_get(headers['X-Endpoint']) + headers['X-Pattern'] - rescue NameError end end end From b03e9c55591c945032fe92b5f8e2deaaef93c2f6 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 14:22:10 +0100 Subject: [PATCH 21/43] fix prefix detection --- lib/travis/api/app/middleware/skylight/actual.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/travis/api/app/middleware/skylight/actual.rb b/lib/travis/api/app/middleware/skylight/actual.rb index 082cb34c..eb140a0d 100644 --- a/lib/travis/api/app/middleware/skylight/actual.rb +++ b/lib/travis/api/app/middleware/skylight/actual.rb @@ -18,7 +18,7 @@ class Travis::Api::App def endpoint return @endpoint if defined? @endpoint and @endpoint return unless headers['X-Pattern'].present? and headers['X-Endpoint'].present? - @endpoint = Object.const_get(headers['X-Endpoint']) + headers['X-Pattern'] + @endpoint = Object.const_get(headers['X-Endpoint']).prefix + headers['X-Pattern'] end end end From fb74fcc711be0f23b8191258f258b75a2c73c2f1 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 14:28:07 +0100 Subject: [PATCH 22/43] debug that --- lib/travis/api/app/middleware/skylight/actual.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/travis/api/app/middleware/skylight/actual.rb b/lib/travis/api/app/middleware/skylight/actual.rb index eb140a0d..6ca906c1 100644 --- a/lib/travis/api/app/middleware/skylight/actual.rb +++ b/lib/travis/api/app/middleware/skylight/actual.rb @@ -12,7 +12,7 @@ class Travis::Api::App after do instrumenter = ::Skylight::Instrumenter.instance trace = instrumenter.current_trace if instrumenter - trace.endpoint = "#{request.request_method} #{endpoint}" || "unknown" if trace + p trace.endpoint = "#{request.request_method} #{endpoint}" || "unknown" if trace end def endpoint From f5f6b9d771c14a548a20e42deff6e9ec836d4e6b Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 15:52:19 +0100 Subject: [PATCH 23/43] I HAVE NO IDEA WHAT I'M DOING --- lib/travis/api/app/middleware/skylight/actual.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/travis/api/app/middleware/skylight/actual.rb b/lib/travis/api/app/middleware/skylight/actual.rb index 6ca906c1..3a77fa10 100644 --- a/lib/travis/api/app/middleware/skylight/actual.rb +++ b/lib/travis/api/app/middleware/skylight/actual.rb @@ -12,7 +12,8 @@ class Travis::Api::App after do instrumenter = ::Skylight::Instrumenter.instance trace = instrumenter.current_trace if instrumenter - p trace.endpoint = "#{request.request_method} #{endpoint}" || "unknown" if trace + x = trace.endpoint = "#{request.request_method} #{endpoint}" || "unknown" if trace + puts env.inspect unless x end def endpoint From 831549a17347cd18c85f79b2f563273de75cda08 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 15:56:44 +0100 Subject: [PATCH 24/43] use path info if we don't have a pattern --- lib/travis/api/app/middleware/skylight/actual.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/travis/api/app/middleware/skylight/actual.rb b/lib/travis/api/app/middleware/skylight/actual.rb index 3a77fa10..3e0d736c 100644 --- a/lib/travis/api/app/middleware/skylight/actual.rb +++ b/lib/travis/api/app/middleware/skylight/actual.rb @@ -12,8 +12,7 @@ class Travis::Api::App after do instrumenter = ::Skylight::Instrumenter.instance trace = instrumenter.current_trace if instrumenter - x = trace.endpoint = "#{request.request_method} #{endpoint}" || "unknown" if trace - puts env.inspect unless x + trace.endpoint = "#{request.request_method} #{endpoint || request.path_info}" if trace end def endpoint From decf338a38fa35abe72933e5434eb03eeef78244 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 16:15:03 +0100 Subject: [PATCH 25/43] automated middleware instrumentation --- lib/travis/api/app.rb | 2 + lib/travis/api/app/stack_instrumentation.rb | 42 +++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 lib/travis/api/app/stack_instrumentation.rb diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index 1bf44abe..b092aee8 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -20,6 +20,7 @@ require 'metriks/librato_metrics_reporter' require 'travis/support/log_subscriber/active_record_metrics' require 'fileutils' require 'travis/api/v2/http' +require 'travis/api/stack_instrumentation' # Rack class implementing the HTTP API. # Instances respond to #call. @@ -75,6 +76,7 @@ module Travis::Api def initialize @app = Rack::Builder.app do + extend StackInstrumentation use(Rack::Config) { |env| env['metriks.request.start'] ||= Time.now.utc } Rack::Utils::HTTP_STATUS_CODES[420] = "Enhance Your Calm" diff --git a/lib/travis/api/app/stack_instrumentation.rb b/lib/travis/api/app/stack_instrumentation.rb new file mode 100644 index 00000000..f6fdec78 --- /dev/null +++ b/lib/travis/api/app/stack_instrumentation.rb @@ -0,0 +1,42 @@ +require 'travis/api/app' + +class Travis::Api::App + module StackInstrumentation + class Middleware + def initialize(app, title = nil) + @app = app + @title = title || "Rack: use #{app.class.name}" + end + + def call(env) + instrument { @app.call(env) } + end + + def instrument(&block) + return yield unless instrument? + ::Skylight.instrument(title: title, &block) + end + + def instrument? + defined? ::Skylight + end + end + + def use(*) + super(Middleware) + super + end + + def run(app) + super Middleware.new(app, "Rack: run %p" % app.class) + end + + def map(path, &block) + super(path) do + use(Middleware, "Rack: map %p" % path) + extend StackInstrumentation + instance_eval(&block) + end + end + end +end From 784ca8479f929ada0fd3f4622c23a149cca3d262 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 16:18:24 +0100 Subject: [PATCH 26/43] fix require --- lib/travis/api/app.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index b092aee8..bb72a075 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -20,7 +20,7 @@ require 'metriks/librato_metrics_reporter' require 'travis/support/log_subscriber/active_record_metrics' require 'fileutils' require 'travis/api/v2/http' -require 'travis/api/stack_instrumentation' +require 'travis/api/app/stack_instrumentation' # Rack class implementing the HTTP API. # Instances respond to #call. From 4a6dabaa0eca63cf5f4ca17b69006b7b3e7153e8 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 16:21:07 +0100 Subject: [PATCH 27/43] fix typo --- lib/travis/api/app/stack_instrumentation.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/travis/api/app/stack_instrumentation.rb b/lib/travis/api/app/stack_instrumentation.rb index f6fdec78..51b28fb2 100644 --- a/lib/travis/api/app/stack_instrumentation.rb +++ b/lib/travis/api/app/stack_instrumentation.rb @@ -14,7 +14,7 @@ class Travis::Api::App def instrument(&block) return yield unless instrument? - ::Skylight.instrument(title: title, &block) + ::Skylight.instrument(title: @title, &block) end def instrument? From 4c2d1b89b3a8c6dd4117fac23589c41b953dbb02 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 16:30:04 +0100 Subject: [PATCH 28/43] better titles --- lib/travis/api/app/stack_instrumentation.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/travis/api/app/stack_instrumentation.rb b/lib/travis/api/app/stack_instrumentation.rb index 51b28fb2..7e8e9a63 100644 --- a/lib/travis/api/app/stack_instrumentation.rb +++ b/lib/travis/api/app/stack_instrumentation.rb @@ -5,7 +5,7 @@ class Travis::Api::App class Middleware def initialize(app, title = nil) @app = app - @title = title || "Rack: use #{app.class.name}" + @title = title || StackInstrumentation.title_for(app, :use) end def call(env) @@ -22,18 +22,28 @@ class Travis::Api::App end end + def self.title_for(verb, object) + object &&= case object + when ::Sinatra::Wrapper then object.settings.inspect + when Class, Module then object.inspect + when String then object + else object.class.inspect + end + "Rack: #{verb} #{object}" + end + def use(*) super(Middleware) super end def run(app) - super Middleware.new(app, "Rack: run %p" % app.class) + super Middleware.new(app, StackInstrumentation.title_for(app, :run)) end def map(path, &block) super(path) do - use(Middleware, "Rack: map %p" % path) + use(Middleware, StackInstrumentation.title_for(path, :map)) extend StackInstrumentation instance_eval(&block) end From e11733527f46a642eabf6a56f5bead0db478262c Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 16:31:49 +0100 Subject: [PATCH 29/43] downgrade ruby --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index e433a477..7a2f174e 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ source 'https://rubygems.org' gemspec -ruby "2.1.5" +ruby '2.1.2' if ENV.key?('DYNO') gem 's3', github: 'travis-ci/s3' From 89aaff401c941a73060d109dd916f7686861955f Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 16:33:58 +0100 Subject: [PATCH 30/43] switcheroo --- lib/travis/api/app/stack_instrumentation.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/travis/api/app/stack_instrumentation.rb b/lib/travis/api/app/stack_instrumentation.rb index 7e8e9a63..0307b6b3 100644 --- a/lib/travis/api/app/stack_instrumentation.rb +++ b/lib/travis/api/app/stack_instrumentation.rb @@ -22,7 +22,7 @@ class Travis::Api::App end end - def self.title_for(verb, object) + def self.title_for(object, verb) object &&= case object when ::Sinatra::Wrapper then object.settings.inspect when Class, Module then object.inspect From 81b0019f14f84a3f88e159541e6c87df5c7821b1 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 16:52:56 +0100 Subject: [PATCH 31/43] move skylight up --- lib/travis/api/app.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index bb72a075..07682455 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -77,6 +77,7 @@ module Travis::Api def initialize @app = Rack::Builder.app do extend StackInstrumentation + use Travis::Api::App::Middleware::Skylight use(Rack::Config) { |env| env['metriks.request.start'] ||= Time.now.utc } Rack::Utils::HTTP_STATUS_CODES[420] = "Enhance Your Calm" @@ -114,7 +115,6 @@ module Travis::Api use Travis::Api::App::Middleware::ScopeCheck use Travis::Api::App::Middleware::Logging - use Travis::Api::App::Middleware::Skylight use Travis::Api::App::Middleware::Metriks use Travis::Api::App::Middleware::Rewrite use Travis::Api::App::Middleware::UserAgentTracker From 7d5d6b578cf90b63b74b9576e382b8e47dd442b8 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 17:00:16 +0100 Subject: [PATCH 32/43] instrument access token --- lib/travis/api/app.rb | 1 + lib/travis/api/app/access_token.rb | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index 07682455..8c0c86f3 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -1,3 +1,4 @@ +require 'skylight' require 'travis' require 'travis/model' require 'travis/support/amqp' diff --git a/lib/travis/api/app/access_token.rb b/lib/travis/api/app/access_token.rb index 99a70ad5..13219b3b 100644 --- a/lib/travis/api/app/access_token.rb +++ b/lib/travis/api/app/access_token.rb @@ -3,6 +3,8 @@ require 'securerandom' class Travis::Api::App class AccessToken + include Skylight::Helpers + DEFAULT_SCOPES = [:public, :private] attr_reader :token, :scopes, :user_id, :app_id, :expires_in, :extra @@ -22,6 +24,7 @@ class Travis::Api::App new(token: token, scopes: scopes, user_id: user_id, app_id: app_id, extra: extra) if user_id end + instrument_method def initialize(options = {}) raise ArgumentError, 'must supply either user_id or user' unless options.key?(:user) ^ options.key?(:user_id) raise ArgumentError, 'must supply app_id' unless options.key?(:app_id) @@ -40,6 +43,7 @@ class Travis::Api::App @extra = options[:extra] end + instrument_method def save key = key(token) redis.del(key) @@ -90,6 +94,7 @@ class Travis::Api::App private + instrument_method def reuse_token redis.get(reuse_key) unless expires_in end From a42afd5180630d23cd3b1f74bfbbab005510f4ae Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 17:06:25 +0100 Subject: [PATCH 33/43] fail nicely when not able to figure out endpoint --- lib/travis/api/app/middleware/skylight/actual.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/travis/api/app/middleware/skylight/actual.rb b/lib/travis/api/app/middleware/skylight/actual.rb index 3e0d736c..f15ad8ee 100644 --- a/lib/travis/api/app/middleware/skylight/actual.rb +++ b/lib/travis/api/app/middleware/skylight/actual.rb @@ -19,6 +19,7 @@ class Travis::Api::App return @endpoint if defined? @endpoint and @endpoint return unless headers['X-Pattern'].present? and headers['X-Endpoint'].present? @endpoint = Object.const_get(headers['X-Endpoint']).prefix + headers['X-Pattern'] + rescue NameError end end end From a8b1ccfc4a6e093f23880bb2d2a590bf6bdd8032 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 17:07:38 +0100 Subject: [PATCH 34/43] instrument responders --- lib/travis/api/app/responders/atom.rb | 1 + lib/travis/api/app/responders/badge.rb | 1 + lib/travis/api/app/responders/base.rb | 1 + lib/travis/api/app/responders/image.rb | 1 + lib/travis/api/app/responders/json.rb | 1 + lib/travis/api/app/responders/plain.rb | 1 + lib/travis/api/app/responders/service.rb | 1 + lib/travis/api/app/responders/xml.rb | 1 + 8 files changed, 8 insertions(+) diff --git a/lib/travis/api/app/responders/atom.rb b/lib/travis/api/app/responders/atom.rb index 163cf7a3..8bdd3e44 100644 --- a/lib/travis/api/app/responders/atom.rb +++ b/lib/travis/api/app/responders/atom.rb @@ -44,6 +44,7 @@ module Travis::Api::App::Responders super && resource.is_a?(ActiveRecord::Relation) && resource.first.is_a?(Build) end + instrument_method def apply super diff --git a/lib/travis/api/app/responders/badge.rb b/lib/travis/api/app/responders/badge.rb index 6c759b85..ec348228 100644 --- a/lib/travis/api/app/responders/badge.rb +++ b/lib/travis/api/app/responders/badge.rb @@ -4,6 +4,7 @@ module Travis::Api::App::Responders 'svg' end + instrument_method def apply set_headers send_file(filename, type: :svg, last_modified: last_modified) diff --git a/lib/travis/api/app/responders/base.rb b/lib/travis/api/app/responders/base.rb index 5f463d9c..525779a2 100644 --- a/lib/travis/api/app/responders/base.rb +++ b/lib/travis/api/app/responders/base.rb @@ -1,5 +1,6 @@ module Travis::Api::App::Responders class Base + include Skylight::Helpers attr_reader :endpoint, :resource, :options def initialize(endpoint, resource, options = {}) diff --git a/lib/travis/api/app/responders/image.rb b/lib/travis/api/app/responders/image.rb index df126d55..5ce73814 100644 --- a/lib/travis/api/app/responders/image.rb +++ b/lib/travis/api/app/responders/image.rb @@ -10,6 +10,7 @@ module Travis::Api::App::Responders headers['Content-Disposition'] = %(inline; filename="#{File.basename(filename)}") end + instrument_method def apply set_headers send_file(filename, type: :png, last_modified: last_modified) diff --git a/lib/travis/api/app/responders/json.rb b/lib/travis/api/app/responders/json.rb index 8d8b0314..441039a9 100644 --- a/lib/travis/api/app/responders/json.rb +++ b/lib/travis/api/app/responders/json.rb @@ -7,6 +7,7 @@ class Travis::Api::App super && !resource.is_a?(String) && !resource.nil? && accepts_log? end + instrument_method def apply super diff --git a/lib/travis/api/app/responders/plain.rb b/lib/travis/api/app/responders/plain.rb index 236bfdcf..df27b210 100644 --- a/lib/travis/api/app/responders/plain.rb +++ b/lib/travis/api/app/responders/plain.rb @@ -13,6 +13,7 @@ module Travis::Api::App::Responders super && (resource.is_a?(Log) || resource.is_a?(String)) end + instrument_method def apply super diff --git a/lib/travis/api/app/responders/service.rb b/lib/travis/api/app/responders/service.rb index 57942234..5f6f5655 100644 --- a/lib/travis/api/app/responders/service.rb +++ b/lib/travis/api/app/responders/service.rb @@ -10,6 +10,7 @@ module Travis::Api resource.respond_to?(:run) end + instrument_method def apply cache_control result = normalize(resource.run) diff --git a/lib/travis/api/app/responders/xml.rb b/lib/travis/api/app/responders/xml.rb index 7db0a964..871dbc22 100644 --- a/lib/travis/api/app/responders/xml.rb +++ b/lib/travis/api/app/responders/xml.rb @@ -37,6 +37,7 @@ module Travis::Api::App::Responders super && @resource.first.is_a?(Repository) end + instrument_method def apply super From 327da14def596c259bc0de27b847d49bcf7a316a Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 17:22:10 +0100 Subject: [PATCH 35/43] instrument services --- lib/travis/api/app.rb | 2 +- lib/travis/api/instruments.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 lib/travis/api/instruments.rb diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index 8c0c86f3..e5f18631 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -1,4 +1,3 @@ -require 'skylight' require 'travis' require 'travis/model' require 'travis/support/amqp' @@ -20,6 +19,7 @@ require 'metriks/reporter/logger' require 'metriks/librato_metrics_reporter' require 'travis/support/log_subscriber/active_record_metrics' require 'fileutils' +require 'travis/api/instruments' require 'travis/api/v2/http' require 'travis/api/app/stack_instrumentation' diff --git a/lib/travis/api/instruments.rb b/lib/travis/api/instruments.rb new file mode 100644 index 00000000..a6973f8d --- /dev/null +++ b/lib/travis/api/instruments.rb @@ -0,0 +1,6 @@ +require 'skylight' + +Travis.services.send(:services).each_value do |service| + service.send(:include, Skylight::Helpers) + service.send(:instrument_method, :run) +end \ No newline at end of file From 6681d160c1621587a2f88e40878b805cdad4e48a Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 17:39:59 +0100 Subject: [PATCH 36/43] Revert "instrument services" This reverts commit 327da14def596c259bc0de27b847d49bcf7a316a. --- lib/travis/api/app.rb | 2 +- lib/travis/api/instruments.rb | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) delete mode 100644 lib/travis/api/instruments.rb diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index e5f18631..8c0c86f3 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -1,3 +1,4 @@ +require 'skylight' require 'travis' require 'travis/model' require 'travis/support/amqp' @@ -19,7 +20,6 @@ require 'metriks/reporter/logger' require 'metriks/librato_metrics_reporter' require 'travis/support/log_subscriber/active_record_metrics' require 'fileutils' -require 'travis/api/instruments' require 'travis/api/v2/http' require 'travis/api/app/stack_instrumentation' diff --git a/lib/travis/api/instruments.rb b/lib/travis/api/instruments.rb deleted file mode 100644 index a6973f8d..00000000 --- a/lib/travis/api/instruments.rb +++ /dev/null @@ -1,6 +0,0 @@ -require 'skylight' - -Travis.services.send(:services).each_value do |service| - service.send(:include, Skylight::Helpers) - service.send(:instrument_method, :run) -end \ No newline at end of file From 01ec5e152a3996d9925d7d3b141f8f555e9f2fa0 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 18:07:40 +0100 Subject: [PATCH 37/43] Revert "instrument responders" This reverts commit a8b1ccfc4a6e093f23880bb2d2a590bf6bdd8032. --- lib/travis/api/app/responders/atom.rb | 1 - lib/travis/api/app/responders/badge.rb | 1 - lib/travis/api/app/responders/base.rb | 1 - lib/travis/api/app/responders/image.rb | 1 - lib/travis/api/app/responders/json.rb | 1 - lib/travis/api/app/responders/plain.rb | 1 - lib/travis/api/app/responders/service.rb | 1 - lib/travis/api/app/responders/xml.rb | 1 - 8 files changed, 8 deletions(-) diff --git a/lib/travis/api/app/responders/atom.rb b/lib/travis/api/app/responders/atom.rb index 8bdd3e44..163cf7a3 100644 --- a/lib/travis/api/app/responders/atom.rb +++ b/lib/travis/api/app/responders/atom.rb @@ -44,7 +44,6 @@ module Travis::Api::App::Responders super && resource.is_a?(ActiveRecord::Relation) && resource.first.is_a?(Build) end - instrument_method def apply super diff --git a/lib/travis/api/app/responders/badge.rb b/lib/travis/api/app/responders/badge.rb index ec348228..6c759b85 100644 --- a/lib/travis/api/app/responders/badge.rb +++ b/lib/travis/api/app/responders/badge.rb @@ -4,7 +4,6 @@ module Travis::Api::App::Responders 'svg' end - instrument_method def apply set_headers send_file(filename, type: :svg, last_modified: last_modified) diff --git a/lib/travis/api/app/responders/base.rb b/lib/travis/api/app/responders/base.rb index 525779a2..5f463d9c 100644 --- a/lib/travis/api/app/responders/base.rb +++ b/lib/travis/api/app/responders/base.rb @@ -1,6 +1,5 @@ module Travis::Api::App::Responders class Base - include Skylight::Helpers attr_reader :endpoint, :resource, :options def initialize(endpoint, resource, options = {}) diff --git a/lib/travis/api/app/responders/image.rb b/lib/travis/api/app/responders/image.rb index 5ce73814..df126d55 100644 --- a/lib/travis/api/app/responders/image.rb +++ b/lib/travis/api/app/responders/image.rb @@ -10,7 +10,6 @@ module Travis::Api::App::Responders headers['Content-Disposition'] = %(inline; filename="#{File.basename(filename)}") end - instrument_method def apply set_headers send_file(filename, type: :png, last_modified: last_modified) diff --git a/lib/travis/api/app/responders/json.rb b/lib/travis/api/app/responders/json.rb index 441039a9..8d8b0314 100644 --- a/lib/travis/api/app/responders/json.rb +++ b/lib/travis/api/app/responders/json.rb @@ -7,7 +7,6 @@ class Travis::Api::App super && !resource.is_a?(String) && !resource.nil? && accepts_log? end - instrument_method def apply super diff --git a/lib/travis/api/app/responders/plain.rb b/lib/travis/api/app/responders/plain.rb index df27b210..236bfdcf 100644 --- a/lib/travis/api/app/responders/plain.rb +++ b/lib/travis/api/app/responders/plain.rb @@ -13,7 +13,6 @@ module Travis::Api::App::Responders super && (resource.is_a?(Log) || resource.is_a?(String)) end - instrument_method def apply super diff --git a/lib/travis/api/app/responders/service.rb b/lib/travis/api/app/responders/service.rb index 5f6f5655..57942234 100644 --- a/lib/travis/api/app/responders/service.rb +++ b/lib/travis/api/app/responders/service.rb @@ -10,7 +10,6 @@ module Travis::Api resource.respond_to?(:run) end - instrument_method def apply cache_control result = normalize(resource.run) diff --git a/lib/travis/api/app/responders/xml.rb b/lib/travis/api/app/responders/xml.rb index 871dbc22..7db0a964 100644 --- a/lib/travis/api/app/responders/xml.rb +++ b/lib/travis/api/app/responders/xml.rb @@ -37,7 +37,6 @@ module Travis::Api::App::Responders super && @resource.first.is_a?(Repository) end - instrument_method def apply super From de9348a14e0871922cbbadc4fb07b3c9c3422783 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 19:41:37 +0100 Subject: [PATCH 38/43] Revert "Revert "instrument responders"" This reverts commit 01ec5e152a3996d9925d7d3b141f8f555e9f2fa0. --- lib/travis/api/app/responders/atom.rb | 1 + lib/travis/api/app/responders/badge.rb | 1 + lib/travis/api/app/responders/base.rb | 1 + lib/travis/api/app/responders/image.rb | 1 + lib/travis/api/app/responders/json.rb | 1 + lib/travis/api/app/responders/plain.rb | 1 + lib/travis/api/app/responders/service.rb | 1 + lib/travis/api/app/responders/xml.rb | 1 + 8 files changed, 8 insertions(+) diff --git a/lib/travis/api/app/responders/atom.rb b/lib/travis/api/app/responders/atom.rb index 163cf7a3..8bdd3e44 100644 --- a/lib/travis/api/app/responders/atom.rb +++ b/lib/travis/api/app/responders/atom.rb @@ -44,6 +44,7 @@ module Travis::Api::App::Responders super && resource.is_a?(ActiveRecord::Relation) && resource.first.is_a?(Build) end + instrument_method def apply super diff --git a/lib/travis/api/app/responders/badge.rb b/lib/travis/api/app/responders/badge.rb index 6c759b85..ec348228 100644 --- a/lib/travis/api/app/responders/badge.rb +++ b/lib/travis/api/app/responders/badge.rb @@ -4,6 +4,7 @@ module Travis::Api::App::Responders 'svg' end + instrument_method def apply set_headers send_file(filename, type: :svg, last_modified: last_modified) diff --git a/lib/travis/api/app/responders/base.rb b/lib/travis/api/app/responders/base.rb index 5f463d9c..525779a2 100644 --- a/lib/travis/api/app/responders/base.rb +++ b/lib/travis/api/app/responders/base.rb @@ -1,5 +1,6 @@ module Travis::Api::App::Responders class Base + include Skylight::Helpers attr_reader :endpoint, :resource, :options def initialize(endpoint, resource, options = {}) diff --git a/lib/travis/api/app/responders/image.rb b/lib/travis/api/app/responders/image.rb index df126d55..5ce73814 100644 --- a/lib/travis/api/app/responders/image.rb +++ b/lib/travis/api/app/responders/image.rb @@ -10,6 +10,7 @@ module Travis::Api::App::Responders headers['Content-Disposition'] = %(inline; filename="#{File.basename(filename)}") end + instrument_method def apply set_headers send_file(filename, type: :png, last_modified: last_modified) diff --git a/lib/travis/api/app/responders/json.rb b/lib/travis/api/app/responders/json.rb index 8d8b0314..441039a9 100644 --- a/lib/travis/api/app/responders/json.rb +++ b/lib/travis/api/app/responders/json.rb @@ -7,6 +7,7 @@ class Travis::Api::App super && !resource.is_a?(String) && !resource.nil? && accepts_log? end + instrument_method def apply super diff --git a/lib/travis/api/app/responders/plain.rb b/lib/travis/api/app/responders/plain.rb index 236bfdcf..df27b210 100644 --- a/lib/travis/api/app/responders/plain.rb +++ b/lib/travis/api/app/responders/plain.rb @@ -13,6 +13,7 @@ module Travis::Api::App::Responders super && (resource.is_a?(Log) || resource.is_a?(String)) end + instrument_method def apply super diff --git a/lib/travis/api/app/responders/service.rb b/lib/travis/api/app/responders/service.rb index 57942234..5f6f5655 100644 --- a/lib/travis/api/app/responders/service.rb +++ b/lib/travis/api/app/responders/service.rb @@ -10,6 +10,7 @@ module Travis::Api resource.respond_to?(:run) end + instrument_method def apply cache_control result = normalize(resource.run) diff --git a/lib/travis/api/app/responders/xml.rb b/lib/travis/api/app/responders/xml.rb index 7db0a964..871dbc22 100644 --- a/lib/travis/api/app/responders/xml.rb +++ b/lib/travis/api/app/responders/xml.rb @@ -37,6 +37,7 @@ module Travis::Api::App::Responders super && @resource.first.is_a?(Repository) end + instrument_method def apply super From 5c6fe06dfd3ed5862edc7ccba0f72f32fb52b638 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 19:41:47 +0100 Subject: [PATCH 39/43] Revert "Revert "instrument services"" This reverts commit 6681d160c1621587a2f88e40878b805cdad4e48a. --- lib/travis/api/app.rb | 2 +- lib/travis/api/instruments.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 lib/travis/api/instruments.rb diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index 8c0c86f3..e5f18631 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -1,4 +1,3 @@ -require 'skylight' require 'travis' require 'travis/model' require 'travis/support/amqp' @@ -20,6 +19,7 @@ require 'metriks/reporter/logger' require 'metriks/librato_metrics_reporter' require 'travis/support/log_subscriber/active_record_metrics' require 'fileutils' +require 'travis/api/instruments' require 'travis/api/v2/http' require 'travis/api/app/stack_instrumentation' diff --git a/lib/travis/api/instruments.rb b/lib/travis/api/instruments.rb new file mode 100644 index 00000000..a6973f8d --- /dev/null +++ b/lib/travis/api/instruments.rb @@ -0,0 +1,6 @@ +require 'skylight' + +Travis.services.send(:services).each_value do |service| + service.send(:include, Skylight::Helpers) + service.send(:instrument_method, :run) +end \ No newline at end of file From ada71f3eb10d83f5a66253aaa225f413ad3ea7b2 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 14 Jan 2015 20:14:21 +0100 Subject: [PATCH 40/43] do not use path info --- lib/travis/api/app/middleware/skylight/actual.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/travis/api/app/middleware/skylight/actual.rb b/lib/travis/api/app/middleware/skylight/actual.rb index f15ad8ee..8d466b34 100644 --- a/lib/travis/api/app/middleware/skylight/actual.rb +++ b/lib/travis/api/app/middleware/skylight/actual.rb @@ -12,7 +12,7 @@ class Travis::Api::App after do instrumenter = ::Skylight::Instrumenter.instance trace = instrumenter.current_trace if instrumenter - trace.endpoint = "#{request.request_method} #{endpoint || request.path_info}" if trace + trace.endpoint = "#{request.request_method} #{endpoint || '???'}" if trace end def endpoint From 016afceeffd90cd4921f8d0cc6577f35688f72ab Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Mon, 19 Jan 2015 13:59:53 +0100 Subject: [PATCH 41/43] only run Skylight for 20% of the dynos (rounding up if there are less than five) --- lib/conditional_skylight.rb | 38 +++++++++++++++++++++ lib/travis/api/app.rb | 1 + lib/travis/api/app/access_token.rb | 2 +- lib/travis/api/app/middleware/skylight.rb | 4 ++- lib/travis/api/app/responders/base.rb | 2 +- lib/travis/api/app/stack_instrumentation.rb | 2 +- lib/travis/api/instruments.rb | 10 +++--- travis-api.gemspec | 22 +++++++----- 8 files changed, 65 insertions(+), 16 deletions(-) create mode 100644 lib/conditional_skylight.rb diff --git a/lib/conditional_skylight.rb b/lib/conditional_skylight.rb new file mode 100644 index 00000000..bacfcaf3 --- /dev/null +++ b/lib/conditional_skylight.rb @@ -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 diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index e5f18631..0f828551 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -1,3 +1,4 @@ +require 'conditional_skylight' require 'travis' require 'travis/model' require 'travis/support/amqp' diff --git a/lib/travis/api/app/access_token.rb b/lib/travis/api/app/access_token.rb index 13219b3b..90723994 100644 --- a/lib/travis/api/app/access_token.rb +++ b/lib/travis/api/app/access_token.rb @@ -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 diff --git a/lib/travis/api/app/middleware/skylight.rb b/lib/travis/api/app/middleware/skylight.rb index ccd2c527..3558a4e9 100644 --- a/lib/travis/api/app/middleware/skylight.rb +++ b/lib/travis/api/app/middleware/skylight.rb @@ -1,4 +1,6 @@ -if ENV['SKYLIGHT_AUTHENTICATION'] +require 'conditional_skylight' + +if ConditionalSkylight.enabled? require_relative 'skylight/actual' else require_relative 'skylight/dummy' diff --git a/lib/travis/api/app/responders/base.rb b/lib/travis/api/app/responders/base.rb index 525779a2..6b92740f 100644 --- a/lib/travis/api/app/responders/base.rb +++ b/lib/travis/api/app/responders/base.rb @@ -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 = {}) diff --git a/lib/travis/api/app/stack_instrumentation.rb b/lib/travis/api/app/stack_instrumentation.rb index 0307b6b3..41a57cdd 100644 --- a/lib/travis/api/app/stack_instrumentation.rb +++ b/lib/travis/api/app/stack_instrumentation.rb @@ -18,7 +18,7 @@ class Travis::Api::App end def instrument? - defined? ::Skylight + ConditionalSkylight.enabled? end end diff --git a/lib/travis/api/instruments.rb b/lib/travis/api/instruments.rb index a6973f8d..715350f3 100644 --- a/lib/travis/api/instruments.rb +++ b/lib/travis/api/instruments.rb @@ -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 \ No newline at end of file diff --git a/travis-api.gemspec b/travis-api.gemspec index d98c31da..66811d13 100644 --- a/travis-api.gemspec +++ b/travis-api.gemspec @@ -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", From d345701948c1c42e2022ee1894ba955dd4b752e6 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Mon, 19 Jan 2015 15:47:34 +0100 Subject: [PATCH 42/43] add lucky dyno logging --- lib/conditional_skylight.rb | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/lib/conditional_skylight.rb b/lib/conditional_skylight.rb index bacfcaf3..ebda6717 100644 --- a/lib/conditional_skylight.rb +++ b/lib/conditional_skylight.rb @@ -20,12 +20,29 @@ module ConditionalSkylight 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 + @lucky_dyno = detect_lucy_dyno unless instance_variable_defined? :@lucky_dyno + @lucky_dyno + end + + def detect_lucy_dyno + unless ENV['DYNO'.freeze] + warn "[ConditionalSkylight] $DYNO not set, skipping lucky dyno check" + return true + end + + unless ENV['DYNO_COUNT'.freeze] + warn "[ConditionalSkylight] $DYNO_COUNT not set, skipping lucky dyno check" + return true + end + + dyno = Integer ENV['DYNO'.freeze][/\d+/] + + if dyno % 5 == 1 + warn "[ConditionalSkylight] lucky dyno, enabling Skylight" + true else - @lucky_dyno = true + warn "[ConditionalSkylight] not a lucky dyno, disabling Skylight" + false end end From 7e9c30896e7ef3fe813e0ceaeb02a3ace203c427 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Mon, 19 Jan 2015 15:49:54 +0100 Subject: [PATCH 43/43] remove dyno count check --- lib/conditional_skylight.rb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/conditional_skylight.rb b/lib/conditional_skylight.rb index ebda6717..a3ddf652 100644 --- a/lib/conditional_skylight.rb +++ b/lib/conditional_skylight.rb @@ -30,11 +30,6 @@ module ConditionalSkylight return true end - unless ENV['DYNO_COUNT'.freeze] - warn "[ConditionalSkylight] $DYNO_COUNT not set, skipping lucky dyno check" - return true - end - dyno = Integer ENV['DYNO'.freeze][/\d+/] if dyno % 5 == 1