wavefront-sdk 4.0.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -118,7 +118,7 @@ class WavefrontMetricHelperTest < MiniTest::Test
118
118
  assert_equal(1, out.select do |o|
119
119
  o[:value] == [[2, 10.0], [1, 11.0],
120
120
  [1, 12.0]]
121
- end .size)
121
+ end.size)
122
122
  assert_equal(1, out.select { |o| o[:tags] == WH_TAGS }.size)
123
123
  assert_equal(3, out.select { |o| o[:path] == 'test.dist1' }.size)
124
124
  end
@@ -0,0 +1,68 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative '../spec_helper'
5
+ require_relative '../test_mixins/general'
6
+
7
+ # Unit tests for Wavefront::Role
8
+ #
9
+ class WavefrontRoleTest < WavefrontTestBase
10
+ include WavefrontTest::Create
11
+ include WavefrontTest::Delete
12
+ include WavefrontTest::Describe
13
+ include WavefrontTest::List
14
+ include WavefrontTest::Update
15
+
16
+ def test_add_assignees
17
+ assert_posts("/api/v2/role/#{id}/addAssignees", assignees.to_json) do
18
+ wf.add_assignees(id, assignees)
19
+ end
20
+
21
+ assert_raises(Wavefront::Exception::InvalidRoleId) do
22
+ wf.add_assignees(invalid_id, assignees)
23
+ end
24
+ end
25
+
26
+ def test_remove_assignees
27
+ assert_posts("/api/v2/role/#{id}/removeAssignees", assignees.to_json) do
28
+ wf.remove_assignees(id, assignees)
29
+ end
30
+
31
+ assert_raises(Wavefront::Exception::InvalidRoleId) do
32
+ wf.remove_assignees(invalid_id, assignees)
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ def api_class
39
+ :role
40
+ end
41
+
42
+ def id
43
+ 'f8dc0c14-91a0-4ca9-8a2a-7d47f4db4672'
44
+ end
45
+
46
+ def roles
47
+ %w[f8dc0c14-91a0-4ca9-8a2a-7d47f4db4672
48
+ 2659191e-aad4-4302-a94e-9667e1517127]
49
+ end
50
+
51
+ def assignees
52
+ roles.push('sa::test')
53
+ end
54
+
55
+ def invalid_id
56
+ '__BAD_ID__'
57
+ end
58
+
59
+ def payload
60
+ { name: 'test role',
61
+ permissions: %w[alerts_management events_management],
62
+ description: 'dummy role for unit tests' }
63
+ end
64
+
65
+ def permission
66
+ 'alerts_management'
67
+ end
68
+ end
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require_relative '../../spec_helper'
5
- require_relative '../../../lib/wavefront-sdk/unstable/spy'
4
+ require_relative '../spec_helper'
5
+ require_relative '../../lib/wavefront-sdk/spy'
6
6
 
7
7
  # Unit tests for Spy class
8
8
  #
@@ -10,7 +10,7 @@ class WavefrontSpyTest < MiniTest::Test
10
10
  attr_reader :wf
11
11
 
12
12
  def setup
13
- @wf = Wavefront::Unstable::Spy.new(CREDS)
13
+ @wf = Wavefront::Spy.new(CREDS)
14
14
  end
15
15
 
16
16
  def test_points
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
+ require 'logger'
4
5
  require_relative '../spec_helper'
5
6
  require_relative '../test_mixins/general'
6
7
 
@@ -13,6 +14,13 @@ class WavefrontUserTest < WavefrontTestBase
13
14
  include WavefrontTest::Describe
14
15
  include WavefrontTest::Update
15
16
 
17
+ # Override the parent constructor so we can suppress all the 'deprecated'
18
+ # log messages
19
+ #
20
+ def setup
21
+ @wf = Wavefront::User.new(CREDS, logger: Logger.new('/dev/null'))
22
+ end
23
+
16
24
  def test_list
