wavefront-sdk 1.6.0 → 1.6.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- WF_SDK_VERSION = '1.6.0'.freeze
1
+ WF_SDK_VERSION = '1.6.1'.freeze
@@ -26,7 +26,6 @@ module Wavefront
26
26
  # Open a socket to a Wavefront proxy, putting the descriptor
27
27
  # in instance variable @sock.
28
28
  #
29
- # rubocop:disable Metrics/MethodLength
30
29
  def open
31
30
  if opts[:noop]
32
31
  log('No-op requested. Not opening connection to proxy.')
@@ -0,0 +1,82 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../../lib/wavefront-sdk/base_write.rb'
4
+ require_relative '../spec_helper'
5
+ require_relative 'resources/dummy_points'
6
+
7
+ # rubocop:disable Style/MutableConstant
8
+ WBWT_CREDS = { endpoint: 'stub.wavefront.com', token: 'tkn' }
9
+ # rubocop:enable Style/MutableConstant
10
+
11
+ class WavefrontBaseWriteTest < MiniTest::Test
12
+ attr_reader :wf, :wf_tags
13
+
14
+ def setup
15
+ @wf = Wavefront::BaseWrite.new(WBWT_CREDS)
16
+ # @wf_noop = Wavefront::Write.new(W_CREDS, noop: true)
17
+ @wf_tags = Wavefront::BaseWrite.new(WBWT_CREDS, tags: TAGS)
18
+ end
19
+
20
+ def test_summary_string
21
+ assert_equal('OK', wf.summary_string(unsent: 0, rejected: 0))
22
+ assert_equal('ERROR', wf.summary_string(unsent: 0, rejected: 1))
23
+ assert_equal('ERROR', wf.summary_string(unsent: 1, rejected: 0))
24
+ end
25
+
26
+ def test_prepped_points
27
+ assert_equal wf.prepped_points(%w[p1 p2 p3 p4]), %w[p1 p2 p3 p4]
28
+ assert_equal wf.prepped_points([%w[p1 p2 p3 p4]]), %w[p1 p2 p3 p4]
29
+ assert_equal wf.prepped_points('p1'), %w[p1]
30
+ assert_equal wf.prepped_points(
31
+ [{ path: 'p1' }, { path: 'p2' }, { path: 'p3' }], 'prefix'
32
+ ),
33
+ [{ path: 'prefix.p1' }, { path: 'prefix.p2' },
34
+ { path: 'prefix.p3' }]
35
+
36
+ assert_equal wf.prepped_points({ path: 'p1' }, 'prefix'),
37
+ [{ path: 'prefix.p1' }]
38
+ end
39
+
40
+ def test_paths_to_deltas
41
+ x = wf.paths_to_deltas(POINTS.dup)
42
+ assert_equal(x.size, 2)
43
+
44
+ x.each do |p|
45
+ assert_instance_of(Hash, p)
46
+ assert(p[:path].start_with?(DELTA))
47
+ end
48
+ end
49
+
50
+ def test_hash_to_wf
51
+ assert_equal(wf.hash_to_wf(POINT),
52
+ 'test.metric 123456 1469987572 ' \
53
+ 'source=testhost t1="v1" t2="v2"')
54
+ assert_equal(wf_tags.hash_to_wf(POINT),
55
+ 'test.metric 123456 1469987572 ' \
56
+ 'source=testhost t1="v1" t2="v2" ' \
57
+ 'gt1="gv1" gt2="gv2"')
58
+
59
+ p1 = POINT.dup
60
+ p1.delete(:ts)
61
+ assert_equal(wf.hash_to_wf(p1),
62
+ 'test.metric 123456 source=testhost t1="v1" t2="v2"')
63
+
64
+ p2 = POINT.dup
65
+ p2.delete(:tags)
66
+ assert_equal(wf.hash_to_wf(p2),
67
+ 'test.metric 123456 1469987572 source=testhost')
68
+
69
+ %i[value path].each do |k|
70
+ p3 = POINT.dup
71
+ p3.delete(k)
72
+
73
+ assert_raises(Wavefront::Exception::InvalidPoint) do
74
+ wf.hash_to_wf(p3)
75
+ end
76
+
77
+ assert_raises(Wavefront::Exception::InvalidPoint) do
78
+ wf_tags.hash_to_wf(p3)
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'logger'
4
+ require_relative '../spec_helper'
5
+ require_relative '../../lib/wavefront-sdk/logger'
6
+
7
+ # Test SDK logger class
8
+ #
9
+ class WavefrontLoggerTest < MiniTest::Test
10
+ attr_reader :wfl
11
+
12
+ def setup
13
+ @wfl = Wavefront::Logger.new
14
+ end
15
+
16
+ def test_format_message
17
+ assert_equal('SDK INFO: some text', wfl.format_message(:info,
18
+ 'some text'))
19
+ end
20
+
21
+ def test_log_no_logger_debug
22
+ l = Wavefront::Logger.new(debug: true)
23
+ assert_output("SDK DEBUG: my message\n") { l.log('my message', :debug) }
24
+ assert_output("SDK INFO: my message\n") { l.log('my message', :info) }
25
+ out, err = capture_io { l.log('my message', :error) }
26
+ assert_equal("SDK ERROR: my message\n", err)
27
+ assert_empty(out)
28
+ end
29
+
30
+ def test_log_no_logger_no_debug
31
+ l = Wavefront::Logger.new(debug: false, verbose: false)
32
+ assert_silent { l.log('my message', :debug) }
33
+ assert_output("SDK INFO: my message\n") { l.log('my message', :info) }
34
+ out, err = capture_io { l.log('my message', :error) }
35
+ assert_equal("SDK ERROR: my message\n", err)
36
+ assert_empty(out)
37
+ out, err = capture_io { l.log('my message', :warn) }
38
+ assert_equal("SDK WARN: my message\n", err)
39
+ assert_empty(out)
40
+ end
41
+
42
+ def test_log_logger_debug
43
+ l = Wavefront::Logger.new(logger: Logger.new(STDOUT))
44
+ out, err = capture_subprocess_io { l.log('my message', :debug) }
45
+ assert_match(/DEBUG -- : my message$/, out)
46
+ assert_empty(err)
47
+ end
48
+
49
+ def test_log_logger_info
50
+ l = Wavefront::Logger.new(logger: Logger.new(STDOUT))
51
+ out, err = capture_subprocess_io { l.log('my message', :info) }
52
+ assert_match(/INFO -- : my message$/, out)
53
+ assert_empty(err)
54
+ end
55
+
56
+ def test_log_logger_error
57
+ l = Wavefront::Logger.new(logger: Logger.new(STDOUT))
58
+ out, err = capture_subprocess_io { l.log('my message', :error) }
59
+ assert_match(/ERROR -- : my message$/, out)
60
+ assert_empty(err)
61
+ end
62
+ end
@@ -55,6 +55,23 @@ class WavefrontMixinsTest < MiniTest::Test
55
55
  end
