wavefront-sdk 6.0.0 → 8.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/release.yml +4 -4
  3. data/.github/workflows/test.yml +2 -2
  4. data/.rubocop.yml +1 -3
  5. data/Gemfile +11 -0
  6. data/HISTORY.md +32 -4
  7. data/README.md +3 -3
  8. data/lib/wavefront-sdk/accesspolicy.rb +37 -0
  9. data/lib/wavefront-sdk/account.rb +28 -0
  10. data/lib/wavefront-sdk/alert.rb +29 -10
  11. data/lib/wavefront-sdk/api_mixins/tag.rb +12 -12
  12. data/lib/wavefront-sdk/apitoken.rb +29 -2
  13. data/lib/wavefront-sdk/cloudintegration.rb +10 -8
  14. data/lib/wavefront-sdk/cluster.rb +18 -0
  15. data/lib/wavefront-sdk/core/api_caller.rb +3 -9
  16. data/lib/wavefront-sdk/core/exception.rb +4 -0
  17. data/lib/wavefront-sdk/core/response.rb +1 -1
  18. data/lib/wavefront-sdk/credentials.rb +2 -2
  19. data/lib/wavefront-sdk/dashboard.rb +7 -6
  20. data/lib/wavefront-sdk/defs/version.rb +1 -1
  21. data/lib/wavefront-sdk/derivedmetric.rb +7 -6
  22. data/lib/wavefront-sdk/event.rb +5 -5
  23. data/lib/wavefront-sdk/externallink.rb +3 -3
  24. data/lib/wavefront-sdk/ingestionpolicy.rb +32 -5
  25. data/lib/wavefront-sdk/integration.rb +14 -4
  26. data/lib/wavefront-sdk/internals.rb +93 -0
  27. data/lib/wavefront-sdk/maintenancewindow.rb +4 -4
  28. data/lib/wavefront-sdk/message.rb +1 -1
  29. data/lib/wavefront-sdk/metric.rb +2 -2
  30. data/lib/wavefront-sdk/metric_helper.rb +1 -1
  31. data/lib/wavefront-sdk/metricspolicy.rb +3 -3
  32. data/lib/wavefront-sdk/monitoredapplication.rb +55 -0
  33. data/lib/wavefront-sdk/notificant.rb +4 -4
  34. data/lib/wavefront-sdk/paginator/base.rb +1 -1
  35. data/lib/wavefront-sdk/proxy.rb +26 -4
  36. data/lib/wavefront-sdk/role.rb +2 -2
  37. data/lib/wavefront-sdk/savedsearch.rb +4 -4
  38. data/lib/wavefront-sdk/search.rb +9 -7
  39. data/lib/wavefront-sdk/source.rb +6 -6
  40. data/lib/wavefront-sdk/spansamplingpolicy.rb +126 -0
  41. data/lib/wavefront-sdk/stdlib/string.rb +1 -1
  42. data/lib/wavefront-sdk/support/mixins.rb +1 -1
  43. data/lib/wavefront-sdk/support/parse_time.rb +1 -1
  44. data/lib/wavefront-sdk/user.rb +5 -5
  45. data/lib/wavefront-sdk/usergroup.rb +2 -2
  46. data/lib/wavefront-sdk/validators.rb +31 -8
  47. data/lib/wavefront-sdk/webhook.rb +3 -3
  48. data/lib/wavefront-sdk/write.rb +1 -0
  49. data/lib/wavefront-sdk/writers/api.rb +31 -8
  50. data/lib/wavefront-sdk/writers/core.rb +1 -1
  51. data/lib/wavefront_sdk.rb +1 -1
  52. data/spec/constants.rb +2 -2
  53. data/spec/spec_helper.rb +1 -1
  54. data/spec/wavefront-sdk/accesspolicy_spec.rb +53 -0
  55. data/spec/wavefront-sdk/account_spec.rb +32 -1
  56. data/spec/wavefront-sdk/alert_spec.rb +17 -0
  57. data/spec/wavefront-sdk/api_mixins/user_mixins_spec.rb +1 -1
  58. data/spec/wavefront-sdk/apitoken_spec.rb +12 -0
  59. data/spec/wavefront-sdk/cluster_spec.rb +13 -0
  60. data/spec/wavefront-sdk/core/api_caller_spec.rb +1 -1
  61. data/spec/wavefront-sdk/core/api_spec.rb +2 -2
  62. data/spec/wavefront-sdk/core/logger_spec.rb +1 -1
  63. data/spec/wavefront-sdk/core/response_spec.rb +1 -1
  64. data/spec/wavefront-sdk/credentials_spec.rb +11 -15
  65. data/spec/wavefront-sdk/distribution_spec.rb +1 -1
  66. data/spec/wavefront-sdk/ingestionpolicy_spec.rb +11 -0
  67. data/spec/wavefront-sdk/integration_spec.rb +4 -0
  68. data/spec/wavefront-sdk/internals_spec.rb +62 -0
  69. data/spec/wavefront-sdk/metric_helper_spec.rb +1 -1
  70. data/spec/wavefront-sdk/metricspolicy_spec.rb +3 -3
  71. data/spec/wavefront-sdk/misc_spec.rb +3 -3
  72. data/spec/wavefront-sdk/monitoredapplication_spec.rb +35 -0
  73. data/spec/wavefront-sdk/paginator/base_spec.rb +1 -1
  74. data/spec/wavefront-sdk/paginator/post_spec.rb +1 -1
  75. data/spec/wavefront-sdk/proxy_spec.rb +14 -0
  76. data/spec/wavefront-sdk/resources/swagger.spec.gz +0 -0
  77. data/spec/wavefront-sdk/savedsearch_spec.rb +2 -2
  78. data/spec/wavefront-sdk/spansamplingpolicy_spec.rb +47 -0
  79. data/spec/wavefront-sdk/spy_spec.rb +1 -1
  80. data/spec/wavefront-sdk/stdlib/array_spec.rb +1 -1
  81. data/spec/wavefront-sdk/stdlib/hash_spec.rb +1 -1
  82. data/spec/wavefront-sdk/stdlib/string_spec.rb +1 -1
  83. data/spec/wavefront-sdk/support/mixins_spec.rb +1 -1
  84. data/spec/wavefront-sdk/support/parse_time_spec.rb +1 -1
  85. data/spec/wavefront-sdk/unstable/chart_spec.rb +1 -1
  86. data/spec/wavefront-sdk/usage_spec.rb +0 -1
  87. data/spec/wavefront-sdk/user_spec.rb +2 -2
  88. data/spec/wavefront-sdk/validators_spec.rb +17 -1
  89. data/spec/wavefront-sdk/write_spec.rb +1 -1
  90. data/spec/wavefront-sdk/writers/api_spec.rb +1 -1
  91. data/spec/wavefront-sdk/writers/core_spec.rb +1 -1
  92. data/spec/wavefront-sdk/writers/http_spec.rb +1 -1
  93. data/spec/wavefront-sdk/writers/proxy_spec.rb +1 -1
  94. data/spec/wavefront-sdk/writers/socket_spec.rb +1 -1
  95. data/spec/wavefront-sdk/writers/summary_spec.rb +1 -1
  96. data/wavefront-sdk.gemspec +4 -15
  97. metadata +22 -224
@@ -43,7 +43,7 @@ module Wavefront
43
43
  api.post('', body, 'application/json')
44
44
  end
45
45
 
46
- # DELETE /api/v2/source/id
46
+ # DELETE /api/v2/source/{id}
47
47
  # Delete metadata (description and tags) for a specific source.
48
48
  #
49
49
  # @param id [String] ID of the source
@@ -54,7 +54,7 @@ module Wavefront
54
54
  api.delete(id)
55
55
  end
56
56
 
57
- # POST /api/v2/source/id/description
57
+ # POST /api/v2/source/{id}/description
58
58
  # Set description associated with a specific source
59
59
 
60
60
  def description_set(id, description)
@@ -63,7 +63,7 @@ module Wavefront
63
63
  'application/json')
64
64
  end
65
65
 
66
- # DELETE /api/v2/source/id/description
66
+ # DELETE /api/v2/source/{id}/description
67
67
  # Remove description from a specific source
68
68
 
69
69
  def description_delete(id)
@@ -71,7 +71,7 @@ module Wavefront
71
71
  api.delete([id, 'description'].uri_concat)
72
72
  end
73
73
 
74
- # GET /api/v2/source/id
74
+ # GET /api/v2/source/{id}
75
75
  # Get a specific source for a customer.
76
76
  #
77
77
  # @param id [String] ID of the source
@@ -85,10 +85,10 @@ module Wavefront
85
85
  api.get(fragments.uri_concat)
86
86
  end
87
87
 
88
- # PUT /api/v2/source/id
88
+ # PUT /api/v2/source/{id}
89
89
  # Update metadata (description or tags) for a specific source.
90
90
  #
91
- # @param id [String] a Wavefront alert ID
91
+ # @param id [String] a Wavefront source ID
92
92
  # @param body [Hash] key-value hash of the parameters you wish
93
93
  # to change
94
94
  # @param modify [true, false] if true, use {#describe()} to get
@@ -0,0 +1,126 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'defs/constants'
4
+ require_relative 'core/api'
5
+
6
+ module Wavefront
7
+ #
8
+ # View and manage the Wavefront span sampling policy.
9
+ #
10
+ class SpanSamplingPolicy < CoreApi
11
+ def update_keys
12
+ %i[name active expression description samplingPercent]
13
+ end
14
+
15
+ # GET /api/v2/spansamplingpolicy
16
+ # Get all sampling policies for a customer
17
+ #
18
+ # @param offset [Int] policy at which the list begins
19
+ # @param limit [Int] the number of policies to return
20
+ # @return [Wavefront::Response]
21
+ #
22
+ def list(offset = 0, limit = 100)
23
+ api.get('', offset: offset, limit: limit)
24
+ end
25
+
26
+ # POST /api/v2/spansamplingpolicy
27
+ # Create a span sampling policy
28
+ #
29
+ # @param body [Hash] description of policy
30
+ # @return [Wavefront::Response]
31
+ #
32
+ def create(body)
33
+ raise ArgumentError unless body.is_a?(Hash)
34
+
35
+ api.post('', body, 'application/json')
36
+ end
37
+
38
+ # DELETE /api/v2/spansamplingpolicy/{id}
39
+ # Delete a specific span sampling policy
40
+ #
41
+ # Deleting an active policy moves it to 'trash', from where it can
42
+ # be restored with an #undelete operation. Deleting an policy in
43
+ # 'trash' removes it for ever.
44
+ #
45
+ # @param id [String] ID of the policy
46
+ # @return [Wavefront::Response]
47
+ #
48
+ def delete(id)
49
+ wf_spansamplingpolicy_id?(id)
50
+ api.delete(id)
51
+ end
52
+
53
+ # GET /api/v2/spansamplingpolicy/deleted
54
+ # Get all deleted sampling policies for a customer
55
+ # @return [Wavefront::Response]
56
+ #
57
+ def deleted
58
+ api.get('deleted')
59
+ end
60
+
61
+ # GET /api/v2/spansamplingpolicy/{id}
62
+ # GET /api/v2/spansamplingpolicy/{id}/history/{version}
63
+ # Get a specific span sampling policy
64
+ # Get a specific policy / Get a specific historical version of a specific
65
+ # sampling policy
66
+ #
67
+ # @param id [String] ID of the policy
68
+ # @param version [Integer] version of policy
69
+ # @return [Wavefront::Response]
70
+ #
71
+ def describe(id, version = nil)
72
+ wf_spansamplingpolicy_id?(id)
73
+ wf_version?(version) if version
74
+ fragments = [id]
75
+ fragments += ['history', version] if version
76
+ api.get(fragments.uri_concat)
77
+ end
78
+
79
+ # PUT /api/v2/spansamplingpolicy/{id}
80
+ # Update a specific span sampling policy
81
+ #
82
+ # @param id [String] a Wavefront span-sampling policy ID
83
+ # @param body [Hash] key-value hash of the parameters you wish
84
+ # to change
85
+ # @param modify [true, false] if true, use {#describe()} to get
86
+ # a hash describing the existing object, and modify that with
87
+ # the new body. If false, pass the new body straight through.
88
+ # @return [Wavefront::Response]
89
+
90
+ def update(id, body, modify = true)
91
+ wf_spansamplingpolicy_id?(id)
92
+ raise ArgumentError unless body.is_a?(Hash)
93
+
94
+ return api.put(id, body, 'application/json') unless modify
95
+
96
+ api.put(id, hash_for_update(describe(id).response, body),
97
+ 'application/json')
98
+ end
99
+
100
+ # GET /api/v2/spansamplingpolicy/{id}/history
101
+ # Get the version history of a specific sampling policy
102
+ #
103
+ # @param id [String] ID of the policy
104
+ # @return [Wavefront::Response]
105
+ #
106
+ def history(id, offset = nil, limit = nil)
107
+ wf_spansamplingpolicy_id?(id)
108
+ qs = {}
109
+ qs[:offset] = offset if offset
110
+ qs[:limit] = limit if limit
111
+
112
+ api.get([id, 'history'].uri_concat, qs)
113
+ end
114
+
115
+ # POST /api/v2/spansamplingpolicy/{id}/undelete
116
+ # Restore a deleted span sampling policy
117
+ #
118
+ # @param id [String] ID of the policy
119
+ # @return [Wavefront::Response]
120
+ #
121
+ def undelete(id)
122
+ wf_spansamplingpolicy_id?(id)
123
+ api.post([id, 'undelete'].uri_concat)
124
+ end
125
+ end
126
+ end
@@ -11,6 +11,6 @@ class String
11
11
  # @return [String] a URI path
12
12
  #
13
13
  def tagescape
14
- gsub(/"/, '\"')
14
+ gsub('"', '\"')
15
15
  end
16
16
  end
@@ -23,7 +23,7 @@ module Wavefront
23
23
  # @raise Wavefront::InvalidTimestamp
24
24
  #
25
25
  def parse_time(time, in_ms = false)
26
- return relative_time(time, in_ms) if time.to_s.match?(/^[\-+]/)
26
+ return relative_time(time, in_ms) if time.to_s.match?(/^[-+]/)
27
27
 
28
28
  ParseTime.new(time, in_ms).parse!
29
29
  end
@@ -55,7 +55,7 @@ module Wavefront
55
55
  end
56
56
 
57
57
  def parse!
58
- method = ('parse_time_' + t.class.name.downcase).to_sym
58
+ method = "parse_time_#{t.class.name.downcase}".to_sym
59
59
  send(method)
60
60
  rescue StandardError
61
61
  raise Wavefront::Exception::InvalidTimestamp, t
@@ -49,7 +49,7 @@ module Wavefront
49
49
  api.post("?sendEmail=#{send_email}", body, 'application/json')
50
50
  end
51
51
 
52
- # DELETE /api/v2/user/id
52
+ # DELETE /api/v2/user/{id}
53
53
  # Delete a specific user. See also #delete_users.
54
54
  #
55
55
  # @param id [String] ID of the user
@@ -61,7 +61,7 @@ module Wavefront
61
61
  api.delete(id)
62
62
  end
63
63
 
64
- # GET /api/v2/user/id
64
+ # GET /api/v2/user/{id}
65
65
  # Retrieves a user by identifier (email addr).
66
66
  #
67
67
  # @param id [String] ID of the user
@@ -73,7 +73,7 @@ module Wavefront
73
73
  api.get(id)
74
74
  end
75
75
 
76
- # PUT /api/v2/user/id
76
+ # PUT /api/v2/user/{id}
77
77
  # Update a specific user definition.
78
78
  #
79
79
  # @param id [String] a Wavefront user ID
@@ -124,7 +124,7 @@ module Wavefront
124
124
  'application/json')
125
125
  end
126
126
 
127
- # PUT /api/v2/user/id/grant
127
+ # POST /api/v2/user/{id}/grant
128
128
  # Grants a specific user permission.
129
129
  #
130
130
  # @param id [String] ID of the user
@@ -147,7 +147,7 @@ module Wavefront
147
147
  'application/x-www-form-urlencoded')
148
148
  end
149
149
 
150
- # PUT /api/v2/user/id/revoke
150
+ # POST /api/v2/user/{id}/revoke
151
151
  # Revokes a specific user permission.
152
152
  #
153
153
  # @param id [String] ID of the user
@@ -16,8 +16,8 @@ module Wavefront
16
16
 
17
17
  # GET /api/v2/usergroup
18
18
  # Get all user groups for a customer
19
- # @param offset [Int] alert at which the list begins
20
- # @param limit [Int] the number of alerts to return
19
+ # @param offset [Int] usergroup at which the list begins
20
+ # @param limit [Int] the number of usergroups to return
21
21
  # @return [Wavefront::Response]
22
22
  #
23
23
  def list(offset = 0, limit = 100)
@@ -81,7 +81,7 @@ module Wavefront
81
81
  # commas in tags and descriptions. This might be too restrictive,
82
82
  # but if it is, this is the only place we need to change it.
83
83
  #
84
- if str.is_a?(String) && str.size < 1024 && str =~ /^[\-\w .,]*$/
84
+ if str.is_a?(String) && str.size < 1024 && str =~ /^[-\w .,]*$/
85
85
  return true
86
86
  end
87
87
 
@@ -164,8 +164,7 @@ module Wavefront
164
164
  #
165
165
  # @param version [Integer] the version number to validate
166
166
  # @return True if the version is valid
167
- # @raise Wavefront::Exception::InvalidVersion if the alert ID is
168
- # not valid
167
+ # @raise Wavefront::Exception::InvalidVersion if the ID is not valid
169
168
  #
170
169
  def wf_version?(version)
171
170
  version = version.to_i if version.is_a?(String) && version =~ /^\d+$/
@@ -197,7 +196,7 @@ module Wavefront
197
196
  def wf_point_tag?(key, val)
198
197
  if key && val && (key.size + val.size < 254) &&
199
198
  key =~ /^[\w\-.:]+$/ && val !~ /\\$/
200
- return
199
+ return false
201
200
  end
202
201
 
203
202
  raise Wavefront::Exception::InvalidTag, "#{key}=#{val}"
@@ -256,7 +255,7 @@ module Wavefront
256
255
  # dashboard ID is not valid
257
256
  #
258
257
  def wf_dashboard_id?(id)
259
- return true if id.is_a?(String) && id.size < 256 && id.match(/^[\w\-]+$/)
258
+ return true if id.is_a?(String) && id.size < 256 && id.match(/^[\w-]+$/)
260
259
 
261
260
  raise Wavefront::Exception::InvalidDashboardId, id
262
261
  end
@@ -391,7 +390,7 @@ module Wavefront
391
390
  # is not valid
392
391
  #
393
392
  def wf_source_id?(source)
394
- if source.is_a?(String) && source.match(/^[\w.\-]+$/) &&
393
+ if source.is_a?(String) && source.match(/^[\w.-]+$/) &&
395
394
  source.size < 1024
396
395
  return true
397
396
  end
@@ -589,10 +588,10 @@ module Wavefront
589
588
  # ID is not valid
590
589
  #
591
590
  def wf_account_id?(id)
592
- return true if wf_user_id?(id)
591
+ true if wf_user_id?(id)
593
592
  rescue Wavefront::Exception::InvalidUserId
594
593
  begin
595
- return true if wf_serviceaccount_id?(id)
594
+ true if wf_serviceaccount_id?(id)
596
595
  rescue Wavefront::Exception::InvalidServiceAccountId
597
596
  raise Wavefront::Exception::InvalidAccountId, id
598
597
  end
@@ -609,6 +608,17 @@ module Wavefront
609
608
  raise Wavefront::Exception::InvalidMonitoredClusterId, id
610
609
  end
611
610
 
611
+ # Ensure the given argument is a valid monitored application ID
612
+ # @param id [String]
613
+ # @raise Wavefront::Exception::InvalidMonitoredApplicationId if the ID is
614
+ # not valid
615
+ #
616
+ def wf_monitoredapplication_id?(id)
617
+ return true if id.is_a?(String) && id.size < 256 && id =~ /^[a-z0-9\-_]+$/
618
+
619
+ raise Wavefront::Exception::InvalidMonitoredApplicationId, id
620
+ end
621
+
612
622
  # Ensure the given value is a valid sampling rate.
613
623
  # @param rate [Float]
614
624
  # @raise Wavefront::Exception::InvalidSamplingValue
@@ -654,6 +664,19 @@ module Wavefront
654
664
 