17
25
  assert_gets('/api/v2/user') { wf.list }
18
26
  end
@@ -7,7 +7,8 @@ require_relative '../test_mixins/general'
7
7
  # Unit tests for WavefrontUserGroup
8
8
  #
9
9
  class WavefrontUserGroupTest < WavefrontTestBase
10
- attr_reader :users, :groups, :permission, :invalid_groups, :invalid_users
10
+ attr_reader :users, :groups, :permission, :invalid_groups, :invalid_users,
11
+ :roles, :invalid_roles
11
12
 
12
13
  include WavefrontTest::Create
13
14
  include WavefrontTest::Delete
@@ -39,22 +40,28 @@ class WavefrontUserGroupTest < WavefrontTestBase
39
40
  assert_invalid_id { wf.remove_users_from_group(invalid_id, users) }
40
41
  end
41
42
 
42
- def test_grant
43
- assert_posts("/api/v2/usergroup/grant/#{permission}",
44
- groups.to_json) do
45
- wf.grant(permission, groups)
43
+ def test_add_roles_to_group
44
+ assert_posts("/api/v2/usergroup/#{id}/addRoles", roles.to_json) do
45
+ wf.add_roles_to_group(id, roles)
46
46
  end
47
47
 
48
- assert_invalid_id { wf.grant(permission, invalid_groups) }
48
+ assert_raises(Wavefront::Exception::InvalidRoleId) do
49
+ wf.add_roles_to_group(id, invalid_roles)
50
+ end
51
+
52
+ assert_invalid_id { wf.add_roles_to_group(invalid_id, roles) }
49
53
  end
50
54
 
51
- def test_revoke
52
- assert_posts("/api/v2/usergroup/revoke/#{permission}",
53
- groups.to_json) do
54
- wf.revoke(permission, groups)
55
+ def test_remove_roles_from_group
56
+ assert_posts("/api/v2/usergroup/#{id}/removeRoles", roles.to_json) do
57
+ wf.remove_roles_from_group(id, roles)
58
+ end
59
+
60
+ assert_raises(Wavefront::Exception::InvalidRoleId) do
61
+ wf.remove_roles_from_group(id, invalid_roles)
55
62
  end
56
63
 
57
- assert_invalid_id { wf.revoke(permission, invalid_groups) }
64
+ assert_invalid_id { wf.remove_roles_from_group(invalid_id, roles) }
58
65
  end
59
66
 
60
67
  def setup_fixtures
@@ -63,7 +70,10 @@ class WavefrontUserGroupTest < WavefrontTestBase
63
70
  @groups = %w[f8dc0c14-91a0-4ca9-8a2a-7d47f4db4672
64
71
  2659191e-aad4-4302-a94e-9667e1517127]
65
72
  @users = %w[someone@somewhere.com other@elsewhere.net]
73
+ @roles = %w[abcdef14-91a0-4ca9-8a2a-7d47f4db4672
74
+ fedcba1e-aad4-4302-a94e-9667e1517127]
66
75
  @invalid_users = ['bad' * 500, '']
76
+ @invalid_roles = ['some nonsense']
67
77
  end
68
78
 
69
79
  private
@@ -401,4 +401,14 @@ class WavefrontValidatorsTest < MiniTest::Test
401
401
  bad = ['a', 0.1, 0.99, 1, -1, 1.1]
402
402
  good_and_bad('wf_sampling_value?', 'InvalidSamplingValue', good, bad)
403
403
  end
404
+
405
+ def test_wf_role_id
406
+ good = %w[2bfdcac7-1c9c-4c4b-9b56-c41c22c586dc
407
+ 17db4cc1-65f6-40a8-a1fa-6fcae460c4bd
408
+ fca312fb-5ff4-420d-862d-5d6d99ed6bcf
409
+ 3a1957e0-459e-49e5-9209-3888a4e8ac5b]
410
+
411
+ bad = %w[fa312fb-5ff4-420d-862d-5d6d99ed6bcf thing 123]
412
+ good_and_bad('wf_role_id?', 'InvalidRoleId', good, bad)
413
+ end
404
414
  end
@@ -28,8 +28,8 @@ Gem::Specification.new do |gem|
28
28
  gem.add_dependency 'map', '~> 6.6'
29
29
 
30
30
  gem.add_development_dependency 'minitest', '~> 5.11'
31
- gem.add_development_dependency 'rake', '~> 12.3'
32
- gem.add_development_dependency 'rubocop', '~> 0.79'
31
+ gem.add_development_dependency 'rake', '~> 13.0'
32
+ gem.add_development_dependency 'rubocop', '~> 0.87'
33
33
  gem.add_development_dependency 'simplecov', '~> 0.16'
34
34
  gem.add_development_dependency 'spy', '~> 1.0.0'
35
35
  gem.add_development_dependency 'webmock', '~> 3.7'
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: 4.0.0
4
+ version: 5.0.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: 2020-02-17 00:00:00.000000000 Z
11
+ date: 2020-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -86,28 +86,28 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '12.3'
89
+ version: '13.0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '12.3'
96
+ version: '13.0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rubocop
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '0.79'
103
+ version: '0.87'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '0.79'
110
+ version: '0.87'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: simplecov
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -205,7 +205,6 @@ files:
205
205
  - lib/wavefront-sdk/message.rb
206
206
  - lib/wavefront-sdk/metric.rb
207
207
  - lib/wavefront-sdk/metric_helper.rb
208
- - lib/wavefront-sdk/monitoredcluster.rb
209
208
  - lib/wavefront-sdk/notificant.rb
210
209
  - lib/wavefront-sdk/paginator/base.rb
211
210
  - lib/wavefront-sdk/paginator/delete.rb
@@ -215,11 +214,13 @@ files:
215
214
  - lib/wavefront-sdk/proxy.rb
216
215
  - lib/wavefront-sdk/query.rb
217
216
  - lib/wavefront-sdk/report.rb
217
+ - lib/wavefront-sdk/role.rb
218
218
  - lib/wavefront-sdk/savedsearch.rb
219
219
  - lib/wavefront-sdk/search.rb
220
220
  - lib/wavefront-sdk/serviceaccount.rb
221
221
  - lib/wavefront-sdk/settings.rb
222
222
  - lib/wavefront-sdk/source.rb
223
+ - lib/wavefront-sdk/spy.rb
223
224
  - lib/wavefront-sdk/stdlib/array.rb
224
225
  - lib/wavefront-sdk/stdlib/hash.rb
225
226
  - lib/wavefront-sdk/stdlib/string.rb
@@ -229,7 +230,6 @@ files:
229
230
  - lib/wavefront-sdk/types/status.rb
230
231
  - lib/wavefront-sdk/unstable/README.md
231
232
  - lib/wavefront-sdk/unstable/chart.rb
232
- - lib/wavefront-sdk/unstable/spy.rb
233
233
  - lib/wavefront-sdk/unstable/unstable.rb
234
234
  - lib/wavefront-sdk/usage.rb
235
235
  - lib/wavefront-sdk/user.rb
@@ -276,7 +276,6 @@ files:
276
276
  - spec/wavefront-sdk/message_spec.rb
277
277
  - spec/wavefront-sdk/metric_helper_spec.rb
278
278
  - spec/wavefront-sdk/metric_spec.rb
279
- - spec/wavefront-sdk/monitoredcluster_spec.rb
280
279
  - spec/wavefront-sdk/notificant_spec.rb
281
280
  - spec/wavefront-sdk/paginator/base_spec.rb
282
281
  - spec/wavefront-sdk/paginator/post_spec.rb
@@ -293,18 +292,19 @@ files:
293
292
  - spec/wavefront-sdk/resources/user_responses/describe.json
294
293
  - spec/wavefront-sdk/resources/user_responses/grant.json
