netflix-spectator-rb 0.1.3 → 0.2.1

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
  SHA256:
3
- metadata.gz: a7fd3c80e6d722432cca59966b94d081ab3c50175fc07e7297d3ada52d55bce9
4
- data.tar.gz: 98fce8bb5978b4a2338dce4a236ee89d2b232820e0f4e605eba9e1f198ebe20d
3
+ metadata.gz: 7461adb6e33f0392ecc42b7752f0c0bd0fb0dc5ab45f14d4415ee95937b08fc4
4
+ data.tar.gz: dc35ff0a6588a74d87b4b2cb8f4ef42118bea937c659c626c4945eea8c795920
5
5
  SHA512:
6
- metadata.gz: 8b396d6dd9f6d0a75af5f807b675758730991c980e84527f1d437383d25c84a8e9ee92986b19d780c0bd4fa95c20a5d245e6a2724e20d96f3b62f1613f048918
7
- data.tar.gz: 3fe4dcf3f86ad2e8d91d0f0bb98b925aa4b0e4838b48cc5fb71436e24a50b4ea746ab8904ec5231e13a714ec28231f6db6be8352b7a55eec57817fd6b871d87a
6
+ metadata.gz: 15a0f31a565eee773ba07d0e36b081b121d982e71f4650d2a2c57b80fc999f7c3c41b129dcd5f9a79f35ffbb4370cc937a98e6fbb9c978f5c524653092bfc93b
7
+ data.tar.gz: 89cccad50469ed909cea9f85a80187053f20431e04ce2a2f942d1f096e11b6c872c9d6033e1f2107c8edacaa76fb865e2f8c705829f7f96e025ec3d989d210f4
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
  *.gem
10
+ Gemfile.lock
data/.travis.yml CHANGED
@@ -1,4 +1,3 @@
1
- sudo: false
2
1
  language: ruby
3
2
  rvm:
4
3
  - 2.5.1
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rake/testtask'
3
5
  require 'rubocop/rake_task'
data/bin/console CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'bundler/setup'
4
5
  require 'spectator'
data/lib/spectator.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spectator/version'
2
4
  require 'spectator/registry'
3
5
  require 'spectator/meter_id'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Spectator
2
4
  # Thread safe number operations
3
5
  class AtomicNumber
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Spectator
2
4
  # A timing source that can be used to access the current time as an object,
3
5
  # and a high resolution monotonic time
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spectator/atomic_number'
2
4
  require 'spectator/measure'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spectator/atomic_number'
2
4
 
3
5
  module Spectator
@@ -19,7 +21,8 @@ module Spectator
19
21
 
20
22
  # Update the statistics kept by the summary with the specified amount.
21
23
  def record(amount)
22
- return if amount < 0
24
+ return if amount.negative?
25
+
23
26
  @count.add_and_get(1)
24
27
  @total_amount.add_and_get(amount)
25
28
  @total_sq.add_and_get(amount * amount)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spectator/atomic_number'
2
4
  require 'spectator/measure'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'json'
2
4
  require 'net/http'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Spectator
2
4
  # This immutable class represents a measurement sampled from a meter
3
5
  class Measure
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Spectator
2
4
  # Identifier for a meter or Measure
3
5
  class MeterId
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spectator/clock'
2
4
  require 'spectator/counter'
3
5
  require 'spectator/distribution_summary'
@@ -9,7 +11,9 @@ require 'spectator/timer'
9
11
  module Spectator
10
12
  # Registry to manage a set of meters
11
13
  class Registry
12
- attr_reader :config, :clock, :publisher, :common_tags
14
+ DEFAULT_BATCH_SIZE = 10_000
15
+
16
+ attr_reader :config, :clock, :publisher, :common_tags, :batch_size
13
17
 
14
18
  # Initialize the registry using the given config, and clock
15
19
  # The default clock is the SystemClock
@@ -20,7 +24,7 @@ module Spectator
20
24
  # :uri the endpoint for the aggregator service
21
25
  def initialize(config, clock = SystemClock.new)
22
26
  @config = config
23
- @batch_size = config[:batch_size] || 10_000
27
+ @batch_size = config[:batch_size] || DEFAULT_BATCH_SIZE
24
28
  @clock = clock
25
29
  @meters = {}
26
30
  @common_tags = to_symbols(config[:common_tags]) || {}
@@ -163,7 +167,7 @@ module Spectator
163
167
 
164
168
  @should_stop = true
165
169
  Spectator.logger.info('Stopping spectator')
166
- @publish_thread.kill if @publish_thread
170
+ @publish_thread&.kill
167
171
 
168
172
  @started = false
169
173
  Spectator.logger.info('Sending last batch of metrics before exiting')
@@ -172,31 +176,27 @@ module Spectator
172
176
 
