wavefront-sdk 3.0.2 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/HISTORY.md +12 -1
  3. data/README.md +4 -0
  4. data/Rakefile +1 -0
  5. data/lib/wavefront-sdk/alert.rb +36 -49
  6. data/lib/wavefront-sdk/api_mixins/acl.rb +76 -0
  7. data/lib/wavefront-sdk/api_mixins/tag.rb +62 -0
  8. data/lib/wavefront-sdk/api_mixins/user.rb +26 -0
  9. data/lib/wavefront-sdk/apitoken.rb +49 -0
  10. data/lib/wavefront-sdk/core/exception.rb +1 -0
  11. data/lib/wavefront-sdk/dashboard.rb +6 -106
  12. data/lib/wavefront-sdk/defs/version.rb +1 -1
  13. data/lib/wavefront-sdk/derivedmetric.rb +6 -56
  14. data/lib/wavefront-sdk/event.rb +4 -50
  15. data/lib/wavefront-sdk/paginator/base.rb +8 -7
  16. data/lib/wavefront-sdk/paginator/post.rb +7 -5
  17. data/lib/wavefront-sdk/source.rb +4 -48
  18. data/lib/wavefront-sdk/user.rb +2 -2
  19. data/lib/wavefront-sdk/usergroup.rb +2 -2
  20. data/lib/wavefront-sdk/validators.rb +10 -0
  21. data/lib/wavefront-sdk/write.rb +43 -12
  22. data/lib/wavefront-sdk/writers/socket.rb +2 -2
  23. data/spec/.rubocop.yml +1 -1
  24. data/spec/spec_helper.rb +66 -0
  25. data/spec/wavefront-sdk/alert_spec.rb +14 -0
  26. data/spec/wavefront-sdk/{support → api_mixins}/user_mixins_spec.rb +2 -2
  27. data/spec/wavefront-sdk/apitoken_spec.rb +31 -0
  28. data/spec/wavefront-sdk/core/api_spec.rb +3 -5
  29. data/spec/wavefront-sdk/credentials_spec.rb +41 -37
  30. data/spec/wavefront-sdk/dashboard_spec.rb +4 -52
  31. data/spec/wavefront-sdk/distribution_spec.rb +1 -3
  32. data/spec/wavefront-sdk/metric_helper_spec.rb +6 -8
  33. data/spec/wavefront-sdk/report_spec.rb +2 -2
  34. data/spec/wavefront-sdk/stdlib/array_spec.rb +6 -6
  35. data/spec/wavefront-sdk/stdlib/hash_spec.rb +5 -5
  36. data/spec/wavefront-sdk/support/mixins_spec.rb +34 -36
  37. data/spec/wavefront-sdk/support/parse_time_spec.rb +25 -29
  38. data/spec/wavefront-sdk/usergroup_spec.rb +34 -34
  39. data/spec/wavefront-sdk/validators_spec.rb +10 -1
  40. data/spec/wavefront-sdk/write_spec.rb +71 -4
  41. data/spec/wavefront-sdk/writers/core_spec.rb +10 -10
  42. data/spec/wavefront-sdk/writers/socket_spec.rb +13 -1
  43. metadata +10 -5
  44. data/lib/wavefront-sdk/support/user_mixins.rb +0 -24
@@ -1,7 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'date'
4
- require 'minitest/autorun'
5
4
  require_relative '../spec_helper'
6
5
  require_relative '../../lib/wavefront-sdk/defs/constants'
7
6
  require_relative '../../lib/wavefront-sdk/validators'
@@ -337,6 +336,16 @@ class WavefrontValidatorsTest < MiniTest::Test
337
336
  good_and_bad('wf_integration_id?', 'InvalidIntegrationId', good, bad)
338
337
  end
339
338
 