295
294
  - spec/wavefront-sdk/resources/user_responses/list.json
295
+ - spec/wavefront-sdk/role_spec.rb
296
296
  - spec/wavefront-sdk/savedsearch_spec.rb
297
297
  - spec/wavefront-sdk/search_spec.rb
298
298
  - spec/wavefront-sdk/serviceaccount_spec.rb
299
299
  - spec/wavefront-sdk/settings_spec.rb
300
300
  - spec/wavefront-sdk/source_spec.rb
301
+ - spec/wavefront-sdk/spy_spec.rb
301
302
  - spec/wavefront-sdk/stdlib/array_spec.rb
302
303
  - spec/wavefront-sdk/stdlib/hash_spec.rb
303
304
  - spec/wavefront-sdk/stdlib/string_spec.rb
304
305
  - spec/wavefront-sdk/support/mixins_spec.rb
305
306
  - spec/wavefront-sdk/support/parse_time_spec.rb
306
307
  - spec/wavefront-sdk/unstable/chart_spec.rb
307
- - spec/wavefront-sdk/unstable/spy_spec.rb
308
308
  - spec/wavefront-sdk/usage_spec.rb
309
309
  - spec/wavefront-sdk/user_spec.rb
310
310
  - spec/wavefront-sdk/usergroup_spec.rb
@@ -374,7 +374,6 @@ test_files:
374
374
  - spec/wavefront-sdk/message_spec.rb
375
375
  - spec/wavefront-sdk/metric_helper_spec.rb
376
376
  - spec/wavefront-sdk/metric_spec.rb
377
- - spec/wavefront-sdk/monitoredcluster_spec.rb
378
377
  - spec/wavefront-sdk/notificant_spec.rb
379
378
  - spec/wavefront-sdk/paginator/base_spec.rb
380
379
  - spec/wavefront-sdk/paginator/post_spec.rb
@@ -391,18 +390,19 @@ test_files:
391
390
  - spec/wavefront-sdk/resources/user_responses/describe.json
392
391
  - spec/wavefront-sdk/resources/user_responses/grant.json
393
392
  - spec/wavefront-sdk/resources/user_responses/list.json
393
+ - spec/wavefront-sdk/role_spec.rb
394
394
  - spec/wavefront-sdk/savedsearch_spec.rb
395
395
  - spec/wavefront-sdk/search_spec.rb
396
396
  - spec/wavefront-sdk/serviceaccount_spec.rb
397
397
  - spec/wavefront-sdk/settings_spec.rb
398
398
  - spec/wavefront-sdk/source_spec.rb
399
+ - spec/wavefront-sdk/spy_spec.rb
399
400
  - spec/wavefront-sdk/stdlib/array_spec.rb
400
401
  - spec/wavefront-sdk/stdlib/hash_spec.rb
401
402
  - spec/wavefront-sdk/stdlib/string_spec.rb
402
403
  - spec/wavefront-sdk/support/mixins_spec.rb
403
404
  - spec/wavefront-sdk/support/parse_time_spec.rb
404
405
  - spec/wavefront-sdk/unstable/chart_spec.rb
405
- - spec/wavefront-sdk/unstable/spy_spec.rb
406
406
  - spec/wavefront-sdk/usage_spec.rb
407
407
  - spec/wavefront-sdk/user_spec.rb
408
408
  - spec/wavefront-sdk/usergroup_spec.rb
