librato-rack-source_prefix 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b89c225d590caae55fe2331da1a38e1bd26614b3
4
+ data.tar.gz: 4e6897ef7acfcd61efdda147d7874c6ee6cd6494
5
+ SHA512:
6
+ metadata.gz: c9157e4412da883869c7a03171e7ffc275e36204d8304bfd9782d7c729d2a9ec883930b2f4ac440b11c3b02b603967815e8d2dfae40f9955deab45c46ccbf04b
7
+ data.tar.gz: d7d655be87cfb336717ae6ed5838cc5cb15f4ed16f50a5acbccf957a9c872e83b8daf11701f5e2ded66be0b16326c9b5dfacea39bc548ddd13c037f4bf4bfa79
Binary file
@@ -0,0 +1,2 @@
1
+ dQ@M����b�:Z�`U��jV�C���UQ�U���2����%r�W���|�=RR
2
+ �t�k� �7�vCO���˳�%$��!�&�W�R�-�� �a� ��(�u��SV��!�W,���H�,bR6�9R�_ơ��^��z��L�x��|
@@ -0,0 +1,2 @@
1
+ ### Version 0.1.0
2
+ * Initial release
data/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ Copyright (c) 2012. Librato, Inc.
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+ * Redistributions of source code must retain the above copyright
7
+ notice, this list of conditions and the following disclaimer.
8
+ * Redistributions in binary form must reproduce the above copyright
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
+ * Neither the name of the <organization> nor the
12
+ names of its contributors may be used to endorse or promote products
13
+ derived from this software without specific prior written permission.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ DISCLAIMED. IN NO EVENT SHALL LIBRATO, INC. BE LIABLE FOR ANY
19
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,75 @@
1
+ # librato-rack-source_prefix
2
+
3
+ This gem enables the automatic prefixing of metric source names.
4
+
5
+ By default, when you submit a metric with a custom source, that source will be passed as-is to the Librato API. For example:
6
+
7
+ ```ruby
8
+ Librato.increment :foo, source: 'some_action'
9
+ ```
10
+
11
+ The code above would result in the following data being POSTed to the Librato API:
12
+
13
+ ```json
14
+ {
15
+ "gauges": [
16
+ {
17
+ "name": "foo",
18
+ "value": 1,
19
+ "source": "some_action"
20
+ }
21
+ ]
22
+ }
23
+ ```
24
+
25
+ Note that the *source* passed to the API is identical to the value specified in the `increment` call. Even if you had configured a global *source* value (either via the `LIBRATO_SOURCE` environment variable or the *librato.yml* configuration file) the global *source* value is ignored completely.
26
+
27
+ If you were to configure a global source value of `myapp` and install the *librato-rack-source_prefix* gem, the same code shown above would result in the following data being POSTed:
28
+
29
+ ```json
30
+ {
31
+ "gauges": [
32
+ {
33
+ "name": "foo",
34
+ "value": 1,
35
+ "source": "myapp.some_action"
36
+ }
37
+ ]
38
+ }
39
+ ```
40
+
41
+ In this case, the *source* value specified as part of the `increment` call is automatically prefixed with the global source `myapp`.
42
+
43
+ ## Installation
44
+
45
+ Add this line to your application's Gemfile:
46
+
47
+ ```ruby
48
+ gem 'librato-rack-source_prefix'
49
+ ```
50
+
51
+ And then execute:
52
+
53
+ $ bundle
54
+
55
+ Or install it yourself as:
56
+
57
+ $ gem install librato-rack-source_prefix
58
+
59
+ ### Rack Applications
60
+
61
+ If your application is using a non-Rails, Rack framework you'll need to add the following line to your app in order to enable the source prefixing behavior:
62
+
63
+ ```ruby
64
+ Librato::Collector.include(Librato::Rack::SourcePrefix::Extensions::Collector)
65
+ ```
66
+
67
+ You'll want to add this line wherever you've configured your `Librato::Rack` middleware.
68
+
69
+ ### Rails
70
+
71
+ If you are using Rails, source prefixing will be enabled automatically as a result of adding the *librato-rack-source_prefix* gem to your Gemfile. No additional configuration is required.
72
+
73
+ ## Copyright
74
+
75
+ Copyright (c) 2015 [Librato Inc.](http://librato.com) See LICENSE for details.
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+
8
+ task 'before_build' do
9
+ signing_key = File.expand_path("~/.gem/librato-private_key.pem")
10
+ if File.exists?(signing_key)
11
+ puts "Key found: signing gem..."
12
+ ENV['GEM_SIGNING_KEY'] = signing_key
13
+ else
14
+ puts "WARN: signing key not found, gem not signed"
15
+ end
16
+ end
17
+ task :build => :before_build
18
+
19
+ require "bundler/gem_tasks"
20
+
21
+ # Testing
22
+ require 'rake/testtask'
23
+ Rake::TestTask.new(:test) do |t|
24
+ t.libs << 'lib'
25
+ t.libs << 'test'
26
+ t.pattern = 'test/**/*_test.rb'
27
+ t.verbose = false
28
+ end
29
+ task :default => :test
@@ -0,0 +1,5 @@
1
+ require 'librato/rack/source_prefix/extensions/collector'
2
+
3
+ if defined?(Rails)
4
+ require 'librato/rack/source_prefix/railtie'
5
+ end
@@ -0,0 +1,74 @@
1
+ module Librato::Rack::SourcePrefix
2
+ module Extensions
3
+ module Collector
4
+
5
+ def self.included(klass)
6
+ # Explicitly removing methods that we intend to override. This is
7
+ # necessary so that the methods in our module will be used when
8
+ # they're mixed-in to the real Collector class. Typically you wouldn't
9
+ # do this, but since the methods we're overriding are just delegates
10
+ # to other objects, we can safely remove the methods and call the
11
+ # underlying objects directly from our new implementations.
12
+ [:increment, :measure, :timing].each do |method|
13
+ if klass.instance_methods(false).include?(method)
14
+ klass.send(:remove_method, method)
15
+ end
16
+ end
17
+ end
18
+
19
+ def increment(counter, options={})
20
+ if prefix_needed?(options)
21
+ options[:source] = apply_prefix(options[:source])
22
+ end
23
+
24
+ counters.increment(counter, options)
25
+ end
26
+
27
+ def measure(*args, &block)
28
+ # If there are options
29
+ if args.length > 1 and args[-1].respond_to?(:each)
30
+ options = args[-1]
31
+
32
+ if prefix_needed?(options)
33
+ options[:source] = apply_prefix(options[:source])
34
+ end
35
+ end
36
+
37
+ aggregate.measure(*args, &block)
38
+ end
39
+ alias :timing :measure
40
+
41
+ private
42
+
43
+ def prefix_needed?(options)
44
+ if options[:apply_prefix].nil?
45
+ apply_prefix = true
46
+ else
47
+ apply_prefix = options.delete(:apply_prefix)
48
+ end
49
+
50
+ apply_prefix &&
51
+ options[:source] &&
52
+ global_source &&
53
+ !global_source.empty?
54
+ end
55
+
56
+ def apply_prefix(source)
57
+ if source_pids
58
+ "#{global_source}.#{$$}.#{source}"
59
+ else
60
+ "#{global_source}.#{source}"
61
+ end
62
+ end
63
+
64
+ def global_source
65
+ Librato.tracker.config.source
66
+ end
67
+
68
+ def source_pids
69
+ Librato.tracker.config.source_pids
70
+ end
71
+ end
72
+ end
73
+ end
74
+
@@ -0,0 +1,10 @@
1
+ module Librato::Rack::SourcePrefix
2
+ class Railtie < ::Rails::Railtie
3
+
4
+ initializer 'librato.rack.source_prefix.extensions' do
5
+ Librato::Collector.include(
6
+ Librato::Rack::SourcePrefix::Extensions::Collector
7
+ )
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ module Librato
2
+ class Rack
3
+ module SourcePrefix
4
+ VERSION = "0.1.0"
5
+ end
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: librato-rack-source_prefix
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Brian DeHamer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDLjCCAhagAwIBAgIBADANBgkqhkiG9w0BAQUFADA9MQ0wCwYDVQQDDARtYXR0
14
+ MRcwFQYKCZImiZPyLGQBGRYHbGlicmF0bzETMBEGCgmSJomT8ixkARkWA2NvbTAe
15
+ Fw0xNTEwMTIyMjA0MzVaFw0xNjEwMTEyMjA0MzVaMD0xDTALBgNVBAMMBG1hdHQx
16
+ FzAVBgoJkiaJk/IsZAEZFgdsaWJyYXRvMRMwEQYKCZImiZPyLGQBGRYDY29tMIIB
17
+ IjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvfN8RlAsUs+K5kK46SkhpYey
18
+ 54m5bXlGZeqIguOygpG+2FJrUJMCnkQ9RmyK0WUjdmANevW01caQQSx5WatQZso0
19
+ GfJyJfKn4dGecz9LOEPpblw++qapLXr4vbuOlNXsum2gdUFc4/YV9l3csxClMVEq
20
+ +ZUmrHjd2koOvzjK+GDRf3iIozCsgY0oeserZ0li/0qRA5ZJeFwWzs9FO9SXPvID
21
+ Mk07WNaXSRT38llcPGX4L8K+DL7whQwxaFj6IZbobUEtRjzV9v/iP7PiJipijbKB
22
+ EiefgUuolRR38NxQE+f4M/lEqwEpkY/feYMYF6Q4hXVruG3fswjrDGWyiG5nEQID
23
+ AQABozkwNzAJBgNVHRMEAjAAMB0GA1UdDgQWBBR8+l0ZSTbj/TT6YVbFFpdGpg7q
24
+ UDALBgNVHQ8EBAMCBLAwDQYJKoZIhvcNAQEFBQADggEBAKuUiuG2PHv6paQjXjaZ
25
+ LQOsFunScHyhDhPFh/CcCUDbmXVDOJ3WIyDVQuUgK7I3jPEDaSFezSPBpjwZvgMK
26
+ 0/in7pXLRKjI8CzsY8Y4u122DN9tBxLur+E/kv5fpUbf8FGUSuRT5X3wh6ZBTzsZ
27
+ EaMe3LpPFUeMShH/H/FEYrexRvaMHo/52Bg0zP0ySSAQDotm+qgMdru2XRDjE5Ms
28
+ 9BheAnoygGHpoKWtExpsklCppL1q2Xlzw2lhoCMLCSSj9T/YyRTL3UQYoK5pPA76
29
+ hvjx0WJP8pzZMJPKJBRZQXJO5ifEPyKjZyMi5XMHmrtDclHLj3sx4RAvEZjGWkRP
30
+ JSQ=
31
+ -----END CERTIFICATE-----
32
+ date: 2015-12-11 00:00:00.000000000 Z
33
+ dependencies:
34
+ - !ruby/object:Gem::Dependency
35
+ name: librato-rack
36
+ requirement: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ type: :runtime
42
+ prerelease: false
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ - !ruby/object:Gem::Dependency
49
+ name: bundler
50
+ requirement: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.10'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.10'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ type: :development
70
+ prerelease: false
71
+ version_requirements: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ - !ruby/object:Gem::Dependency
77
+ name: minitest
78
+ requirement: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ type: :development
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ description: Applies a source prefix to any custom source names supplied when submitting
91
+ metrics
92
+ email:
93
+ - brian@librato.com
94
+ executables: []
95
+ extensions: []
96
+ extra_rdoc_files: []
97
+ files:
98
+ - CHANGELOG.md
99
+ - LICENSE
100
+ - README.md
101
+ - Rakefile
102
+ - lib/librato-rack-source_prefix.rb
103
+ - lib/librato/rack/source_prefix/extensions/collector.rb
104
+ - lib/librato/rack/source_prefix/railtie.rb
105
+ - lib/librato/rack/source_prefix/version.rb
106
+ homepage: https://github.com/librato/librato-rack-source_prefix
107
+ licenses:
108
+ - BSD 3-clause
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.2.2
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Automatic source prefixing for librato-rack
130
+ test_files: []
Binary file