339
+ def test_apitoken_id
340
+ good = %w[2bfdcac7-1c9c-4c4b-9b56-c41c22c586dc
341
+ 17db4cc1-65f6-40a8-a1fa-6fcae460c4bd
342
+ fca312fb-5ff4-420d-862d-5d6d99ed6bcf
343
+ 3a1957e0-459e-49e5-9209-3888a4e8ac5b]
344
+
345
+ bad = %w[fa312fb-5ff4-420d-862d-5d6d99ed6bcf thing 123]
346
+ good_and_bad('wf_apitoken_id?', 'InvalidApiTokenId', good, bad)
347
+ end
348
+
340
349
  def test_distribution_interval
341
350
  good = %i[m h d]
342
351
  bad = ['m', [], {}, nil, 'bad id', :x, 'p']
@@ -1,12 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require_relative '../spec_helper'
4
- require 'minitest/autorun'
5
- require_relative '../../lib/wavefront-sdk/write.rb'
4
+ require_relative '../../lib/wavefront-sdk/write'
5
+ require_relative '../../lib/wavefront-sdk/core/response'
6
6
  require_relative 'resources/dummy_points'
7
7
 
8
- W_CREDS = { proxy: 'wavefront', port: 2878 }.freeze
9
-
10
8
  # This class is sufficiently different to the API calling classes
11
9
  # that it doesn't use spec helper or inherit anything.
12
10
  #
@@ -29,6 +27,75 @@ class WavefrontWriteTest < MiniTest::Test
29
27
  assert_instance_of(Wavefront::Writer::Socket, wf.writer)
30
28
  end
31
29
 
30
+ def test_composite_response
31
+ bad_status = { result: 'ERROR', message: nil, code: nil }
32
+ bad_response = { sent: 0, rejected: 1, unsent: 0 }
33
+ good_status = { result: 'OK', message: nil, code: nil }
34
+ good_response = { sent: 1, rejected: 0, unsent: 0 }
35
+
36
+ bad_resp = Wavefront::Response.new(
37
+ { status: bad_status, response: bad_response }.to_json, nil
38
+ )
39
+
40
+ good_resp = Wavefront::Response.new(
41
+ { status: good_status, response: good_response }.to_json, nil
42
+ )
43
+
44
+ x = wf.composite_response(Array.new(5).map { good_resp })
45
+ assert x.ok?
46
+ assert_equal('OK', x.status.result)
47
+ assert_equal(5, x.response.sent)
48
+ assert_equal(0, x.response.rejected)
49
+ assert_equal(0, x.response.unsent)
50
+
51
+ y = wf.composite_response(Array.new(4).map { good_resp } + [bad_resp])
52
+ refute y.ok?
53
+ assert_equal('ERROR', y.status.result)
54
+ assert_equal(4, y.response.sent)
55
+ assert_equal(1, y.response.rejected)
56
+ assert_equal(0, y.response.unsent)
57
+
58
+ z = wf.composite_response(Array.new(5).map { bad_resp })
59
+ refute z.ok?
60
+ assert_equal('ERROR', z.status.result)
61
+ assert_equal(0, z.response.sent)
62
+ assert_equal(5, z.response.rejected)
63
+ assert_equal(0, z.response.unsent)
64
+ end
65
+
66
+ def test_write_empty
67
+ assert wf.write([])
68
+ end
69
+
70
+ def test_bad_write
71
+ write_method = Spy.on(wf.writer, :write).and_return(BadMocket.new)
72
+ refute wf.write(point_array(19)).ok?
73
+ assert write_method.has_been_called?
74
+ assert_equal(1, write_method.calls.size)
75
+ end
76
+
77
+ def test_write_single_chunk
78
+ write_method = Spy.on(wf.writer, :write).and_return(Mocket.new)
79
+ assert wf.write(point_array(19)).ok?
80
+ assert write_method.has_been_called?
81
+ assert_equal(1, write_method.calls.size)
82
+ end
83
+
84
+ def test_write_multi_chunk
85
+ write_method = Spy.on(wf.writer, :write).and_return(Mocket.new)
86
+ assert wf.write(point_array(4321))
87
+ assert write_method.has_been_called?
88
+ assert_equal(5, write_method.calls.size)
89
+ end
90
+
91
+ # helper to test write chunking
92
+ #
93
+ def point_array(count)
94
+ 1.upto(count).map do |i|
95
+ { path: 'dummy.path', value: i, ts: Time.now.to_i - i }
96
+ end
97
+ end
98
+
32
99
  def test_paths_to_deltas