655
665
  raise Wavefront::Exception::InvalidMetricsPolicyId, id
656
666
  end
667
+
668
+ # Ensure the given argument is a valid Wavefront Span Sampling Policy ID.
669
+ # So far as I can tell they're just strings.
670
+ #
671
+ # @param id [String] the span sampling policy ID to validate
672
+ # @return true if the ID is valid
673
+ # @raise Wavefront::Exception::InvalidSpanSamplingPolicyId if the ID is
674
+ # not valid
675
+ def wf_spansamplingpolicy_id?(id)
676
+ return true if id.is_a?(String)
677
+
678
+ raise Wavefront::Exception::InvalidSpanSamplingPolicyId, id
679
+ end
657
680
  end
658
681
  # rubocop:enable Metrics/ModuleLength
659
682
  end
@@ -35,7 +35,7 @@ module Wavefront
35
35
  api.post('', body, 'application/json')
36
36
  end
37
37
 
38
- # DELETE /api/v2/webhook/id
38
+ # DELETE /api/v2/webhook/{id}
39
39
  # Delete a specific webhook.
40
40
  #
41
41
  # @param id [String, Integer] ID of the webhook
@@ -46,7 +46,7 @@ module Wavefront
46
46
  api.delete(id)
47
47
  end
48
48
 
49
- # GET /api/v2/webhook/id
49
+ # GET /api/v2/webhook/{id}
50
50
  # Get a specific webhook.
51
51
  #
52
52
  # @param id [String, Integer] ID of the webhook
@@ -57,7 +57,7 @@ module Wavefront
57
57
  api.get(id)
58
58
  end
59
59
 
60
- # PUT /api/v2/webhook/id
60
+ # PUT /api/v2/webhook/{id}
61
61
  # Update a specific webhook.
62
62
  #
63
63
  # @param id [String] a Wavefront webhook ID
@@ -88,6 +88,7 @@ module Wavefront
88
88
  writer.close
89
89
  end
90
90
 
91
+ # POST /report
91
92
  # A wrapper to the writer class's #write method.
92
93
  # Writers implement this method differently, Check the
93
94
  # appropriate class documentation for @return information etc.
@@ -6,10 +6,23 @@ require_relative '../core/api_caller'
6
6
  module Wavefront
7
7
  module Writer
8
8
  #
9
- # Send points direct to Wavefront's API. This requires an
10
- # endpoint, a token, and HTTPS egress.
9
+ # Send points direct to Wavefront's API. This requires an endpoint, a
10
+ # token, and HTTPS egress.
11
+ #
12
+ # Points are sent in batches of BATCH_SIZE. We attempt to make a summary
13
+ # of how many points are sent or rejected, but it's quantized by the batch
14
+ # size.
15
+ #
16
+ # TODO I think this needs a composite response. It makes one or more API
17
+ # calls depending on the amount of metrics to be sent, and the CLI needs
18
+ # to know if there was anything other than a 200. Options are to return
19
+ # the first failure when it happens, or to try all the chunks and return
20
+ # the last non-200, or the highest numbered return code, or some other
21
+ # indication of failure.
11
22
  #
12
23
  class Api < Core
24
+ BATCH_SIZE = 100
25
+
13
26
  def open
14
27
  @conn = Wavefront::ApiCaller.new(self, creds, opts)
15
28
  end
@@ -32,7 +45,6 @@ module Wavefront
32
45
 
33
46
  def send_point(body)
34
47
  _send_point(body)
35
- summary.sent += body.size
36
48
  true
37
49
  rescue StandardError => e
38
50
  summary.unsent += body.size
@@ -52,15 +64,26 @@ module Wavefront
52
64
  send_point(body)
53
65
  end
54
66
 
55
- # Send points in batches of a hundred. I'm not sure exactly
56
- # how much the API can cope with in a single call, so this
57
- # might change.
67
+ # Send points in batches of BATCH_SIZE. I'm not sure exactly how much the
68
+ # API can cope with in a single call, so this might change.
69
+ # @return [Nil]
58
70
  #
71
+ # rubocop:disable Metrics/MethodLength
59
72
  def _send_point(body)
