wavefront-sdk 5.4.4 → 7.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/release.yml +3 -3
  3. data/.github/workflows/test.yml +2 -2
  4. data/.rubocop.yml +1 -3
  5. data/HISTORY.md +17 -0
  6. data/README.md +5 -5
  7. data/lib/wavefront-sdk/api_mixins/acl.rb +1 -1
  8. data/lib/wavefront-sdk/core/api.rb +1 -1
  9. data/lib/wavefront-sdk/core/api_caller.rb +1 -7
  10. data/lib/wavefront-sdk/core/exception.rb +2 -0
  11. data/lib/wavefront-sdk/core/response.rb +1 -1
  12. data/lib/wavefront-sdk/credentials.rb +3 -5
  13. data/lib/wavefront-sdk/defs/version.rb +1 -1
  14. data/lib/wavefront-sdk/event.rb +64 -1
  15. data/lib/wavefront-sdk/maintenancewindow.rb +1 -1
  16. data/lib/wavefront-sdk/metric.rb +2 -2
  17. data/lib/wavefront-sdk/metric_helper.rb +1 -1
  18. data/lib/wavefront-sdk/metricspolicy.rb +57 -0
  19. data/lib/wavefront-sdk/paginator/base.rb +1 -1
  20. data/lib/wavefront-sdk/search.rb +3 -3
  21. data/lib/wavefront-sdk/spy.rb +22 -0
  22. data/lib/wavefront-sdk/support/mixins.rb +1 -1
  23. data/lib/wavefront-sdk/support/parse_time.rb +1 -1
  24. data/lib/wavefront-sdk/user.rb +1 -1
  25. data/lib/wavefront-sdk/validators.rb +18 -3
  26. data/lib/wavefront-sdk/write.rb +2 -2
  27. data/lib/wavefront-sdk/writers/api.rb +1 -1
  28. data/lib/wavefront-sdk/writers/core.rb +1 -1
  29. data/lib/wavefront-sdk/writers/proxy.rb +71 -0
  30. data/lib/wavefront-sdk/writers/socket.rb +15 -27
  31. data/lib/wavefront_sdk.rb +1 -1
  32. data/spec/constants.rb +2 -2
  33. data/spec/test_mixins/general.rb +1 -1
  34. data/spec/wavefront-sdk/core/api_spec.rb +1 -1
  35. data/spec/wavefront-sdk/core/response_spec.rb +2 -2
  36. data/spec/wavefront-sdk/credentials_spec.rb +9 -13
  37. data/spec/wavefront-sdk/event_spec.rb +46 -0
  38. data/spec/wavefront-sdk/metric_helper_spec.rb +2 -0
  39. data/spec/wavefront-sdk/metricspolicy_spec.rb +94 -0
  40. data/spec/wavefront-sdk/misc_spec.rb +2 -2
  41. data/spec/wavefront-sdk/savedsearch_spec.rb +2 -2
  42. data/spec/wavefront-sdk/spy_spec.rb +27 -0
  43. data/spec/wavefront-sdk/user_spec.rb +2 -2
  44. data/spec/wavefront-sdk/validators_spec.rb +10 -0
  45. data/spec/wavefront-sdk/write_spec.rb +1 -1
  46. data/spec/wavefront-sdk/writers/{unix_spec.rb → proxy_spec.rb} +29 -31
  47. data/spec/wavefront-sdk/writers/socket_spec.rb +26 -24
  48. data/wavefront-sdk.gemspec +10 -11
  49. metadata +27 -97
  50. data/lib/wavefront-sdk/writers/unix.rb +0 -59
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1f0aafb012ded5a99a13ee3553d686e0552f5c4cae8da39e70139f6882aadcc9
4
- data.tar.gz: b033a54d99e7a8402d04fd3555d56c53c765b655f89c59c6b1b27e2880ec5945
3
+ metadata.gz: 5d89604feef126265df36a17289e1f1320b07e30787f7596d195ea76284526c1
4
+ data.tar.gz: 393ea7ba3b44646eb1b67c6976713941530b36943ded7e12c4f6a5ee1d87ca7f
5
5
  SHA512:
6
- metadata.gz: e647c51a97b626d080d7d666e17b81c6ead709b8780f0bb3f2897fc34d326df65d6c524359f4ea461520ef75cf7d29883f1f822feb774b06a3d822ce7717e882
7
- data.tar.gz: c6602237acfdf5c18820e086071e1f06cc73199fc45ef02e689f091fec36208936b3618c5ec0d1464fff2773f4424bb49d0be3c9ba394da5d31143a14e2aed71
6
+ metadata.gz: ccd6b23b76944bbac1a1790b61b79365dfb2da530c8c851f19052c57128db3744e52aa29b81194709315925d87b4627eef6c96079fe5a10534fbbf358cd43dfb
7
+ data.tar.gz: 4228c14a3f026d74e98dfae97a22a689772bfd4ae590820832b5ffe5af8c052e2c63a9ace60cea66c6038f50d6a3495c564c38ddb7b0def1b4013d8b6ce421d5
@@ -11,14 +11,14 @@ jobs:
11
11
  runs-on: ubuntu-latest
12
12
 
13
13
  steps:
14
- - uses: actions/checkout@v2
14
+ - uses: actions/checkout@v3
15
15
  - name: Set env
16
16
  run: echo "RELEASE_VERSION=$(echo ${GITHUB_REF:10})" >> $GITHUB_ENV
17
17
 
18
- - name: Set up Ruby 2.7
18
+ - name: Set up Ruby 3.0
19
19
  uses: ruby/setup-ruby@v1
20
20
  with:
21
- ruby-version: 2.7
21
+ ruby-version: 3.0
22
22
  - run: bundle install
23
23
 
24
24
  - name: Run tests
@@ -9,9 +9,9 @@ jobs:
9
9
  runs-on: ubuntu-latest
10
10
  strategy:
11
11
  matrix:
12
- ruby-version: [2.4.10, 2.5.8, 2.6.6, 2.7.2, 3.0.0]
12
+ ruby-version: [2.7.7, 3.1.3, 3.2.0]
13
13
  steps:
14
- - uses: actions/checkout@v2
14
+ - uses: actions/checkout@v3
15
15
  - name: Set up Ruby
16
16
  uses: ruby/setup-ruby@v1
17
17
  with:
data/.rubocop.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
 
3
3
  AllCops:
4
- TargetRubyVersion: 2.4
4
+ TargetRubyVersion: 2.7
5
5
  NewCops: enable
6
6
 
7
7
  require:
@@ -14,7 +14,5 @@ Layout/LineLength:
14
14
  Max: 80
15
15
  Metrics/ClassLength:
16
16
  Max: 150
17
- Style/StringConcatenation:
18
- Enabled: false
19
17
  Style/OptionalBooleanParameter:
20
18
  Enabled: false
data/HISTORY.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # Changelog
2
2
 
3
+ ## 7.0.0 (2023-01-19)
4
+ * Drop support for Ruby 2.5. (Breaking change.)
5
+ * Drop support for Ruby 2.6. (Breaking change.)
6
+ * Bugfix for `metricspolicy` API.
7
+
8
+ ## 6.0.0 (2021-07-16)
9
+ * Drop support for Ruby 2.4. (Breaking change.)
10
+ * Change the name of the proxy writer from `socket` to `proxy`. (Breaking
11
+ change.)
12
+ * Change the name of the Unix datagram socket writer from `unix` to `socket`.
13
+ * added `Wavefront::Event#alert_firing_details`.
14
+ * added `Wavefront::Event#alert_queries_slug`.
15
+ * added `Wavefront::Event#events`.
16
+ * added `Wavefront::Event#alert_firings`.
17
+ * Add `Wavefront::MetricsPolicy`.
18
+ * Add `Wavefront::Spy#deltas`.
19
+
3
20
  ## 5.4.4 (2021-02-01)
4
21
  * Fix credential validation on writer classes.