33
100
  x = wf.paths_to_deltas(POINTS.dup)
34
101
  assert_equal(x.size, 2)
@@ -37,17 +37,17 @@ class WavefrontCoreWriteTest < MiniTest::Test
37
37
  end
38
38
 
39
39
  def test_prefix_points
40
- assert_equal(wf.prefix_points(%w[p1 p2 p3 p4]), %w[p1 p2 p3 p4])
41
- assert_equal(wf.prefix_points([%w[p1 p2 p3 p4]]), %w[p1 p2 p3 p4])
42
- assert_equal(wf.prefix_points('p1'), %w[p1])
43
- assert_equal(wf.prefix_points([{ path: 'p1' },
44
- { path: 'p2' },
45
- { path: 'p3' }], 'prefix'),
46
- [{ path: 'prefix.p1' },
40
+ assert_equal(%w[p1 p2 p3 p4], wf.prefix_points(%w[p1 p2 p3 p4]))
41
+ assert_equal(%w[p1 p2 p3 p4], wf.prefix_points([%w[p1 p2 p3 p4]]))
42
+ assert_equal(%w[p1], wf.prefix_points('p1'))
43
+ assert_equal([{ path: 'prefix.p1' },
47
44
  { path: 'prefix.p2' },
48
- { path: 'prefix.p3' }])
45
+ { path: 'prefix.p3' }],
46
+ wf.prefix_points([{ path: 'p1' },
47
+ { path: 'p2' },
48
+ { path: 'p3' }], 'prefix'))
49
49
 
50
- assert_equal(wf.prefix_points({ path: 'p1' }, 'prefix'),
51
- [path: 'prefix.p1'])
50
+ assert_equal([path: 'prefix.p1'],
51
+ wf.prefix_points({ path: 'p1' }, 'prefix'))
52
52
  end
53
53
  end
@@ -85,12 +85,24 @@ class WavefrontWriterSocketTest < MiniTest::Test
85
85
  tcp_spy = Spy.on(TCPSocket, :new)
86
86
  wf.open
87
87
  assert tcp_spy.has_been_called?
88
- assert_equal(tcp_spy.calls.first.args, ['wavefront-proxy', 2878])
88
+ assert_equal(['wavefront-proxy', 2878], tcp_spy.calls.first.args)
89
89
  end
90
90
 
91
91
  def test_noop_open
92
92
  tcp_spy = Spy.on(TCPSocket, :new)
93
+ log_spy = Spy.on(wf_noop.logger, :log)
93
94
  wf_noop.open
94
95
  refute tcp_spy.has_been_called?
96
+ assert_equal(['No-op requested. Not opening connection to proxy.'],
97
+ log_spy.calls.last.args)
98
+ assert_equal(1, log_spy.calls.size)
99
+ end
100
+
101
+ def test_noop_close
102
+ tcp_spy = Spy.on(TCPSocket, :new)
103
+ log_spy = Spy.on(wf_noop.logger, :log)
104
+ wf_noop.close
105
+ refute tcp_spy.has_been_called?
106
+ refute log_spy.has_been_called?
95
107
  end
96
108
  end
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: 3.0.2
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Fisher
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-06 00:00:00.000000000 Z
11
+ date: 2019-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -180,6 +180,10 @@ files:
180
180
  - README.md
181
181
  - Rakefile
182
182
  - lib/wavefront-sdk/alert.rb
183
+ - lib/wavefront-sdk/api_mixins/acl.rb
184
+ - lib/wavefront-sdk/api_mixins/tag.rb
185
+ - lib/wavefront-sdk/api_mixins/user.rb
186
+ - lib/wavefront-sdk/apitoken.rb
183
187
  - lib/wavefront-sdk/cloudintegration.rb
