hosted_graphite 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: 5a96d4721686e9b29cded57b6624a05bec73484c
4
- data.tar.gz: e2350801a97eb3b09b97e2ea36e8c97241fd4463
3
+ metadata.gz: 4272720da2d9eb6e32be3a43dd1b7188fc363550
4
+ data.tar.gz: e12ca2cb51e10288ccf138740f3541f7fbad908d
5
5
  SHA512:
6
- metadata.gz: 9f6f7351e6d2be3135e9a6f88772e6e3c5d81d1fb71baffa8558f5b4404ea7d4a3592f380b38e93f505013272220f574d0e69ae33c5fecdb97fea05b67d2106d
7
- data.tar.gz: 4c93fd58f0c53687a8165f337eb532c404c4c132b54c8862eae29dbabad6ca06b7ebdfb19f602281ccf09b6c4b23dffd263a01b221fad703513d708dfbfde91d
6
+ metadata.gz: 7d6779726beaaeac6d344c0f26846d087a1d3cefc59884a01d5dc41a3ac427a921f6e08349c69c70c7b303a4106153f545180a879df6bb17a5b47882eebb7c17
7
+ data.tar.gz: '048f1ff89f556e12537c6b421d8cce685b31d5adfdf914de1dfd7d54605309dcd77f54de56f9c5d048ec7b0053c8308f8e42dfd07d87d08b23ea0acc2b8c72e2'
@@ -1,9 +1,11 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.3.1
4
- - 2.2
3
+ - 2.3.3
4
+ - 2.2.5
5
5
  - 2.1
6
6
  - 2.0.0
