travis-metrics 2.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +43 -0
- data/MIT-LICENSE +21 -0
- data/README.md +1 -0
- data/lib/travis/metrics/reporter/graphite.rb +38 -0
- data/lib/travis/metrics/reporter/librato.rb +44 -0
- data/lib/travis/metrics/sidekiq.rb +14 -0
- data/lib/travis/metrics/version.rb +5 -0
- data/lib/travis/metrics.rb +50 -0
- data/spec/spec_helper.rb +6 -0
- data/spec/support/logger.rb +13 -0
- data/spec/travis/metrics/instrument_spec.rb +43 -0
- data/spec/travis/metrics/reporter/graphite_spec.rb +37 -0
- data/spec/travis/metrics/reporter/librato_spec.rb +37 -0
- data/travis-metrics.gemspec +21 -0
- metadata +72 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 202ba9076da5cb2ecedfd3bfc0af052b96eaeac5
|
4
|
+
data.tar.gz: ffaa169c567cce2e4445b168da8fbd5bd345b9ab
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ab7dd5d25bc4775a3e9d1f81ec7e91113fc0bb6b7ceba2cf89093d42403e1b4d044319ee863c1593f5bfee0bda0723f514c8ba187ac9447a5d5a2d46fed2fd27
|
7
|
+
data.tar.gz: 598eacf6c8a7a497a0e08eb5fdc2e3f01543fae208902f2e292d1206319c3dc588db30a94dabd2f2d26df239c5aeeb1ef9dc4f4f5048ee718d6d925af4a7573b
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
travis-metrics (0.0.1)
|
5
|
+
metriks-librato_metrics (~> 1.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
atomic (1.1.99)
|
11
|
+
avl_tree (1.2.1)
|
12
|
+
atomic (~> 1.1)
|
13
|
+
diff-lcs (1.2.5)
|
14
|
+
hitimes (1.2.3)
|
15
|
+
metriks (0.9.9.7)
|
16
|
+
atomic (~> 1.0)
|
17
|
+
avl_tree (~> 1.2.0)
|
18
|
+
hitimes (~> 1.1)
|
19
|
+
metriks-librato_metrics (1.0.3)
|
20
|
+
metriks (>= 0.9.9.6)
|
21
|
+
rspec (3.3.0)
|
22
|
+
rspec-core (~> 3.3.0)
|
23
|
+
rspec-expectations (~> 3.3.0)
|
24
|
+
rspec-mocks (~> 3.3.0)
|
25
|
+
rspec-core (3.3.2)
|
26
|
+
rspec-support (~> 3.3.0)
|
27
|
+
rspec-expectations (3.3.1)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.3.0)
|
30
|
+
rspec-mocks (3.3.2)
|
31
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
32
|
+
rspec-support (~> 3.3.0)
|
33
|
+
rspec-support (3.3.0)
|
34
|
+
|
35
|
+
PLATFORMS
|
36
|
+
ruby
|
37
|
+
|
38
|
+
DEPENDENCIES
|
39
|
+
rspec
|
40
|
+
travis-metrics!
|
41
|
+
|
42
|
+
BUNDLED WITH
|
43
|
+
1.12.5
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT LICENSE
|
2
|
+
|
3
|
+
Copyright (c) 2015 Travis CI GmbH <contact@travis-ci.org>
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# travis-metrics
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'metriks/reporter/graphite'
|
2
|
+
|
3
|
+
module Travis
|
4
|
+
class Metrics
|
5
|
+
module Reporter
|
6
|
+
class Graphite < Struct.new(:config, :logger)
|
7
|
+
MSGS = {
|
8
|
+
setup: 'Using Graphite metrics reporter (host: %s, port: %s)',
|
9
|
+
error: 'Graphite error: %s (%s)'
|
10
|
+
}
|
11
|
+
|
12
|
+
def setup
|
13
|
+
return unless host
|
14
|
+
logger.info MSGS[:setup] % [host, port]
|
15
|
+
Metriks::Reporter::Graphite.new(host, port, interval: interval, on_error: method(:on_error))
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def host
|
21
|
+
config[:host]
|
22
|
+
end
|
23
|
+
|
24
|
+
def port
|
25
|
+
config[:port]
|
26
|
+
end
|
27
|
+
|
28
|
+
def interval
|
29
|
+
config[:interval]
|
30
|
+
end
|
31
|
+
|
32
|
+
def on_error(e)
|
33
|
+
logger.error MSGS[:error] % [e.message, e.respond_to?(:response) ? e.response.body : '?']
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'metriks/librato_metrics_reporter'
|
2
|
+
|
3
|
+
module Travis
|
4
|
+
class Metrics
|
5
|
+
module Reporter
|
6
|
+
class Librato < Struct.new(:config, :logger)
|
7
|
+
MSGS = {
|
8
|
+
setup: 'Using Librato metrics reporter (source: %s, account: %s)',
|
9
|
+
error: 'Librato error: %s (%s)'
|
10
|
+
}
|
11
|
+
|
12
|
+
def setup
|
13
|
+
return unless email && token
|
14
|
+
logger.info MSGS[:setup] % [source, email]
|
15
|
+
Metriks::LibratoMetricsReporter.new(email, token, source: source, on_error: method(:on_error))
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def email
|
21
|
+
config[:email]
|
22
|
+
end
|
23
|
+
|
24
|
+
def token
|
25
|
+
config[:token]
|
26
|
+
end
|
27
|
+
|
28
|
+
def source
|
29
|
+
source = config[:source]
|
30
|
+
source = "#{source}.#{dyno}" if dyno
|
31
|
+
source
|
32
|
+
end
|
33
|
+
|
34
|
+
def dyno
|
35
|
+
ENV['DYNO']
|
36
|
+
end
|
37
|
+
|
38
|
+
def on_error(e)
|
39
|
+
logger.error MSGS[:error] % [e.message, e.response.body]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'metriks'
|
2
|
+
|
3
|
+
module Travis
|
4
|
+
class Metrics
|
5
|
+
class Sidekiq
|
6
|
+
def call(worker, message, queue, &block)
|
7
|
+
::Metriks.timer("sidekiq.jobs.#{queue}.perform").time(&block)
|
8
|
+
rescue Exception
|
9
|
+
::Metriks.meter("sidekiq.jobs.#{queue}.failure").mark
|
10
|
+
raise
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'metriks'
|
2
|
+
require 'travis/metrics/reporter/librato'
|
3
|
+
require 'travis/metrics/reporter/graphite'
|
4
|
+
|
5
|
+
module Travis
|
6
|
+
class Metrics
|
7
|
+
class << self
|
8
|
+
attr_reader :reporter
|
9
|
+
|
10
|
+
MSGS = {
|
11
|
+
no_reporter: 'No metrics reporter configured.',
|
12
|
+
error: '"Exception while starting metrics reporter: %s"'
|
13
|
+
}
|
14
|
+
|
15
|
+
def setup(config, logger)
|
16
|
+
config[:reporter] ? start(config, logger) : logger.info(MSGS[:no_reporter])
|
17
|
+
new
|
18
|
+
rescue Exception => e
|
19
|
+
logger.error [e.message, e.backtrace].join("\n")
|
20
|
+
end
|
21
|
+
|
22
|
+
def start(config, logger)
|
23
|
+
adapter = config[:reporter]
|
24
|
+
config = config[adapter.to_sym] || {}
|
25
|
+
@reporter = Reporter.send(adapter, config, logger)
|
26
|
+
reporter.start
|
27
|
+
end
|
28
|
+
|
29
|
+
def started?
|
30
|
+
!!reporter
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def count(key)
|
35
|
+
Metriks.counter(key).increment
|
36
|
+
end
|
37
|
+
|
38
|
+
def meter(key)
|
39
|
+
Metriks.meter(key).mark
|
40
|
+
end
|
41
|
+
|
42
|
+
def time(key, &block)
|
43
|
+
Metriks.timer(key).time(&block)
|
44
|
+
end
|
45
|
+
|
46
|
+
def gauge(key, value)
|
47
|
+
Metriks.gauge(key).set(value)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
describe Travis::Metrics do
|
2
|
+
let(:metrics) { described_class.new }
|
3
|
+
let(:key) { :foo }
|
4
|
+
let(:obj) { double }
|
5
|
+
|
6
|
+
describe 'count' do
|
7
|
+
|
8
|
+
it 'increments a counter' do
|
9
|
+
expect(Metriks).to receive(:counter).with(key).and_return(obj)
|
10
|
+
expect(obj).to receive(:increment)
|
11
|
+
metrics.count(key)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'meter' do
|
16
|
+
it 'meters an instrument' do
|
17
|
+
expect(Metriks).to receive(:meter).with(key).and_return(obj)
|
18
|
+
expect(obj).to receive(:mark)
|
19
|
+
metrics.meter(key)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'time' do
|
24
|
+
it 'times a block' do
|
25
|
+
called = false
|
26
|
+
block = -> { called = true }
|
27
|
+
expect(Metriks).to receive(:timer).with(key).and_return(obj)
|
28
|
+
expect(obj).to receive(:time).and_yield
|
29
|
+
metrics.time(key, &block)
|
30
|
+
expect(called).to be true
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe 'gauge' do
|
35
|
+
let(:value) { 1 }
|
36
|
+
|
37
|
+
it 'gauges a value' do
|
38
|
+
expect(Metriks).to receive(:gauge).with(key).and_return(obj)
|
39
|
+
expect(obj).to receive(:set).with(value)
|
40
|
+
metrics.gauge(key, value)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
describe Travis::Metrics::Reporter::Graphite do
|
2
|
+
let(:config) { { host: host, port: 1234, interval: 0 } }
|
3
|
+
let(:host) { 'https://example.com' }
|
4
|
+
let(:reporter) { described_class.new(config, logger) }
|
5
|
+
subject { reporter.setup }
|
6
|
+
|
7
|
+
def log
|
8
|
+
reporter.setup
|
9
|
+
super
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'setup' do
|
13
|
+
describe 'returns nil if host is missing' do
|
14
|
+
let(:host) { nil }
|
15
|
+
it { expect(subject).to be_nil }
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'returns a graphite reporter' do
|
19
|
+
it { expect(subject).to be_kind_of(Metriks::Reporter::Graphite) }
|
20
|
+
it { expect(log).to include "Using Graphite metrics reporter (host: #{host}, port: 1234)" }
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'on_error' do
|
24
|
+
let(:error) { StandardError.new('message') }
|
25
|
+
before { allow(error).to receive(:response).and_return(double(body: 'body')) }
|
26
|
+
before { allow_any_instance_of(Metriks::Reporter::Graphite).to receive(:write).and_raise(error) }
|
27
|
+
|
28
|
+
before do
|
29
|
+
subject.start
|
30
|
+
sleep 0.1 # ugh.
|
31
|
+
subject.stop
|
32
|
+
end
|
33
|
+
|
34
|
+
it { expect(stdout.string).to include 'Graphite error: message (body)' }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
describe Travis::Metrics::Reporter::Librato do
|
2
|
+
let(:config) { { email: email, token: token, source: 'source' } }
|
3
|
+
let(:email) { 'anja@travis-ci.org' }
|
4
|
+
let(:token) { 'token' }
|
5
|
+
let(:reporter) { described_class.new(config, logger) }
|
6
|
+
subject { reporter.setup }
|
7
|
+
|
8
|
+
def log
|
9
|
+
reporter.setup
|
10
|
+
super
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'setup' do
|
14
|
+
describe 'returns nil if email is missing' do
|
15
|
+
let(:email) { nil }
|
16
|
+
it { expect(subject).to be_nil }
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'returns nil if token is missing' do
|
20
|
+
let(:token) { nil }
|
21
|
+
it { expect(subject).to be_nil }
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'returns a librato reporter' do
|
25
|
+
it { expect(subject).to be_kind_of(Metriks::LibratoMetricsReporter) }
|
26
|
+
it { expect(log).to include 'Using Librato metrics reporter (source: source, account: anja@travis-ci.org)' }
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'on_error' do
|
30
|
+
let(:error) { StandardError.new('message') }
|
31
|
+
before { allow(error).to receive(:response).and_return(double(body: 'body')) }
|
32
|
+
before { allow_any_instance_of(Metriks::LibratoMetricsReporter).to receive(:write).and_raise(error) }
|
33
|
+
before { subject.flush }
|
34
|
+
it { expect(stdout.string).to include 'Librato error: message (body)' }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
$:.unshift File.expand_path('../lib', __FILE__)
|
4
|
+
require 'travis/metrics/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "travis-metrics"
|
8
|
+
s.version = Travis::Metrics::VERSION
|
9
|
+
s.authors = ['Travis CI']
|
10
|
+
s.email = 'contact@travis-ci.org'
|
11
|
+
s.homepage = 'https://github.com/travis-ci/travis-instrumentation'
|
12
|
+
s.summary = 'Instrumentation for Travis CI'
|
13
|
+
s.description = "#{s.summary}."
|
14
|
+
|
15
|
+
s.files = Dir['{lib/**/*,spec/**/*,[A-Z]*}']
|
16
|
+
s.platform = Gem::Platform::RUBY
|
17
|
+
s.require_paths = ['lib']
|
18
|
+
s.rubyforge_project = '[none]'
|
19
|
+
|
20
|
+
s.add_dependency 'metriks-librato_metrics', '~> 1.0'
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: travis-metrics
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0.rc1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Travis CI
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: metriks-librato_metrics
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
description: Instrumentation for Travis CI.
|
28
|
+
email: contact@travis-ci.org
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- Gemfile
|
34
|
+
- Gemfile.lock
|
35
|
+
- MIT-LICENSE
|
36
|
+
- README.md
|
37
|
+
- lib/travis/metrics.rb
|
38
|
+
- lib/travis/metrics/reporter/graphite.rb
|
39
|
+
- lib/travis/metrics/reporter/librato.rb
|
40
|
+
- lib/travis/metrics/sidekiq.rb
|
41
|
+
- lib/travis/metrics/version.rb
|
42
|
+
- spec/spec_helper.rb
|
43
|
+
- spec/support/logger.rb
|
44
|
+
- spec/travis/metrics/instrument_spec.rb
|
45
|
+
- spec/travis/metrics/reporter/graphite_spec.rb
|
46
|
+
- spec/travis/metrics/reporter/librato_spec.rb
|
47
|
+
- travis-metrics.gemspec
|
48
|
+
homepage: https://github.com/travis-ci/travis-instrumentation
|
49
|
+
licenses: []
|
50
|
+
metadata: {}
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">"
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 1.3.1
|
65
|
+
requirements: []
|
66
|
+
rubyforge_project: "[none]"
|
67
|
+
rubygems_version: 2.4.5
|
68
|
+
signing_key:
|
69
|
+
specification_version: 4
|
70
|
+
summary: Instrumentation for Travis CI
|
71
|
+
test_files: []
|
72
|
+
has_rdoc:
|