-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
115 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require 'faraday' | ||
|
||
module Travis | ||
class Insights < Struct.new(:config) | ||
def post(data) | ||
http.post do |r| | ||
r.url '/events' | ||
r.params['source'] = 'hub' | ||
r.headers['Content-Type'] = 'application/json' | ||
r.body = JSON.dump(data) | ||
end | ||
end | ||
|
||
private | ||
|
||
def http | ||
@http ||= Faraday.new(compact(url: url, ssl: ssl)) do |c| | ||
c.request :authorization, :Token, %(token="#{token}") | ||
c.request :retry, max: 5, methods: [:post], exceptions: [Faraday::Error] | ||
c.response :raise_error | ||
c.adapter :net_http | ||
end | ||
end | ||
|
||
def url | ||
config[:insights][:url] | ||
end | ||
|
||
def token | ||
config[:insights][:token] | ||
end | ||
|
||
def ssl | ||
config[:ssl].to_h | ||
end | ||
|
||
def compact(hash) | ||
hash.reject { |_, value| value.nil? || value&.empty? } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ def http_basic_auth | |
database: { adapter: 'postgresql', database: "travis_#{env}", encoding: 'unicode', min_messages: 'warning', pool: 25, reaping_frequency: 60, variables: { statement_timeout: 10000 } }, | ||
logs_api: { url: 'https://travis-logs-notset.example.com:1234', token: 'notset', retries: { max: 5, interval: 3, max_interval: 60, interval_randomness: 0.5, backoff_factor: 2 } }, | ||
job_board: { url: 'https://not:[email protected]', site: 'org' }, | ||
insights: { url: ENV['INSIGHTS_URL'], token: ENV['INSIGHTS_TOKEN'] }, | ||
redis: { url: ENV['TRAVIS_REDIS_URL'] || 'redis://localhost:6379', insights_url: ENV['INSIGHTS_REDIS_URL'] || 'redis://localhost:6379' }, | ||
sidekiq: { namespace: 'sidekiq', pool_size: 1 }, | ||
lock: { strategy: :redis, ttl: 30000 }, | ||
|
@@ -34,6 +35,7 @@ def http_basic_auth | |
limit: { resets: { max: 50, after: 6 * 60 * 60 } }, | ||
notifications: [], | ||
auth: { jwt_public_key: ENV['JWT_RSA_PUBLIC_KEY'], http_basic_auth: http_basic_auth } | ||
|
||
def metrics | ||
# TODO cleanup keychain? | ||
super.to_h.merge(librato: librato.to_h.merge(source: librato_source), graphite: graphite) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module Support | ||
module Config | ||
def self.included(base) | ||
base.send(:extend, ClassMethods) | ||
end | ||
|
||
module ClassMethods | ||
def config(vars) | ||
before { define_config(vars) } | ||
after { undefine_config(vars) } | ||
end | ||
end | ||
|
||
def define_config(vars) | ||
vars.each { |key, value| context.config[key] = value } | ||
end | ||
|
||
def undefine_config(vars) | ||
vars.each { |key, _| context.config[key] = nil } | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters