formatted-metrics 1.0.4 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f7edd948c0f2e561a7fba319c15f4708f92cf24e
4
+ data.tar.gz: 74220cfe25a93832000aa8620090508f99fef40d
5
+ SHA512:
6
+ metadata.gz: f45582f1080e61c61ae1fd9db73f7c972f17b4c31fb887f95a2bcd3600283f2c0308c53618e4582bad08f3d18899d98dd2b3a5e14904eca772bb5f02eaf51f74
7
+ data.tar.gz: bdf3c63a206664ae884c2fd714faa630a95fe8211a1b32e523a62849fed5974c2b32935225d7a73af97d4a86a75464d2a379e7805c4fbc419ab7ee0e9b4fee1b
data/.travis.yml CHANGED
@@ -2,6 +2,4 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
- - jruby-19mode
6
- - rbx-19mode
7
5
  script: bundle exec rake
@@ -1,16 +1,14 @@
1
1
  module Metrics::Formatters
2
- PRECISION = 3
2
+ PRECISION = 3.freeze
3
3
 
4
4
  class L2Met < Base
5
5
  # Example
6
6
  # source=web.2 sample#load_avg_1m=0.31 sample#load_avg_5m=0.10 sample#load_avg_15m=0.05
7
7
  def lines
8
8
  groups.map do |source, instrumenters|
9
- [
10
- "source=#{full_source(source)}",
11
- instrumenters.map { |instrumenter| measurement(instrumenter) }.join(' ')
12
- ].flatten.join(' ')
13
- end
9
+ measurements = instrumenters.map { |instrumenter| measurement(instrumenter) }
10
+ Lines.new(full_source(source), measurements).lines
11
+ end.flatten
14
12
  end
15
13
 
16
14
  private
@@ -34,5 +32,51 @@ module Metrics::Formatters
34
32
  def blank?(string)
35
33
  string.nil? || string.empty?
36
34
  end
35
+
36
+ # Responsible for taking a prefix, and an array of measurements, and
37
+ # returning an array of log lines that are limited to 1024 characters per
38
+ # line.
39
+ class Lines
40
+ include Enumerable
41
+
42
+ MAX_LEN = 1024.freeze
43
+ DELIMITER = ' '.freeze
44
+
45
+ attr_reader :source
46
+ attr_reader :measurements
47
+ attr_reader :max
48
+
49
+ def initialize(source, measurements)
50
+ @source = "source=#{source}"
51
+ @measurements = measurements
52
+ @max = MAX_LEN - @source.length + DELIMITER.length * 2
53
+ end
54
+
55
+ def each(&block)
56
+ measurements.each(&block)
57
+ end
58
+
59
+ # Groups the array of measurements into an array of log lines, each line
60
+ # prefixed with the source.
61
+ #
62
+ # Example
63
+ #
64
+ # # This:
65
+ # ['measure#rack.request=1', ..., 'measure#rack.request.time=200ms']
66
+ #
67
+ # # Into this:
68
+ # ['source=app measure#rack.request=1', 'source=app measure#rack.request.time=200ms', ...]
69
+ #
70
+ # Returns an Array.
71
+ def lines
72
+ total = 0
73
+ chunk { |measurement|
74
+ total += measurement.length + DELIMITER.length * 2
75
+ total / max
76
+ }.map { |_, line|
77
+ [source, line].join(DELIMITER)
78
+ }
79
+ end
80
+ end
37
81
  end
38
82
  end
@@ -1,3 +1,3 @@
1
1
  module FormattedMetrics
2
- VERSION = '1.0.4'
2
+ VERSION = '1.1.0'
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ require 'securerandom'
2
3
 
3
4
  describe Metrics::Formatters::L2Met do
4
5
  let(:formatter) { described_class.new *instrumenters }
@@ -12,7 +13,7 @@ describe Metrics::Formatters::L2Met do
12
13
  end
13
14
 
14
15
  describe '.lines' do
15
- subject(:format) { formatter.lines }
16
+ subject(:lines) { formatter.lines }
16
17
 
17
18
  context 'with a single instrumenter' do
18
19
  let(:instrumenters) { [ instrumenter(metric: 'rack.request.time', value: 10.3333, units: 'ms', type: 'sample') ] }
@@ -37,5 +38,17 @@ describe Metrics::Formatters::L2Met do
37
38
 
38
39
  it { should eq ['source=app sample#rack.request.time=10ms', 'source=app.foo count#jobs.queued=15jobs count#jobs.busy=10jobs'] }
39
40
  end
41
+
42
+ context 'with lots of metrics from the same source' do
43
+ let(:instrumenters) do
44
+ 100.times.map { instrumenter(metric: SecureRandom.hex, value: rand(100), units: 'ms', type: 'sample') }
45
+ end
46
+
47
+ it 'limits each line to 1024 characters' do
48
+ lines.each do |line|
49
+ expect(line.length).to be < 1024
50
+ end
51
+ end
52
+ end
40
53
  end
41
54
  end
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formatted-metrics
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
5
- prerelease:
4
+ version: 1.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Eric J. Holmes
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-09-26 00:00:00.000000000 Z
11
+ date: 2013-12-20 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bundler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,23 +27,20 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rspec
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ~>
60
53
  - !ruby/object:Gem::Version
@@ -97,33 +90,26 @@ files:
97
90
  homepage: http://github.com/remind101/formatted-metrics
98
91
  licenses:
99
92
  - MIT
93
+ metadata: {}
100
94
  post_install_message:
101
95
  rdoc_options: []
102
96
  require_paths:
103
97
  - lib
104
98
  required_ruby_version: !ruby/object:Gem::Requirement
105
- none: false
106
99
  requirements:
107
- - - ! '>='
100
+ - - '>='
108
101
  - !ruby/object:Gem::Version
109
102
  version: '0'
110
- segments:
111
- - 0
112
- hash: -116079147036176157
113
103
  required_rubygems_version: !ruby/object:Gem::Requirement
114
- none: false
115
104
  requirements:
116
- - - ! '>='
105
+ - - '>='
117
106
  - !ruby/object:Gem::Version
118
107
  version: '0'
119
- segments:
120
- - 0
121
- hash: -116079147036176157
122
108
  requirements: []
123
109
  rubyforge_project:
124
- rubygems_version: 1.8.23
110
+ rubygems_version: 2.0.3
125
111
  signing_key:
126
- specification_version: 3
112
+ specification_version: 4
127
113
  summary: Easily output formatted metrics to stdout
128
114
  test_files:
129
115
  - spec/metrics/formatters/l2met_spec.rb