184
188
  - lib/wavefront-sdk/core/api.rb
185
189
  - lib/wavefront-sdk/core/api_caller.rb
@@ -217,7 +221,6 @@ files:
217
221
  - lib/wavefront-sdk/stdlib/string.rb
218
222
  - lib/wavefront-sdk/support/mixins.rb
219
223
  - lib/wavefront-sdk/support/parse_time.rb
220
- - lib/wavefront-sdk/support/user_mixins.rb
221
224
  - lib/wavefront-sdk/types/status.rb
222
225
  - lib/wavefront-sdk/user.rb
223
226
  - lib/wavefront-sdk/usergroup.rb
@@ -234,6 +237,8 @@ files:
234
237
  - spec/.rubocop.yml
235
238
  - spec/spec_helper.rb
236
239
  - spec/wavefront-sdk/alert_spec.rb
240
+ - spec/wavefront-sdk/api_mixins/user_mixins_spec.rb
241
+ - spec/wavefront-sdk/apitoken_spec.rb
237
242
  - spec/wavefront-sdk/cloudintegration_spec.rb
238
243
  - spec/wavefront-sdk/core/api_caller_spec.rb
239
244
  - spec/wavefront-sdk/core/api_spec.rb
@@ -269,7 +274,6 @@ files:
269
274
  - spec/wavefront-sdk/stdlib/string_spec.rb
270
275
  - spec/wavefront-sdk/support/mixins_spec.rb
271
276
  - spec/wavefront-sdk/support/parse_time_spec.rb
272
- - spec/wavefront-sdk/support/user_mixins_spec.rb
273
277
  - spec/wavefront-sdk/user_spec.rb
274
278
  - spec/wavefront-sdk/usergroup_spec.rb
275
279
  - spec/wavefront-sdk/validators_spec.rb
@@ -308,6 +312,8 @@ test_files:
308
312
  - spec/.rubocop.yml
309
313
  - spec/spec_helper.rb
310
314
  - spec/wavefront-sdk/alert_spec.rb
315
+ - spec/wavefront-sdk/api_mixins/user_mixins_spec.rb
316
+ - spec/wavefront-sdk/apitoken_spec.rb
311
317
  - spec/wavefront-sdk/cloudintegration_spec.rb
312
318
  - spec/wavefront-sdk/core/api_caller_spec.rb
313
319
  - spec/wavefront-sdk/core/api_spec.rb
@@ -343,7 +349,6 @@ test_files:
343
349
  - spec/wavefront-sdk/stdlib/string_spec.rb
344
350
  - spec/wavefront-sdk/support/mixins_spec.rb
345
351
  - spec/wavefront-sdk/support/parse_time_spec.rb
346
- - spec/wavefront-sdk/support/user_mixins_spec.rb
347
352
  - spec/wavefront-sdk/user_spec.rb
348
353
  - spec/wavefront-sdk/usergroup_spec.rb
349
354
  - spec/wavefront-sdk/validators_spec.rb
@@ -1,24 +0,0 @@
1
- module Wavefront
2
- #
3
- # Things needed by User and UserGroup classes
4
- #
5
- module UserMixins
6
- # Validate a list of users.
7
- # @param list [Array[String]] list of user IDs
8
- # @raise Wavefront::Exception::InvalidUser
9
- #
10
- def validate_user_list(list)
11
- raise ArgumentError unless list.is_a?(Array)
12
- list.each { |id| wf_user_id?(id) }
13
- end
14
-
15
- # Validate a list of user groups
16
- # @param list [Array[String]] list of user group IDs
17
- # @raise Wavefront::Exception::InvalidUserGroup
18
- #
19
- def validate_usergroup_list(list)
20
- raise ArgumentError unless list.is_a?(Array)
21
- list.each { |id| wf_usergroup_id?(id) }
22
- end
23
- end
24
- end