telltale 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b3f430fa5cc97024ccd48df79272a985e7ac38c0
4
- data.tar.gz: 6f4f841816fd08dbfc41686c4cce8a259178a85a
3
+ metadata.gz: 4304b4c63a305124212552fb5fd320ff24e57c86
4
+ data.tar.gz: 507d4254e2adf0d1c8678ba01a838b40d9c1ae7a
5
5
  SHA512:
6
- metadata.gz: 14829cad71505623efd5689258094d6129e532d4318c387729787e077d9a828c4312e065a781e63587f72ac6522bb47639dd42c9c7520c93a5730b745678e4ea
7
- data.tar.gz: 3ee53c67ee0dcba82576ce5ce35c38c184989e54948c9ce029bdc4e5e5c4506e695ff50c214b67c0de643bc8f19f8bd441ca7193cf5fe4477c8b43fbf6609516
6
+ metadata.gz: bce6a6c780f9bb5a05f783518dd5bcfee5306c50ab1052e5969feaa11ae7a6eac4fc9f133c07928a3e6934131ef8c76fac03aeefca250d3550cba322cddb4921
7
+ data.tar.gz: df4e8574926ae457f84b6daf6dd18e8d99aea13df403be12bc5b75e57c205355ec1e7ce02eb947d10e8d62399da6c98f08960ce0ada9cfb33d82e3afc737eefa
data/.gitignore ADDED
@@ -0,0 +1,38 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ ## Specific to RubyMotion:
14
+ .dat*
15
+ .repl_history
16
+ build/
17
+
18
+ ## Documentation cache and generated files:
19
+ /.yardoc/
20
+ /_yardoc/
21
+ /doc/
22
+ /rdoc/
23
+
24
+ ## Environment normalization:
25
+ /.bundle/
26
+ /vendor/bundle
27
+ /lib/bundler/man/
28
+
29
+ # for a library or gem, you might want to ignore these files since the code is
30
+ # intended to run in multiple environments; otherwise, check them in:
31
+ # Gemfile.lock
32
+ # .ruby-version
33
+ # .ruby-gemset
34
+
35
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
36
+ .rvmrc
37
+
38
+ /spec/examples.txt
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## v0.2
6
+
7
+ * Request Count Metric
8
+
5
9
  ## v0.1.1
6
10
 
7
11
  * Reporting disabled for test environment.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,34 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ telltale (0.1.1)
5
+ opentsdb (~> 0.2.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.2.5)
11
+ opentsdb (0.2.0)
12
+ rspec (3.4.0)
13
+ rspec-core (~> 3.4.0)
14
+ rspec-expectations (~> 3.4.0)
15
+ rspec-mocks (~> 3.4.0)
16
+ rspec-core (3.4.2)
17
+ rspec-support (~> 3.4.0)
18
+ rspec-expectations (3.4.0)
19
+ diff-lcs (>= 1.2.0, < 2.0)
20
+ rspec-support (~> 3.4.0)
21
+ rspec-mocks (3.4.1)
22
+ diff-lcs (>= 1.2.0, < 2.0)
23
+ rspec-support (~> 3.4.0)
24
+ rspec-support (3.4.1)
25
+
26
+ PLATFORMS
27
+ ruby
28
+
29
+ DEPENDENCIES
30
+ rspec
31
+ telltale!
32
+
33
+ BUNDLED WITH
34
+ 1.11.2
data/README.md CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  Report Rails application metrics to OpenTSDB.
4
4
 