60
- body.each_slice(100) do |p|
61
- conn.post('/?f=wavefront', p.join("\n"), 'application/octet-stream')
73
+ body.each_slice(BATCH_SIZE) do |p|
74
+ ret = conn.post('/?f=wavefront', p.join("\n"),
75
+ 'application/octet-stream')
76
+
77
+ if ret.ok?
78
+ logger.log("sent #{BATCH_SIZE} points", :debug)
79
+ summary.sent += p.count
80
+ else
81
+ logger.log("failed to send #{BATCH_SIZE} points", :debug)
82
+ summary.unsent += p.count
83
+ end
62
84
  end
63
85
  end
86
+ # rubocop:enable Metrics/MethodLength
64
87
  end
65
88
  end
66
89
  end
@@ -112,7 +112,7 @@ module Wavefront
112
112
  ret = [points].flatten
113
113
  return ret unless prefix
114
114
 
115
- ret.map { |pt| pt.tap { |p| p[:path] = prefix + '.' + p[:path] } }
115
+ ret.map { |pt| pt.tap { |p| p[:path] = "#{prefix}.#{p[:path]}" } }
116
116
  end
117
117
 
118
118
  # Filter invalid points out of an array of points
data/lib/wavefront_sdk.rb CHANGED
@@ -4,7 +4,7 @@
4
4
  #
5
5
  require 'pathname'
6
6
 
7
- libdir = Pathname.new(__dir__) + 'wavefront-sdk'
7
+ libdir = Pathname.new(__dir__).join('wavefront-sdk')
8
8
 
9
9
  libdir.children.select { |f| f.extname == '.rb' }.each do |f|
10
10
  require_relative f
data/spec/constants.rb CHANGED
@@ -19,8 +19,8 @@ DUMMY_RESPONSE = '{"status":{"result":"OK","message":"","code":200},' \
19
19
  '"response":{"items":[{"name":"test data"}],"offset":0,' \
20
20
  '"limit":100,"totalItems":3,"moreItems":false}}'
21
21
 
22
- RESOURCE_DIR = (Pathname.new(__FILE__).dirname +
23
- 'wavefront-sdk' + 'resources').freeze
22
+ RESOURCE_DIR = Pathname.new(__FILE__).dirname.join('wavefront-sdk',
23
+ 'resources').freeze
24
24
 
25
25
  U_ACL_1 = 'someone@example.com'
26
26
  U_ACL_2 = 'other@elsewhere.com'
data/spec/spec_helper.rb CHANGED
@@ -10,7 +10,7 @@ require_relative 'constants'
10
10
 
11
11
  # Abstract class which sets up everything needed by the API tests
12
12
  #
13
- class WavefrontTestBase < MiniTest::Test
13
+ class WavefrontTestBase < Minitest::Test
14
14
  attr_reader :wf, :wf_noop, :headers, :invalid_id, :valid_id
15
15
 
16
16
  def initialize(args)
@@ -0,0 +1,53 @@
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 AccessPolicy class
8
+ #
9
+ class WavefrontAccessPolicyTest < WavefrontTestBase
10
+ def test_describe
11
+ assert_gets('/api/v2/accesspolicy') { wf.describe }
12
+ end
13
+
14
+ def test_update
15
+ assert_puts('/api/v2/accesspolicy', payload.to_json) do
16
+ wf.update(payload)
17
+ end
18
+ end
19
+
20
+ def test_validate
21
+ assert_gets('/api/v2/accesspolicy/validate?ip=1.2.3.4') do
22
+ wf.validate('1.2.3.4')
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def api_class
29
+ 'accesspolicy'
30
+ end
31
+
32
+ def payload
33
+ {
34
+ status: {
35
+ result: 'OK',
36
+ message: 'string',
37
+ code: 0
38
+ },
39
+ response: {
40
+ customer: 'string',
41
+ lastUpdatedMs: 0,
42
+ policyRules: [
43
+ {
44
+ name: 'string',
45
+ description: 'string',
46
+ subnet: 'string',
47
+ action: 'ALLOW'
48
+ }
49
+ ]
50
+ }
51
+ }
52
+ end
53
+ end
@@ -179,6 +179,18 @@ class WavefrontAccountTest < WavefrontTestBase
179
179
  assert_raises(ArgumentError) { wf.validate_accounts }
180
180
  end
181
181
 