56
56
  end
57
57
 
58
+ def test_valid_relative_time?
59
+ assert valid_relative_time?('+1h')
60
+ assert valid_relative_time?('+1m')
61
+ assert valid_relative_time?('-1s')
62
+ assert valid_relative_time?('-10d')
63
+ assert valid_relative_time?('+1.3h')
64
+ assert valid_relative_time?('+1h')
65
+ assert valid_relative_time?('-1h')
66
+ assert valid_relative_time?('-1.142w')
67
+ assert valid_relative_time?('+0.002y')
68
+ refute valid_relative_time?('1h')
69
+ refute valid_relative_time?('1m')
70
+ refute valid_relative_time?('-1t')
71
+ refute valid_relative_time?('-dd')
72
+ refute valid_relative_time?('-1.1.1d')
73
+ end
74
+
58
75
  def test_parse_relative_time
59
76
  assert_equal parse_relative_time('-5s'), -5
60
77
  assert_equal parse_relative_time('-5s', true), -5000
@@ -0,0 +1,20 @@
1
+ # Constants used in the write tests
2
+ #
3
+ TAGS = { gt1: 'gv1', gt2: 'gv2' }.freeze
4
+
5
+ POINT = { path: 'test.metric',
6
+ value: 123_456,
7
+ ts: 1_469_987_572,
8
+ source: 'testhost',
9
+ tags: { t1: 'v1', t2: 'v2' } }.freeze
10
+
11
+ POINT_L = 'test.metric 123456 1469987572 source=testhost t1="v1" ' \
12
+ 't2="v2"'.freeze
13
+
14
+ POINT_A = [POINT,
15
+ POINT.dup.update(ts: 1_469_987_588, value: 54_321)].freeze
16
+
17
+ POINTS = [POINT.dup, { path: 'test.other_metric',
18
+ value: 89,
19
+ ts: 1_469_987_572,
20
+ source: 'otherhost' }].freeze
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require_relative '../../lib/wavefront-sdk/write.rb'
4
+ require_relative 'resources/dummy_points'
4
5
  require 'minitest/autorun'