173
177
  ADD_OP = 0
174
178
  MAX_OP = 10
175
- UNKNOWN_OP = -1
176
- OPS = { count: ADD_OP,
177
- totalAmount: ADD_OP,
178
- totalTime: ADD_OP,
179
- totalOfSquares: ADD_OP,
180
- percentile: ADD_OP,
181
- max: MAX_OP,
182
- gauge: MAX_OP,
183
- activeTasks: MAX_OP,
184
- duration: MAX_OP }.freeze
179
+ COUNTER_STATS = %i[count totalAmount totalTime
180
+ totalOfSquares percentile].freeze
181
+
185
182
  # Get the operation to be used for the given Measure
186
183
  # Gauges are aggregated using MAX_OP, counters with ADD_OP
187
184
  def op_for_measurement(measure)
188
- stat = measure.id.tags.fetch(:statistic, :unknown)
189
- OPS.fetch(stat, UNKNOWN_OP)
185
+ stat = measure.id.tags.fetch(:statistic, '')
186
+ if COUNTER_STATS.include? stat
187
+ ADD_OP
188
+ else
189
+ MAX_OP
190
+ end
190
191
  end
191
192
 
192
193
  # Gauges are sent if they have a value
193
194
  # Counters if they have a number of increments greater than 0
194
195
  def should_send(measure)
195
196
  op = op_for_measurement(measure)
196
- return measure.value > 0 if op == ADD_OP
197
- return !measure.value.nan? if op == MAX_OP
197
+ return measure.value.positive? if op == ADD_OP
198
198
 
199
- false
199
+ !measure.value.nan?
200
200
  end
201
201
 
202
202
  # Build a string table from the list of measurements
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spectator/atomic_number'
2
4
  require 'spectator/clock'
3
5
 
@@ -20,7 +22,8 @@ module Spectator
20
22
  # Update the statistics kept by this timer. If the amount of nanoseconds
21
23
  # passed is negative, the value will be ignored.
22
24
  def record(nanos)
23
- return if nanos < 0
25
+ return if nanos.negative?
26
+
24
27
  @count.add_and_get(1)
25
28
  @total_time.add_and_get(nanos)
26
29
  @total_sq.add_and_get(nanos * nanos)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Spectator
2
- VERSION = '0.1.3'.freeze
4
+ VERSION = '0.2.1'
3
5
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
@@ -23,7 +24,7 @@ Gem::Specification.new do |spec|
23
24
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
25
  spec.require_paths = ['lib']
25
26
 
26
- spec.add_development_dependency 'bundler', '~> 1.16'
27
+ spec.add_development_dependency 'bundler', '~> 2.0'
27
28
  spec.add_development_dependency 'minitest', '~> 5.0'
28
29
  spec.add_development_dependency 'rake', '~> 10.0'
29
30
  spec.add_development_dependency 'rubocop', '~> 0.55'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: netflix-spectator-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Muino
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-10-05 00:00:00.000000000 Z
11
+ date: 2019-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.16'
19
+ version: '2.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.16'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -78,7 +78,6 @@ files:
78
78
  - ".rubocop.yml"
79
79
  - ".travis.yml"
80
80
  - Gemfile
81
- - Gemfile.lock
82
81
  - LICENSE
83
82
  - OSSMETADATA
84
83
  - README.md
data/Gemfile.lock DELETED
@@ -1,46 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- netflix-spectator-rb (0.1.3)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- ast (2.4.0)
10
- docile (1.3.0)
11
- json (2.1.0)
12
- minitest (5.11.3)
13
- parallel (1.12.1)
14
- parser (2.5.1.0)
15
- ast (~> 2.4.0)
16
- powerpack (0.1.1)
17
- rainbow (3.0.0)
18
- rake (10.5.0)
19
- rubocop (0.55.0)
20
- parallel (~> 1.10)
21
- parser (>= 2.5)
22
- powerpack (~> 0.1)
23
- rainbow (>= 2.2.2, < 4.0)
24
- ruby-progressbar (~> 1.7)
25
- unicode-display_width (~> 1.0, >= 1.0.1)
26
- ruby-progressbar (1.9.0)
27
- simplecov (0.16.1)
28
- docile (~> 1.1)
29
- json (>= 1.8, < 3)
30
- simplecov-html (~> 0.10.0)
31
- simplecov-html (0.10.2)
32
- unicode-display_width (1.3.2)
33
-
34
- PLATFORMS
35
- ruby
36
-
37
- DEPENDENCIES
38
- bundler (~> 1.16)
39
- minitest (~> 5.0)
40
- netflix-spectator-rb!
41
- rake (~> 10.0)
42
- rubocop (~> 0.55)
43
- simplecov
44
-
45
- BUNDLED WITH
46
- 1.16.1