7
- - 1.9.3
8
- - jruby-19mode
9
- - rbx-2
7
+ - ruby-head
8
+
9
+ matrix:
10
+ allow_failures:
11
+ - rvm: ruby-head
@@ -1 +1,5 @@
1
- 1.0.1 : Add sidekiq extension
1
+ * 0.2.0 :
2
+ * Added flag to enable metric sending #16
3
+ * Added namespace for statsd #15
4
+ * Remove unsupported version of ruby
5
+ * 0.1.1 : Add sidekiq extension
data/README.md CHANGED
@@ -32,10 +32,16 @@ Your API key can be found on your [account home](https://www.hostedgraphite.com/
32
32
 
33
33
  You can also set the hosted graphite API key programatically with:
34
34
 
35
- ```bash
35
+ ```ruby
36
36
  HostedGraphite.api_key = 'YOUR API KEY'
37
37
  ```
38
38
 
39
+ You may also specify a namespace for your metrics, which will be applied if you are using the StatsD backend:
40
+
41
+ ```bash
42
+ HostedGraphite.namespace = 'our_app'
43
+ ```
44
+
39
45
  #### Sending a metric via UDP
40
46
  ```ruby
41
47
  HostedGraphite.protocol = :udp
@@ -81,17 +87,23 @@ HostedGraphite.time('newsletter.monthly') { @newsletter.deliver_now }
81
87
 
82
88
  ### Extensions
83
89
  #### Sidekiq
84
- ```ruby
85
- require 'hosted_graphite/ext/sidekiq'
86
-
87
- Sidekiq.configure_server do |config|
88
- config.server_middleware do |chain|
89
- # my_app is an optional namespace
90
- # chain.prepend HostedGraphite::Ext::Sidekiq::StatsdMetrics, 'my_app'
91
- # or
92
- # chain.prepend HostedGraphite::Ext::Sidekiq::Metrics
93
- end
90
+ ```ruby
91
+ require 'hosted_graphite/ext/sidekiq'
92
+
93
+ Sidekiq.configure_server do |config|
94
+ config.server_middleware do |chain|
95
+ # my_app is an optional namespace
96
+ # chain.prepend HostedGraphite::Ext::Sidekiq::StatsdMetrics, 'my_app'
97
+ # or
98
+ # chain.prepend HostedGraphite::Ext::Sidekiq::Metrics
94
99
  end
100
+ end
101
+ ```
102
+
103
+ ### Disable sends for local/test environments
104
+
105
+ ```ruby
106
+ HostedGraphite.enabled = false unless Rails.env.production?
95
107
  ```
96
108
 
97
109
  ## Contributing
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.summary = 'A Ruby client for HostedGraphite'
11
11
  spec.homepage = 'https://github.com/seuros/hosted_graphite'
12
12
  spec.license = 'Apache 2.0'
13
- spec.required_ruby_version = '>= 1.9.3'
13
+ spec.required_ruby_version = '>= 2.0.0'
14
14
 
15
15
  spec.files = `git ls-files -z`.split("\x0")
16
16
  spec.test_files = spec.files.grep(%r{^(test)/})
@@ -6,11 +6,10 @@ require 'hosted_graphite/protocol'
6
6
  module HostedGraphite
7
7
  extend Forwardable
8
8
  extend self
9
- attr_reader :namespace, :protocol
10
- attr_writer :namespace, :api_key
11
9
 
12
- def_delegators :protocol, :send_metric
13
- module_function :send_metric
10
+ attr_accessor :namespace, :enabled
11
+ attr_reader :protocol
12
+ attr_writer :api_key
14
13
 
15
14
  class MissingAPIKey < StandardError
16
15
  def initialize
@@ -22,14 +21,25 @@ module HostedGraphite
22
21
  @api_key ||= ENV['HOSTEDGRAPHITE_APIKEY']
23
22
  end
24
23
 
25
- def protocol=(protocol)
24
+ def enabled?
25
+ @enabled.nil? ? true : @enabled
26
+ end
27
+
28
+ def send_metric(*args)
29
+ protocol.send_metric(*args) if enabled?
30
+ end
31
+ module_function :send_metric
32
+
33
+ def protocol=(protocol)
26
34
  protocol = protocol.to_s.downcase
27
35
  require "hosted_graphite/protocols/#{protocol}"
28
36
  @protocol = @registred_protocols[protocol].new
29
- end
37
+ end
30
38
 
31
39
  @registred_protocols = {}
32
- private def register(name, klass)
40
+ private
41
+
42
+ def register(name, klass)
33
43
  @registred_protocols[name] = klass
34
44
  end
35
45
  end
@@ -12,7 +12,11 @@ module HostedGraphite
12
12
  def initialize
13
13
  raise MissingAPIKey unless HostedGraphite.api_key
14
14
  super(HOST, PORT)
15
- self.namespace = [HostedGraphite.api_key,HostedGraphite.namespace].join('.')
15
+ if HostedGraphite.namespace
16
+ self.namespace = [HostedGraphite.api_key,HostedGraphite.namespace].join('.')
17
+ else
18
+ self.namespace = HostedGraphite.api_key
19
+ end
16
20
  end
17
21
  end
18
22
 
@@ -1 +1 @@
1
- HostedGraphite.protocol = :stastd
1
+ HostedGraphite.protocol = :statsd
@@ -1,3 +1,3 @@
1
1
  module HostedGraphite
2
- VERSION = '0.1.1'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -0,0 +1,35 @@
1
+ require_relative 'helper'
2
+
3
+ class DefaultBehaviourTest < Minitest::Test
4
+ def setup
5
+ HostedGraphite.protocol = :http
6
+ end
7
+
8
+ def test_enabled_by_default
9
+ assert_equal true, HostedGraphite.enabled?
10
+ end
11
+
12
+ def test_send_by_default
13
+ assert_send [HostedGraphite.protocol, :send_metric, *['foo', 1.2]]
14
+ HostedGraphite.send_metric 'foo', 1.2
15
+ end
16
+ end
17
+
18
+
19
+ class DisabledTest < Minitest::Test
20
+ def setup
21
+ @previous_api_key = HostedGraphite.api_key
22
+ HostedGraphite.api_key = nil
23
+ HostedGraphite.enabled = false
24
+ end
25
+
26
+ def teardown
27
+ HostedGraphite.enabled = nil
28
+ HostedGraphite.api_key = @previous_api_key
29
+ end
30
+
31
+ def test_metric_send
32
+ # Will raise HostedGraphite::MissingAPIKey if incorrect
33
+ HostedGraphite.send_metric 'foo', 1.2
34
+ end
35
+ end
@@ -28,4 +28,22 @@ class StatsDTest < Minitest::Test
28
28
  def test_respond_to_increment
29
29
  assert_respond_to HostedGraphite, :increment
30
30
  end
31
+
32
+ def test_initialize_without_namespace
33
+ old_namespace = HostedGraphite.namespace
34
+ HostedGraphite.namespace = nil
35
+
36
+ assert_equal HostedGraphite.api_key, HostedGraphite::STATSD.new.namespace
37
+
38
+ HostedGraphite.namespace = old_namespace
39
+ end
40
+
41
+ def test_initialize_with
42
+ old_namespace = HostedGraphite.namespace
43
+ HostedGraphite.namespace = "foo"
44
+
45
+ assert_equal "#{HostedGraphite.api_key}.foo", HostedGraphite::STATSD.new.namespace
46
+
47
+ HostedGraphite.namespace = old_namespace
48
+ end
31
49
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hosted_graphite
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
  - Abdelkader Boudih
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-23 00:00:00.000000000 Z
11
+ date: 2016-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,7 @@ files:
80
80
  - lib/hosted_graphite/testing.rb
81
81
  - lib/hosted_graphite/version.rb
82
82
  - test/helper.rb
83
+ - test/test_enabling.rb
83
84
  - test/test_http_protocol.rb
84
85
  - test/test_missing_apikey.rb
85
86
  - test/test_stastd.rb
@@ -97,7 +98,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
97
98
  requirements:
98
99
  - - ">="
99
100
  - !ruby/object:Gem::Version
100
- version: 1.9.3
101
+ version: 2.0.0
101
102
  required_rubygems_version: !ruby/object:Gem::Requirement
102
103
  requirements:
103
104
  - - ">="
@@ -105,12 +106,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
106
  version: '0'
106
107
  requirements: []
107
108
  rubyforge_project:
108
- rubygems_version: 2.5.1
109
+ rubygems_version: 2.5.2
109
110
  signing_key:
110
111
  specification_version: 4
111
112
  summary: A Ruby client for HostedGraphite
112
113
  test_files:
113
114
  - test/helper.rb
115
+ - test/test_enabling.rb
114
116
  - test/test_http_protocol.rb
115
117
  - test/test_missing_apikey.rb
116
118
  - test/test_stastd.rb