5
6
  require 'webmock/minitest'
6
7
  require 'spy'
@@ -9,26 +10,6 @@ require 'socket'
9
10
 
10
11
  W_CREDS = { proxy: 'wavefront', port: 2878 }.freeze
11
12
 
12
- TAGS = { gt1: 'gv1', gt2: 'gv2' }.freeze
13
-
14
- POINT = { path: 'test.metric',
15
- value: 123_456,
16
- ts: 1_469_987_572,
17
- source: 'testhost',
18
- tags: { t1: 'v1', t2: 'v2' } }.freeze
19
-
20
- POINT_L = 'test.metric 123456 1469987572 source=testhost t1="v1" t2="v2"'.freeze
21
-
22
- POINT_A = [
23
- POINT, POINT.dup.update(ts: 1_469_987_588, value: 54_321)
24
- ].freeze
25
-
26
- POINTS = [POINT.dup,
27
- { path: 'test.other_metric',
28
- value: 89,
29
- ts: 1_469_987_572,
30
- source: 'otherhost' }].freeze
31
-
32
13
  # This class is sufficiently different to the API calling classes
33
14
  # that it doesn't use spec helper or inherit anything.
34
15
  #
@@ -85,20 +66,6 @@ class WavefrontWriteTest < MiniTest::Test
85
66
  assert mocket_spy.has_been_called?
86
67
  end
87
68
 
88
- def test_prepped_points
89
- assert_equal wf.prepped_points(%w[p1 p2 p3 p4]), %w[p1 p2 p3 p4]
90
- assert_equal wf.prepped_points([%w[p1 p2 p3 p4]]), %w[p1 p2 p3 p4]
91
- assert_equal wf.prepped_points('p1'), %w[p1]
92
- assert_equal wf.prepped_points(
93
- [{ path: 'p1' }, { path: 'p2' }, { path: 'p3' }], 'prefix'
94
- ),
95
- [{ path: 'prefix.p1' }, { path: 'prefix.p2' },
96
- { path: 'prefix.p3' }]
97
-
98
- assert_equal wf.prepped_points({ path: 'p1' }, 'prefix'),
99
- [{ path: 'prefix.p1' }]
100
- end
101
-
102
69
  def test_write_array
103
70
  mocket = Mocket.new
104
71
  Spy.on(TCPSocket, :new).and_return(mocket)
@@ -108,55 +75,12 @@ class WavefrontWriteTest < MiniTest::Test
108
75
  assert mocket_spy.has_been_called?
109
76
  end
110
77
 
111
- def test_paths_to_deltas
112
- x = wf.paths_to_deltas(POINTS.dup)
113
- assert_equal(x.size, 2)
114
-
115
- x.each do |p|
116
- assert_instance_of(Hash, p)
117
- assert(p[:path].start_with?(DELTA))
118
- end
119
- end
120
-
121
- def test_hash_to_wf
122
- assert_equal(wf.hash_to_wf(POINT),
123
- 'test.metric 123456 1469987572 ' \
124
- 'source=testhost t1="v1" t2="v2"')
125
- assert_equal(wf_tags.hash_to_wf(POINT),
126
- 'test.metric 123456 1469987572 ' \
127
- 'source=testhost t1="v1" t2="v2" ' \
128
- 'gt1="gv1" gt2="gv2"')
129
-
130
- p1 = POINT.dup
131
- p1.delete(:ts)
132
- assert_equal(wf.hash_to_wf(p1),
133
- 'test.metric 123456 source=testhost t1="v1" t2="v2"')
134
-
135
- p2 = POINT.dup
136
- p2.delete(:tags)
137
- assert_equal(wf.hash_to_wf(p2),
138
- 'test.metric 123456 1469987572 source=testhost')
139
-
140
- %i[value path].each do |k|
141
- p3 = POINT.dup
142
- p3.delete(k)
143
-
144
- assert_raises(Wavefront::Exception::InvalidPoint) do
145
- wf.hash_to_wf(p3)
146
- end
147
-
148
- assert_raises(Wavefront::Exception::InvalidPoint) do
149
- wf_tags.hash_to_wf(p3)
150
- end
151
- end
152
- end
153
-
154
- def test_send_point
78
+ def test_really_send_point
155
79
  mocket = Mocket.new