@@ -1,93 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'core/api'
4
- require_relative 'api_mixins/tag'
5
-
6
- module Wavefront
7
- #
8
- # Manage and query Wavefront monitored clusters
9
- #
10
- class MonitoredCluster < CoreApi
11
- include Wavefront::Mixin::Tag
12
-
13
- def update_keys
14
- %i[id]
15
- end
16
-
17
- # GET /api/v2/monitoredcluster
18
- # Get all monitored clusters
19
- # @param offset [Integer] cluster at which the list begins
20
- # @param limit [Integer] the number of clusters to return
21
- # @return [Wavefront::Response]
22
- #
23
- def list(offset = 0, limit = 100)
24
- api.get('', offset: offset, limit: limit)
25
- end
26
-
27
- # POST /api/v2/monitoredcluster
28
- # Create a specific cluster
29
- # @param body [Hash] a hash of parameters describing the cluster.
30
- # Please refer to the Wavefront Swagger docs for key:value
31
- # information
32
- # @return [Wavefront::Response]
33
- #
34
- def create(body)
35
- raise ArgumentError unless body.is_a?(Hash)
36
-
37
- api.post('', body, 'application/json')
38
- end
39
-
40
- # DELETE /api/v2/monitoredcluster/{id}
41
- # Delete a specific cluster
42
- # @param id [String, Integer] ID of the maintenance cluster
43
- # @return [Wavefront::Response]
44
- #
45
- def delete(id)
46
- wf_monitoredcluster_id?(id)
47
- api.delete(id)
48
- end
49
-
50
- # GET /api/v2/monitoredcluster/{id}
51
- # Get a specific cluster
52
- # @param id [String, Integer] ID of the cluster
53
- # @return [Wavefront::Response]
54
- #
55
- def describe(id)
56
- wf_monitoredcluster_id?(id)
57
- api.get(id)
58
- end
59
-
60
- # PUT /api/v2/monitoredcluster/{id}
61
- # Update a specific cluster
62
- # @return [Wavefront::Response]
63
- #
64
- def update(id, body, modify = true)
65
- wf_monitoredcluster_id?(id)
66
- raise ArgumentError unless body.is_a?(Hash)
67
-
68
- return api.put(id, body, 'application/json') unless modify
69
-
70
- api.put(id, hash_for_update(describe(id).response, body),
71
- 'application/json')
72
- end
73
-
74
- # PUT /api/v2/monitoredcluster/merge/{id1}/{id2}
75
- # Merge two monitored clusters. The first cluster will remain and the
76
- # second cluster will be deleted, with its id added as an alias to the
77
- # first cluster.
78
- # @param id1 [String, Integer] ID of the target cluster
79
- # @param id2 [String, Integer] ID of the other cluster
80
- # @return [Wavefront::Response]
81
- #
82
- def merge(id1, id2)
83
- wf_monitoredcluster_id?(id1)
84
- wf_monitoredcluster_id?(id2)
85
-
86
- api.put(['merge', id1, id2].uri_concat, nil, 'application/json')
87
- end
88
-
89
- def valid_id?(id)
90
- wf_monitoredcluster_id?(id)
91
- end
92
- end
93
- end
@@ -1,134 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../defs/constants'
4
- require_relative '../core/api'
5
-
6
- module Wavefront
7
- module Unstable
8
- #
9
- # THIS IS AN UNSTABLE CLASS. PLEASE REFER TO README.md.
10
- #
11
- # Everything about this API is different from the public one. To make it
12
- # appear similar we must change various things we normally take for
13
- # granted.
14
- #
15
- # This class is built according to the documentation at
16
- # https://docs.wavefront.com/wavefront_monitoring_spy.html
17
- #
18
- class Spy < CoreApi
19
- # https://<cluster>.wavefront.com/api/spy/points
20
- # Gets new metric data points that are added to existing time series.
21
- # @param sampling [Float] the amount of points to sample, from 0
22
- # (none) to 1 (all)
23
- # @param filter [Hash] with the following keys:
24
- # :prefix [String] only list points whose metric name begins with this
25
- # case-sensitive string
26
- # :host [Array] only list points if source name begins with this
27
- # case-sensitive string
28
- # :tag_key [String,Array[String]] only list points with one or more of
29
- # the given points tags
30
- # @param options [Hash] with the following keys
31
- # :timestamp [Boolean] prefix each block of streamed data with a
32
- # timestamp
33
- # :timeout [Integer] how many seconds to run the spy. After this time
34
- # the method returns
35
- # @raise Wavefront::Exception::InvalidSamplingValue
36
- # @return [Nil]
37
- #
38
- def points(sampling = 0.01, filters = {}, options = {})
39
- wf_sampling_value?(sampling)
40
- api.get_stream('points', points_filter(sampling, filters), options)
41
- end
42
-
43
- # Gets new histograms that are added to existing time series.
44
- # @param sampling [Float] see #points
45
- # @param filter [Hash] see #points
46
- # @param options [Hash] see #points
47
- # @raise Wavefront::Exception::InvalidSamplingValue
48
- # @return [Nil]
49
- #
50
- def histograms(sampling = 0.01, filters = {}, options = {})
51
- wf_sampling_value?(sampling)
52
- api.get_stream('histograms',
53
- histograms_filter(sampling, filters),
54
- options)
55
- end
56
-
57
- # https://<cluster>.wavefront.com/api/spy/spans
58
- # Gets new spans with existing source names and span tags.
59
- # @param sampling [Float] see #points
60
- # @param filter [Hash] see #points
61
- # @param options [Hash] see #points
62
- # @raise Wavefront::Exception::InvalidSamplingValue
63
- # @return [Nil]
64
- #
65
- def spans(sampling = 0.01, filters = {}, options = {})
66
- wf_sampling_value?(sampling)
67
- api.get_stream('spans', spans_filter(sampling, filters), options)
68
- end
69
-
70
- # https://<cluster>.wavefront.com/api/spy/ids
71
- # Gets newly allocated IDs that correspond to new metric names, source
72
- # names, point tags, or span tags. A new ID generally indicates that a
73
- # new time series has been introduced.
74
- # @param sampling [Float] see #points
75
- # @param filter [Hash] with keys:
76
- # :prefix [String] only list assignments whose metric name begins with
77
- # this case-sensitive string
78
- # :type [String] one of METRIC, SPAN, HOST or STRING
79
- # @param options [Hash] see #points
80
- #
81
- def ids(sampling = 0.01, filters = {}, options = {})
82
- wf_sampling_value?(sampling)
83
- api.get_stream('ids', ids_filter(sampling, filters), options)
84
- end
85
-
86
- def api_path
87
- '/api/spy'
88
- end
89
-
90
- # We have to try to make the response we get from the API look
91
- # like the one we get from the public API. To begin with, it's
92
- # nothing like it.
93
- #
94
- # This method must be public because a #respond_to? looks for
95
- # it.
96
- #
97
- def _response_shim(resp, status)
98
- { response: parse_response(resp),
99
- status: { result: status == 200 ? 'OK' : 'ERROR',
100
- message: extract_api_message(status, resp),
101
- code: status } }.to_json
102
- end
103
-
104
- private
105
-
106
- def points_filter(sampling, filters)
107
- { metric: filters.fetch(:prefix, nil),
108
- host: filters.fetch(:host, nil),
109
- sampling: sampling,
110
- pointTagKey: filters.fetch(:tag_key, nil) }.compact
111
- end
112
-
113
- def histograms_filter(sampling, filters)
114
- { histogram: filters.fetch(:prefix, nil),
115
- host: filters.fetch(:host, nil),
116
- sampling: sampling,
117
- histogramTagKey: filters.fetch(:tag_key, nil) }.compact
118
- end
119
-
120
- def spans_filter(sampling, filters)
121
- { name: filters.fetch(:prefix, nil),
122
- host: filters.fetch(:host, nil),
123
- sampling: sampling,
124
- spanTagKey: filters.fetch(:tag_key, nil) }.compact
125
- end
126
-
127
- def ids_filter(sampling, filters)
128
- { name: filters.fetch(:prefix, nil),
129
- type: filters.fetch(:type, nil),
130
- sampling: sampling }.compact
131
- end
132
- end
133
- end
134
- end