5
+ [![Build Status](https://travis-ci.org/ninech/telltale.svg?branch=master)](https://travis-ci.org/ninech/telltale)
6
+ [![Code Climate](https://codeclimate.com/github/ninech/telltale/badges/gpa.svg)](https://codeclimate.com/github/ninech/telltale)
7
+
5
8
  ## Instructions
6
9
 
7
10
  Add the following line to your `Gemfile` and run `bundle install`.
@@ -24,6 +27,7 @@ environment variables.
24
27
  These numbers are currently reported:
25
28
 
26
29
  * `<prefix>.rails.total_time`: Total request time in seconds
30
+ * `<prefix>.rails.request_count`: A counter for requests (always 1)
27
31
 
28
32
  The default `prefix` is "telltale" and can be configured with the environment variable `TELLTALE_PREFIX`.
29
33
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.0
data/lib/telltale.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'opentsdb'
2
+ require 'telltale/data'
2
3
 
3
4
  module Telltale
4
5
  class << self
@@ -14,13 +15,7 @@ module Telltale
14
15
  def configure_request_instrumentation
15
16
  ActiveSupport::Notifications.subscribe 'process_action.action_controller' do |_name, started, finished, _unique_id, payload|
16
17
  next unless report?
17
- data = {
18
- metric: "#{metric_prefix}.rails.total_time",
19
- value: ((finished - started) * 1000).ceil,
20
- timestamp: Time.now.to_i,
21
- tags: tags(payload),
22
- }
23
- client.put(data)
18
+ client.put Telltale::Data.compile(started, finished, payload)
24
19
  end
25
20
  end
26
21
 
@@ -28,17 +23,6 @@ module Telltale
28
23
  opentsdb_host.present? && !Rails.env.test?
29
24
  end
30
25
 
31
- def tags(payload)
32
- {
33
- http_status: http_status_from_payload(payload),
34
- controller: payload[:controller],
35
- action: [payload[:controller], payload[:action]].join('.'),
36
- host: Socket.gethostname,
37
- environment: Rails.env,
38
- app: Rails.application.class.parent_name.downcase,
39
- }
40
- end
41
-
42
26
  def opentsdb_port
43
27
  ENV['TELLTALE_OPENTSDB_PORT'] || 4242
44
28
  end
@@ -47,18 +31,9 @@ module Telltale
47
31
  ENV['TELLTALE_OPENTSDB_HOST']
48
32
  end
49
33
 
50
- def metric_prefix
51
- ENV['TELLTALE_PREFIX'] || 'telltale'
52
- end
53
-
54
34
  def client
55
35
  OpenTSDB::Client.new(hostname: opentsdb_host, port: opentsdb_port)
56
36
  end
57
-
58
- def http_status_from_payload(payload)
59
- return payload[:status] if payload[:status]
60
- return 500 if payload[:exception].present?
61
- end
62
37
  end
63
38
  end
64
39
 
@@ -0,0 +1,59 @@
1
+ module Telltale
2
+ class Data
3
+ attr_reader :started, :finished, :payload
4
+
5
+ def self.compile(started, finished, payload)
6
+ new(started, finished, payload).all
7
+ end
8
+
9
+ def initialize(started, finished, payload)
10
+ @started = started
11
+ @finished = finished
12
+ @payload = payload
13
+ end
14
+
15
+ def all
16
+ [total_time, request_count]
17
+ end
18
+
19
+ def total_time
20
+ {
21
+ metric: "#{metric_prefix}.rails.total_time",
22
+ value: ((finished - started) * 1000).ceil,
23
+ timestamp: Time.now.to_i,
24
+ tags: tags,
25
+ }
26
+ end
27
+
28
+ def request_count
29
+ {
30
+ metric: "#{metric_prefix}.rails.request_count",
31
+ value: 1,
32
+ timestamp: Time.now.to_i,
33
+ tags: tags,
34
+ }
35
+ end
36
+
37
+ private
38
+
39
+ def metric_prefix
40
+ ENV['TELLTALE_PREFIX'] || 'telltale'
41
+ end
42
+
43
+ def tags
44
+ {
45
+ http_status: http_status,
46
+ controller: payload[:controller],
47
+ action: [payload[:controller], payload[:action]].join('.'),
48
+ host: Socket.gethostname,
49
+ environment: Rails.env,
50
+ app: Rails.application.class.parent_name.downcase,
51
+ }
52
+ end
53
+
54
+ def http_status
55
+ return payload[:status] if payload[:status]
56
+ return 500 if payload[:exception].present?
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,18 @@
1
+ RSpec.configure do |config|
2
+ config.expect_with :rspec do |expectations|
3
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
4
+ end
5
+
6
+ config.mock_with :rspec do |mocks|
7
+ mocks.verify_partial_doubles = true
8
+ end
9
+
10
+ config.filter_run :focus
11
+ config.run_all_when_everything_filtered = true
12
+ config.example_status_persistence_file_path = 'spec/examples.txt'
13
+ config.disable_monkey_patching!
14
+ config.warnings = true
15
+ config.order = :random
16
+
17
+ Kernel.srand config.seed
18
+ end
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+ require 'telltale/data'
3
+
4
+ RSpec.describe Telltale::Data do
5
+ Rails = Class.new do
6
+ def self.application; end
7
+ def self.env; end
8
+ end
9
+
10
+ let(:started) { Time.at 1 }
11
+ let(:finished) { Time.at 10 }
12
+ let(:payload) { { controller: 'contacts', action: 'show', status: 200 } }
13
+ let(:data) { Telltale::Data.new started, finished, payload }
14
+
15
+ before do
16
+ allow(Rails).to receive_message_chain(:application, :class, :parent_name).and_return('MyApp')
17
+ allow(Rails).to receive(:env).and_return('staging')
18
+ end
19
+
20
+ describe '.compile' do
21
+ it 'compiles the data for the total request time metric' do
22
+ expect(described_class.compile(started, finished, payload)).to match_array [Hash, Hash]
23
+ end
24
+ end
25
+
26
+ describe '#all' do
27
+ it 'compiles the data all metrics' do
28
+ expect(data.all).to match_array [Hash, Hash]
29
+ end
30
+ end
31
+
32
+ describe '#total_time' do
33
+ it 'compiles the data for the total request time metric' do
34
+ expect(data.total_time).to eq(
35
+ metric: 'telltale.rails.total_time',
36
+ value: 9000,
37
+ timestamp: Time.now.to_i,
38
+ tags: {
39
+ http_status: 200,
40
+ controller: 'contacts',
41
+ action: 'contacts.show',
42
+ host: 'odin',
43
+ environment: 'staging',
44
+ app: 'myapp',
45
+ },
46
+ )
47
+ end
48
+ end
49
+
50
+ describe '#request_count' do
51
+ it 'compiles the data for the request count metric' do
52
+ expect(data.request_count).to eq(
53
+ metric: 'telltale.rails.request_count',
54
+ value: 1,
55
+ timestamp: Time.now.to_i,
56
+ tags: {
57
+ http_status: 200,
58
+ controller: 'contacts',
59
+ action: 'contacts.show',
60
+ host: 'odin',
61
+ environment: 'staging',
62
+ app: 'myapp',
63
+ },
64
+ )
65
+ end
66
+ end
67
+ end
data/telltale.gemspec CHANGED
@@ -18,4 +18,5 @@ Gem::Specification.new do |s|
18
18
  s.require_paths = ['lib']
19
19
 
20
20
  s.add_runtime_dependency 'opentsdb', '~> 0.2.0'
21
+ s.add_development_dependency 'rspec'
21
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: telltale
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philippe Hassig
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-19 00:00:00.000000000 Z
11
+ date: 2016-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opentsdb
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  description: Report Rails application metrics to OpenTSDB
28
42
  email:
29
43
  - phil@nine.ch
@@ -31,11 +45,18 @@ executables: []
31
45
  extensions: []
32
46
  extra_rdoc_files: []
33
47
  files:
48
+ - ".gitignore"
49
+ - ".rspec"
34
50
  - CHANGELOG.md
51
+ - Gemfile
52
+ - Gemfile.lock
35
53
  - README.md
36
54
  - VERSION
37
55
  - lib/telltale.rb
56
+ - lib/telltale/data.rb
38
57
  - lib/telltale/railtie.rb
58
+ - spec/spec_helper.rb
59
+ - spec/telltate/data_spec.rb
39
60
  - telltale.gemspec
40
61
  homepage: http://github.com/ninech/
41
62
  licenses:
@@ -57,8 +78,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
57
78
  version: '0'
58
79
  requirements: []
59
80
  rubyforge_project:
60
- rubygems_version: 2.4.5.1
81
+ rubygems_version: 2.5.1
61
82
  signing_key:
62
83
  specification_version: 4
63
84
  summary: Report Rails application metrics to OpenTSDB
64
- test_files: []
85
+ test_files:
86
+ - spec/spec_helper.rb
87
+ - spec/telltate/data_spec.rb