156
80
  Spy.on(TCPSocket, :new).and_return(mocket)
157
81
  mocket_spy = Spy.on(mocket, :puts)
158
82
  wf.open
159
- wf.send_point(POINT_L)
83
+ wf.really_send_point(POINT_L)
160
84
  assert mocket_spy.has_been_called_with?(POINT_L)
161
85
  end
162
86
 
@@ -37,3 +37,4 @@ Gem::Specification.new do |gem|
37
37
 
38
38
  gem.required_ruby_version = Gem::Requirement.new('>= 2.2.0')
39
39
  end
40
+ # rubocop:enable Metrics/BlockLength:
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wavefront-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Fisher
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-07 00:00:00.000000000 Z
11
+ date: 2018-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -205,6 +205,7 @@ files:
205
205
  - lib/wavefront-sdk/exception.rb
206
206
  - lib/wavefront-sdk/externallink.rb
207
207
  - lib/wavefront-sdk/integration.rb
208
+ - lib/wavefront-sdk/logger.rb
208
209
  - lib/wavefront-sdk/maintenancewindow.rb
209
210
  - lib/wavefront-sdk/message.rb
210
211
  - lib/wavefront-sdk/metric.rb
@@ -232,6 +233,7 @@ files:
232
233
  - spec/spec_helper.rb
233
234
  - spec/wavefront-sdk/alert_spec.rb
234
235
  - spec/wavefront-sdk/base_spec.rb
236
+ - spec/wavefront-sdk/base_write_spec.rb
235
237
  - spec/wavefront-sdk/cloudintegration_spec.rb
236
238
  - spec/wavefront-sdk/credentials_spec.rb
237
239
  - spec/wavefront-sdk/dashboard_spec.rb
@@ -239,6 +241,7 @@ files:
239
241
  - spec/wavefront-sdk/event_spec.rb
240
242
  - spec/wavefront-sdk/externallink_spec.rb
241
243
  - spec/wavefront-sdk/integration_spec.rb
244
+ - spec/wavefront-sdk/logger_spec.rb
242
245
  - spec/wavefront-sdk/maintenancewindow_spec.rb
243
246
  - spec/wavefront-sdk/message_spec.rb
244
247
  - spec/wavefront-sdk/metric_spec.rb
@@ -248,6 +251,7 @@ files:
248
251
  - spec/wavefront-sdk/proxy_spec.rb
249
252
  - spec/wavefront-sdk/query_spec.rb
250
253
  - spec/wavefront-sdk/report_spec.rb
254
+ - spec/wavefront-sdk/resources/dummy_points.rb
251
255
  - spec/wavefront-sdk/resources/test.conf
252
256
  - spec/wavefront-sdk/resources/test2.conf
253
257
  - spec/wavefront-sdk/response_spec.rb
@@ -291,6 +295,7 @@ test_files:
291
295
  - spec/spec_helper.rb
292
296
  - spec/wavefront-sdk/alert_spec.rb
293
297
  - spec/wavefront-sdk/base_spec.rb
298
+ - spec/wavefront-sdk/base_write_spec.rb
294
299
  - spec/wavefront-sdk/cloudintegration_spec.rb
295
300
  - spec/wavefront-sdk/credentials_spec.rb
296
301
  - spec/wavefront-sdk/dashboard_spec.rb
@@ -298,6 +303,7 @@ test_files:
298
303
  - spec/wavefront-sdk/event_spec.rb
299
304
  - spec/wavefront-sdk/externallink_spec.rb
300
305
  - spec/wavefront-sdk/integration_spec.rb
306
+ - spec/wavefront-sdk/logger_spec.rb
301
307
  - spec/wavefront-sdk/maintenancewindow_spec.rb
302
308
  - spec/wavefront-sdk/message_spec.rb
303
309
  - spec/wavefront-sdk/metric_spec.rb
@@ -307,6 +313,7 @@ test_files:
307
313
  - spec/wavefront-sdk/proxy_spec.rb
308
314
  - spec/wavefront-sdk/query_spec.rb
309
315
  - spec/wavefront-sdk/report_spec.rb
316
+ - spec/wavefront-sdk/resources/dummy_points.rb
310
317
  - spec/wavefront-sdk/resources/test.conf
311
318
  - spec/wavefront-sdk/resources/test2.conf
312
319
  - spec/wavefront-sdk/response_spec.rb