182
+ def test_admins
183
+ assert_gets('/api/v2/account/user/admin') { wf.admins }
184
+ end
185
+
186
+ def test_update_perms
187
+ assert_invalid_id { wf.update_perms(invalid_id, perms_payload) }
188
+
189
+ assert_puts("/api/v2/account/user/#{user_id}", perms_payload.to_json) do
190
+ wf.update_perms(user_id, perms_payload, false)
191
+ end
192
+ end
193
+
182
194
  private
183
195
 
184
196
  def api_class
@@ -203,6 +215,10 @@ class WavefrontAccountTest < WavefrontTestBase
203
215
  2659191e-aad4-4302-a94e-9667e1515678]
204
216
  end
205
217
 
218
+ def user_id
219
+ 'user@example.com'
220
+ end
221
+
206
222
  def invalid_role
207
223
  %w[bad_role]
208
224
  end
@@ -212,7 +228,7 @@ class WavefrontAccountTest < WavefrontTestBase
212
228
  end
213
229
 
214
230
  def id_list
215
- %w[sa:test user@example.com]
231
+ ['sa:test', user_id]
216
232
  end
217
233
 
218
234
  def invalid_permission
@@ -235,4 +251,19 @@ class WavefrontAccountTest < WavefrontTestBase
235
251
  { emailAddress: id,
236
252
  groups: %w[browse] }
237
253
  end
254
+
255
+ def perms_payload
256
+ {
257
+ identifier: 'user@example.com',
258
+ groups: [
259
+ 'user_management'
260
+ ],
261
+ userGroups: [
262
+ '8b23136b-ecd2-4cb5-8c92-62477dcc4090'
263
+ ],
264
+ roles: [
265
+ 'Role'
266
+ ]
267
+ }
268
+ end
238
269
  end
@@ -35,6 +35,23 @@ class WavefrontAlertTest < WavefrontTestBase
35
35
  assert_invalid_id { wf.unsnooze(invalid_id) }
36
36
  end
37
37
 
38
+ def test_check_query
39
+ query = {
40
+ inputQuery: 'string',
41
+ translatedInput: 'sum(http_requests_total{method="GET"})',
42
+ queryType: 'PromQL'
43
+ }
44
+ assert_posts('/api/v2/alert/checkQuery', query.to_json) do
45
+ wf.check_query(query)
46
+ end
47
+ end
48
+
49
+ def test_preview
50
+ assert_posts('/api/v2/alert/preview', payload.to_json) do
51
+ wf.preview(payload)
52
+ end
53
+ end
54
+
38
55
  def test_summary
39
56
  assert_gets('/api/v2/alert/summary') { wf.summary }
40
57
  end
@@ -8,7 +8,7 @@ require_relative '../../../lib/wavefront-sdk/core/exception'
8
8
 
9
9
  # Test user mixins
10
10
  #
11
- class WavefrontUserMixinsTest < MiniTest::Test
11
+ class WavefrontUserMixinsTest < Minitest::Test
12
12
  include Wavefront::Mixin::User
13
13
  include Wavefront::Validators
14
14
 
@@ -10,6 +10,18 @@ class WavefrontApiTokenTest < WavefrontTestBase
10
10
  assert_gets('/api/v2/apitoken') { wf.list }
11
11
  end
12
12
 
13
+ def test_list_customer_tokens
14
+ assert_gets('/api/v2/apitoken/customertokens') { wf.list_customer_tokens }
15
+ end
16
+
17
+ def test_describe_customer_token
18
+ assert_invalid_id { wf.describe_customer_token(invalid_token_id) }
19
+
20
+ assert_gets("/api/v2/apitoken/customertokens/#{token_id}") do
21
+ wf.describe_customer_token(token_id)
22
+ end
23
+ end
24
+
13
25
  def test_create
14
26
  assert_posts('/api/v2/apitoken', 'null') { wf.create }
15
27
  assert_raises(ArgumentError) { wf.create('test') }
@@ -0,0 +1,13 @@
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 Cluster class
8
+ #
9
+ class WavefrontClusterTest < WavefrontTestBase
10
+ def test_describe
11
+ assert_gets('/api/v2/cluster/info') { wf.describe }
12
+ end
13
+ end