5
22
  * Improve tests for writer classes
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # wavefront-sdk
2
- ![Test](https://github.com/snltd/wavefront-sdk/workflows/Test/badge.svg) ![Release](https://github.com/snltd/wavefront-sdk/workflows/Release/badge.svg) [![Code Climate](https://codeclimate.com/github/snltd/wavefront-sdk/badges/gpa.svg)](https://codeclimate.com/github/snltd/wavefront-sdk) [![Issue Count](https://codeclimate.com/github/snltd/wavefront-sdk/badges/issue_count.svg)](https://codeclimate.com/github/snltd/wavefront-sdk) [![Gem Version](https://badge.fury.io/rb/wavefront-sdk.svg)](https://badge.fury.io/rb/wavefront-sdk) ![](http://ruby-gem-downloads-badge.herokuapp.com/wavefront-sdk?type=total)
2
+ [![Test](https://github.com/snltd/wavefront-sdk/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/snltd/wavefront-sdk/actions/workflows/test.yml) [![Release](https://github.com/snltd/wavefront-sdk/actions/workflows/release.yml/badge.svg?branch=master)](https://github.com/snltd/wavefront-sdk/actions/workflows/release.yml) [![Code Climate](https://codeclimate.com/github/snltd/wavefront-sdk/badges/gpa.svg)](https://codeclimate.com/github/snltd/wavefront-sdk) [![Issue Count](https://codeclimate.com/github/snltd/wavefront-sdk/badges/issue_count.svg)](https://codeclimate.com/github/snltd/wavefront-sdk) [![Gem Version](https://badge.fury.io/rb/wavefront-sdk.svg)](https://badge.fury.io/rb/wavefront-sdk) ![](http://ruby-gem-downloads-badge.herokuapp.com/wavefront-sdk?type=total)
3
3
 
4
4
  This is a Ruby SDK for v2 of
5
5
  [Wavefront](https://www.wavefront.com/)'s public API. It aims to be
@@ -24,7 +24,7 @@ or to build locally,
24
24
  $ gem build wavefront-sdk.gemspec
25
25
  ```
26
26
 
27
- `wavefront-sdk` requires Ruby >= 2.4. All its dependencies are pure
27
+ `wavefront-sdk` requires Ruby >= 2.7. All its dependencies are pure
28
28
  Ruby, right the way down, so a compiler should never be required to
29
29
  install it.
30
30
 
@@ -41,7 +41,7 @@ method will return a `Wavefront::Response` object. This object has
41
41
  `status` and `response` methods. `status` always yields a structure
42
42
  containing `result`, `message` and `code` fields which can be
43
43
  inspected to ensure an API call was processed successfully.
44
- `response` gives you a the JSON response from the API, conveniently
44
+ `response` gives you the JSON response from the API, conveniently
45
45
  processed and turned into a [`Map`](https://github.com/ahoward/map)
46
46
  object. Map objects can be interrogated in various ways. For
47
47
  instance `map['items']`, `map[:items]` and `map.items` will all get
@@ -203,7 +203,7 @@ wf.close
203
203
  ```
204
204
 
205
205
  Alternatively, pass `false` as the second argument to `Write#write`.
206
- (This is the legacy method, kept in for backward compatability.)
206
+ (This is the legacy method, kept in for backward compatibility.)
207
207
 
208
208
  ```ruby
209
209
  wf = Wavefront::Write.new(Wavefront::Credentials.new.proxy)
@@ -220,7 +220,7 @@ but other methods are supported via the `writer` option.
220
220
  wf = Wavefront::Write.new(Wavefront::Credentials.new.creds, writer: :api)
221
221
 
222
222
  # To send points via a local Unix socket
223
- wf = Wavefront::Write.new(socket: '/tmp/wf_sock', { writer: :unix })
223
+ wf = Wavefront::Write.new({ socket: '/tmp/wf_sock'}, { writer: :socket })
224
224
 
225
225
  # To send points over HTTP
226
226
  wf = Wavefront::Write.new(Wavefront::Credentials.new.creds, writer: :http)
@@ -80,7 +80,7 @@ module Wavefront
80
80
  end
81
81
 
82
82
  def valid_acl_body?(list)
83
- return true if list.is_a?(Array) && list.all? { |h| h.is_a?(String) }
83
+ return true if list.is_a?(Array) && list.all?(String)
84
84
 
85
85
  raise ArgumentError
86
86
  end
@@ -94,7 +94,7 @@ module Wavefront
94
94
  def hash_for_update(old, new)
95
95
  raise ArgumentError unless old.is_a?(Hash) && new.is_a?(Hash)
96
96
 
97
- Hash[old.merge(new).map { |k, v| [k.to_sym, v] }].select do |k, _v|
97
+ old.merge(new).transform_keys(&:to_sym).select do |k, _v|
98
98
  update_keys.include?(k)
99
99
  end
100
100
  end
@@ -229,14 +229,8 @@ module Wavefront
229
229
  return if noop
230
230
 
231
231
  pp args if debug
232
-
233
232
  resp = conn.public_send(method, *args)
234
-
235
- if debug
236
- require 'pp'
237
- pp resp
238
- end
239
-
233
+ pp resp if debug
240
234
  respond(resp)
241
235
  end
242
236
 
@@ -59,6 +59,8 @@ module Wavefront
59
59
 
60
60
  class InvalidMetricName < RuntimeError; end
61
61
 
62
+ class InvalidMetricsPolicyId < RuntimeError; end
63
+
62
64
  class InvalidMetricValue < RuntimeError; end
63
65
 
64
66
  class InvalidName < RuntimeError; end
@@ -51,7 +51,7 @@ module Wavefront
51
51
  # Were there items in the response?
52
52
  #
53
53
  def empty?
54
- response.items.size.zero?
54
+ response.items.empty?
55
55
  rescue StandardError
56
56
  false
57
57
  end
@@ -82,8 +82,8 @@ module Wavefront
82
82
  Array(Pathname.new(opts[:file]))
83
83
  else
84
84
  [Pathname.new('/etc/wavefront/credentials'),
85
- Pathname.new(ENV['HOME']) + '.wavefront.conf',
86
- Pathname.new(ENV['HOME']) + '.wavefront']
85
+ Pathname.new(Dir.home).join('.wavefront.conf'),
86
+ Pathname.new(Dir.home).join('.wavefront')]
87
87
  end
88
88
  end
89
89
 
@@ -128,9 +128,7 @@ module Wavefront
128
128
  # @return [Hash] options loaded from file. Each key becomes a symbol
129
129
  #
130
130
  def load_profile(file, profile = 'default')
131
- IniFile.load(file)[profile].each_with_object({}) do |(k, v), memo|
132
- memo[k.to_sym] = v
133
- end
131
+ IniFile.load(file)[profile].transform_keys(&:to_sym)
134
132
  rescue StandardError
135
133
  raise Wavefront::Exception::InvalidConfigFile, file
136
134
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  require 'pathname'
4
4
 
5
- WF_SDK_VERSION = '5.4.4'
5
+ WF_SDK_VERSION = '7.0.0'
6
6
  WF_SDK_LOCATION = Pathname.new(__dir__).parent.parent.parent
@@ -117,12 +117,75 @@ module Wavefront
117
117
  api.post([id, 'close'].uri_concat)
118
118
  end
119
119
 
120
- def valid_id?(id)
120
+ # GET /api/v2/event/{id}/alertFiringDetails
121
+ # Return details of a particular alert firing, including all the series
122
+ # that fired during the referred alert firing
123
+ #
124
+ # @param id [String] ID of the event
125
+ # @return [Wavefront::Response]
126
+ #
127
+ def alert_firing_details(id)
128
+ wf_event_id?(id)
129
+ api.get([id, 'alertFiringDetails'].uri_concat)
130
+ end
131
+
132
+ # GET /api/v2/event/{id}/alertQueriesSlug
133
+ # If the specified event is associated with an alert, returns a slug
134
+ # encoding the queries having to do with that alert firing or resolution
135
+ # @param id [String] ID of the event
136
+ # @return [Wavefront::Response]
137
+ #
138
+ def alert_queries_slug(id)
139
+ wf_event_id?(id)
140
+ api.get([id, 'alertQueriesSlug'].uri_concat)
141
+ end
142
+
143
+ # GET /api/v2/event/{id}/events
144
+ # List all related events for a specific firing event with a time span of
145
+ # one hour
146
+ # @param id [String] ID of the event
147
+ # @param opts [Hash] containing one or more of
148
+ # is_overlapped [Bool]
149
+ # rendering_method [Symbol,String] one of :HOST, :METRIC, :SIMILARITY
150
+ # limit [Integer]
151
+ # @return [Wavefront::Response]
152
+ #
153
+ def events(id, opts = {})
121
154
  wf_event_id?(id)
155
+
156
+ api.get([id, 'events'].uri_concat,
157
+ { isOverlapped: opts[:is_overlapped] || false,
158
+ renderingMethod: (opts[:rendering_method] || :HOST).to_s,
159
+ limit: opts[:limit] || nil }.compact)
160
+ end
161
+
162
+ # GET /api/v2/event/alertFirings
163
+ # Get firings events of an alert within a time range
164
+ # @param alert_id [String] ID of the alert
165
+ # @param opts [Hash] containing one or more of
166
+ # earliest_start [Integer] epoch ms timestamp
167
+ # latest_start [Integer] epoch ms timestamp
168
+ # ascending [Bool]
169
+ # limit [Integer]
170
+ # @return [Wavefront::Response]
171
+ #
172
+ def alert_firings(alert_id, opts = {})
173
+ wf_alert_id?(alert_id)
174
+
175
+ api.get('alertFirings',
176
+ { alertId: alert_id,
177
+ earliestStartTimeEpochMillis: opts[:earliest_start] || nil,
178
+ latestStartTimeEpochMillis: opts[:latest_start] || nil,
179
+ limit: opts[:limit] || nil,
180
+ asc: opts[:asc] || true }.compact)
122
181
  end
123
182
 
124
183
  private
125
184
 
185
+ def valid_id?(id)
186
+ wf_event_id?(id)
187
+ end
188
+
126
189
  def list_body(t_start, t_end, limit, cursor)
127
190
  { earliestStartTimeEpochMillis: parse_time(t_start, true),
128
191
  latestStartTimeEpochMillis: parse_time(t_end, true),
@@ -93,7 +93,7 @@ module Wavefront
93
93
  # @return [Wavefront::Response]
94
94
  #
95
95
  def pending(hours = 24)
96
- cutoff = Time.now.to_i + hours * 3600
96
+ cutoff = Time.now.to_i + (hours * 3600)
97
97
 
98
98
  ret = windows_in_state(:pending)
99
99
 
@@ -27,10 +27,10 @@ module Wavefront
27
27
  if cursor
28
28
  raise ArgumentError unless cursor.is_a?(String)
29
29
 
30
- query.<< [:c, cursor]
30
+ query << [:c, cursor]
31
31
  end
32
32
 
33
- sources.each { |source| query.<< [:h, source] }
33
+ sources.each { |source| query << [:h, source] }
34
34
 
35
35
  api.get('detail', query)
36
36
  end
@@ -37,7 +37,7 @@ module Wavefront
37
37
  def gauge(path, value, tags = nil)
38
38
  gauge = { path: path, ts: Time.now.to_i, value: value }
39
39
  gauge[:tags] = tags if tags
40
- @buf[:gauges].<< gauge
40
+ @buf[:gauges] << gauge
41
41
  end
42
42
 
43
43
  # These counters are internal, and specific to the SDK. When
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'core/api'
4
+
5
+ module Wavefront
6
+ #
7
+ # Manage and query Wavefront metrics policies
8
+ #
9
+ class MetricsPolicy < CoreApi
10
+ # GET /api/v2/metricspolicy
11
+ # Get the metrics policy
12
+ # GET /api/v2/metricspolicy/history/{version}
13
+ # Get a specific historical version of a metrics policy
14
+ # @param version [Integer] specify version to describe
15
+ # @return [Wavefront::Response]
16
+ #
17
+ def describe(version = nil)
18
+ if version
19
+ wf_version?(version)
20
+ api.get(['history', version].uri_concat)
21
+ else
22
+ api.get('')
23
+ end
24
+ end
25
+
26
+ # GET /api/v2/metricspolicy/history
27
+ # Get the version history of metrics policy
28
+ #
29
+ # @param offset [Integer] version at which the list begins
30
+ # @param limit [Integer] the number of versions to return
31
+ #
32
+ def history(offset = 0, limit = 100)
33
+ api.get('history', offset: offset, limit: limit)
34
+ end
35
+
36
+ # POST /api/v2/metricspolicy/revert/{version}
37
+ # Revert to a specific historical version of a metrics policy
38
+ # @param version [Integer] specify version to describe
39
+ # @return [Wavefront::Response]
40
+ #
41
+ def revert(version)
42
+ wf_version?(version)
43
+ api.post(['revert', version].uri_concat, nil, 'application/json')
44
+ end
45
+
46
+ # PUT /api/v2/metricspolicy
47
+ # Update the metrics policy
48
+ # @param body [Hash] hash describing metrics policy
49
+ # @return [Wavefront::Response]
50
+ #
51
+ def update(body)
52
+ raise ArgumentError unless body.is_a?(Hash)
53
+
54
+ api.put('', body, 'application/json')
55
+ end
56
+ end
57
+ end
@@ -166,7 +166,7 @@ module Wavefront
166
166
  end
167
167
 
168
168
  p_args = set_pagination(offset, page_size, p_args)
169
- resp.response.items.map { |i| y.<< i }
169
+ resp.response.items.map { |i| y << i }
170
170
  raise StopIteration unless resp.more_items?
171
171
  end
172
172
  end.lazy
@@ -98,7 +98,7 @@ module Wavefront
98
98
  end
99
99
 
100
100
  path = [entity]
101
- path.<< 'deleted' if deleted
101
+ path << 'deleted' if deleted
102
102
  api.post(path, body, 'application/json')
103
103
  end
104
104
 
@@ -119,8 +119,8 @@ module Wavefront
119
119
  raise ArgumentError unless entity.is_a?(String) && body.is_a?(Hash)
120
120
 
121
121
  path = [entity]
122
- path.<< 'deleted' if deleted
123
- path.<< facet || 'facets'
122
+ path << 'deleted' if deleted
123
+ path << (facet || 'facets')
124
124
  api.post(path, body, 'application/json')
125
125
  end
126
126
  # rubocop:enable Metrics/ParameterLists
@@ -32,6 +32,21 @@ module Wavefront
32
32
  api.get_stream('points', points_filter(sampling, filters), options)
33
33
  end
34
34
 
35
+ # GET /api/spy/deltas
36
+ # Gets new deltas that are added to existing time series.
37
+ # @param sampling [Float] see #points
38
+ # @param filter [Hash] see #points
39
+ # @param options [Hash] see #points
40
+ # @raise Wavefront::Exception::InvalidSamplingValue
41
+ # @return [Nil]
42
+ #
43
+ def deltas(sampling = 0.01, filters = {}, options = {})
44
+ wf_sampling_value?(sampling)
45
+ api.get_stream('deltas',
46
+ deltas_filter(sampling, filters),
47
+ options)
48
+ end
49
+
35
50
  # GET /api/spy/histograms
36
51
  # Gets new histograms that are added to existing time series.
37
52
  # @param sampling [Float] see #points
@@ -103,6 +118,13 @@ module Wavefront
103
118
  pointTagKey: filters.fetch(:tag_key, nil) }.compact
104
119
  end
105
120
 
121
+ def deltas_filter(sampling, filters)
122
+ { counter: filters.fetch(:prefix, nil),
123
+ host: filters.fetch(:host, nil),
124
+ sampling: sampling,
125
+ counterTagKey: filters.fetch(:tag_key, nil) }.compact
126
+ end
127
+
106
128
  def histograms_filter(sampling, filters)
107
129
  { histogram: filters.fetch(:prefix, nil),
108
130
  host: filters.fetch(:host, nil),
@@ -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
@@ -19,7 +19,7 @@ module Wavefront
19
19
 
20
20
  def deprecation_warning
21
21
  logger.log('Wavefront::User is deprecated and will be removed from the ' \
22
- 'next major release. Please use Wavefront::Account.', :warn)
22
+ 'next major release. Please use Wavefront::Account.', :warn)
23
23
  end
24
24
 
25
25
  def post_initialize(_creds, _opts)
@@ -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
 
@@ -256,7 +256,7 @@ module Wavefront
256
256
  # dashboard ID is not valid
257
257
  #
258
258
  def wf_dashboard_id?(id)
259
- return true if id.is_a?(String) && id.size < 256 && id.match(/^[\w\-]+$/)
259
+ return true if id.is_a?(String) && id.size < 256 && id.match(/^[\w-]+$/)
260
260
 
261
261
  raise Wavefront::Exception::InvalidDashboardId, id
262
262
  end
@@ -391,7 +391,7 @@ module Wavefront
391
391
  # is not valid
392
392
  #
393
393
  def wf_source_id?(source)
394
- if source.is_a?(String) && source.match(/^[\w.\-]+$/) &&
394
+ if source.is_a?(String) && source.match(/^[\w.-]+$/) &&
395
395
  source.size < 1024
396
396
  return true
397
397
  end
@@ -467,6 +467,9 @@ module Wavefront
467
467
  true
468
468
  end
469
469
 
470
+ # @
471
+ def wf_trace?(trace); end
472
+
470
473
  # Validate an array of distribution values
471
474
  # @param vals [Array[Array]] [count, value]
472
475
  # @return true if valid
@@ -639,6 +642,18 @@ module Wavefront
639
642
 
640
643
  raise Wavefront::Exception::InvalidAwsExternalId, id
641
644
  end
645
+
646
+ # Ensure the given argument is a valid Wavefront metrics policy ID
647
+ # @param id [String] the metrics policy ID to validate
648
+ # @return true if the role ID is valid
649
+ # @raise Wavefront::Exception::InvalidMetricsPolicyId if the ID is
650
+ # not valid
651
+ #
652
+ def wf_metricspolicy_id?(id)
653
+ return true if uuid?(id)
654
+
655
+ raise Wavefront::Exception::InvalidMetricsPolicyId, id
656
+ end
642
657
  end
643
658
  # rubocop:enable Metrics/ModuleLength
644
659
  end
@@ -39,7 +39,7 @@ module Wavefront
39
39
  # verbose [Bool]
40
40
  # debug [Bool]
41
41
  # writer [Symbol, String] the name of the writer class to use.
42
- # Defaults to :socket
42
+ # Defaults to :proxy
43
43
  # noauto [Bool] if this is false, #write will automatically
44
44
  # open a connection to Wavefront on each invocation. Set
45
45
  # this to true to manually manage the connection.
@@ -62,7 +62,7 @@ module Wavefront
62
62
  #
63
63
  def defaults
64
64
  { tags: nil,
65
- writer: :socket,
65
+ writer: :proxy,
66
66
  noop: false,
67
67
  novalidate: false,
68
68
  noauto: false,
@@ -24,7 +24,7 @@ module Wavefront
24
24
  'credentials must contain API endpoint')
25
25
  end
26
26
 
27
- return if creds.key?(:token) && creds[:token]
27
+ return true if creds.key?(:token) && creds[:token]
28
28
 
29
29
  raise(Wavefront::Exception::CredentialError,
30
30
  'credentials must contain API token')
@@ -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
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'core'
4
+
5
+ module Wavefront
6
+ module Writer
7
+ #
8
+ # Everything specific to writing points to a Wavefront proxy, in
9
+ # native Wavefront format, to a socket. (The original and,
10
+ # once, only way to send points.)
11
+ #
12
+ class Proxy < Core
13
+ # Open a connection to a socket to a Wavefront proxy, putting the
14
+ # descriptor in instance variable @conn.
15
+ # @return [TCPSocket]
16
+ #
17
+ def open
18
+ if opts[:noop]
19
+ logger.log('No-op requested. Not opening connection to proxy.')
20
+ return true
21
+ end
22
+
23
+ port = creds[:port] || default_port
24
+ logger.log("Connecting to #{creds[:proxy]}:#{port}.", :debug)
25
+ open_socket(creds[:proxy], port)
26
+ end
27
+
28
+ # Close the connection described by the @conn instance variable.
29
+ #
30
+ def close
31
+ return if opts[:noop]
32
+
33
+ logger.log('Closing connection to proxy.', :debug)
34
+ conn.close
35
+ end
36
+
37
+ def validate_credentials(creds)
38
+ return true if creds.key?(:proxy) && creds[:proxy]
39
+
40
+ raise(Wavefront::Exception::CredentialError,
41
+ 'credentials must contain proxy address')
42
+ end
43
+
44
+ private
45
+
46
+ def open_socket(proxy, port)
47
+ @conn = TCPSocket.new(proxy, port)
48
+ rescue StandardError => e
49
+ logger.log(e, :error)
50
+ raise Wavefront::Exception::InvalidEndpoint
51
+ end
52
+
53
+ # @param point [String] point or points in native Wavefront format.
54
+ # @raise [SocketError] if point cannot be written
55
+ #
56
+ def _send_point(point)
57
+ return if opts[:noop]
58
+
59
+ conn.puts(point)
60
+ rescue StandardError
61
+ raise Wavefront::Exception::SocketError
62
+ end
63
+
64
+ # return [Integer] the port to connect to, if none is supplied
65
+ #
66
+ def default_port
67
+ 2878
68
+ end
69
+ end
70
+ end
71
+ end