wavefront-sdk 3.3.3 → 3.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -17
- data/Gemfile +2 -0
- data/HISTORY.md +4 -0
- data/Rakefile +2 -0
- data/lib/wavefront-sdk/alert.rb +5 -2
- data/lib/wavefront-sdk/api_mixins/acl.rb +3 -0
- data/lib/wavefront-sdk/api_mixins/tag.rb +2 -0
- data/lib/wavefront-sdk/api_mixins/user.rb +4 -0
- data/lib/wavefront-sdk/apitoken.rb +2 -0
- data/lib/wavefront-sdk/cloudintegration.rb +4 -0
- data/lib/wavefront-sdk/core/api.rb +3 -0
- data/lib/wavefront-sdk/core/api_caller.rb +16 -10
- data/lib/wavefront-sdk/core/exception.rb +2 -0
- data/lib/wavefront-sdk/core/logger.rb +6 -3
- data/lib/wavefront-sdk/core/response.rb +6 -3
- data/lib/wavefront-sdk/credentials.rb +5 -2
- data/lib/wavefront-sdk/dashboard.rb +3 -0
- data/lib/wavefront-sdk/defs/constants.rb +3 -1
- data/lib/wavefront-sdk/defs/version.rb +3 -1
- data/lib/wavefront-sdk/derivedmetric.rb +3 -0
- data/lib/wavefront-sdk/distribution.rb +36 -16
- data/lib/wavefront-sdk/event.rb +16 -12
- data/lib/wavefront-sdk/externallink.rb +3 -0
- data/lib/wavefront-sdk/integration.rb +2 -0
- data/lib/wavefront-sdk/maintenancewindow.rb +4 -1
- data/lib/wavefront-sdk/message.rb +2 -0
- data/lib/wavefront-sdk/metric.rb +3 -0
- data/lib/wavefront-sdk/metric_helper.rb +6 -4
- data/lib/wavefront-sdk/notificant.rb +3 -0
- data/lib/wavefront-sdk/paginator/base.rb +5 -0
- data/lib/wavefront-sdk/paginator/delete.rb +2 -0
- data/lib/wavefront-sdk/paginator/get.rb +2 -0
- data/lib/wavefront-sdk/paginator/post.rb +2 -0
- data/lib/wavefront-sdk/paginator/put.rb +2 -0
- data/lib/wavefront-sdk/proxy.rb +2 -0
- data/lib/wavefront-sdk/query.rb +6 -3
- data/lib/wavefront-sdk/report.rb +2 -0
- data/lib/wavefront-sdk/savedsearch.rb +4 -0
- data/lib/wavefront-sdk/search.rb +4 -1
- data/lib/wavefront-sdk/settings.rb +2 -0
- data/lib/wavefront-sdk/source.rb +3 -0
- data/lib/wavefront-sdk/stdlib/array.rb +2 -0
- data/lib/wavefront-sdk/stdlib/hash.rb +5 -1
- data/lib/wavefront-sdk/stdlib/string.rb +2 -0
- data/lib/wavefront-sdk/support/mixins.rb +5 -1
- data/lib/wavefront-sdk/support/parse_time.rb +3 -0
- data/lib/wavefront-sdk/types/status.rb +4 -0
- data/lib/wavefront-sdk/user.rb +18 -8
- data/lib/wavefront-sdk/usergroup.rb +3 -0
- data/lib/wavefront-sdk/validators.rb +28 -0
- data/lib/wavefront-sdk/webhook.rb +3 -0
- data/lib/wavefront-sdk/write.rb +43 -28
- data/lib/wavefront-sdk/writers/api.rb +2 -0
- data/lib/wavefront-sdk/writers/core.rb +21 -4
- data/lib/wavefront-sdk/writers/http.rb +9 -2
- data/lib/wavefront-sdk/writers/socket.rb +11 -9
- data/lib/wavefront-sdk/writers/summary.rb +2 -0
- data/lib/wavefront-sdk/writers/unix.rb +10 -7
- data/lib/wavefront_sdk.rb +3 -1
- data/spec/.rubocop.yml +10 -14
- data/spec/constants.rb +10 -8
- data/spec/spec_helper.rb +2 -0
- data/spec/support/bad_mocket.rb +2 -0
- data/spec/support/hash.rb +2 -0
- data/spec/support/minitest_assertions.rb +2 -0
- data/spec/support/mocket.rb +2 -0
- data/spec/test_mixins/acl.rb +2 -0
- data/spec/test_mixins/general.rb +2 -0
- data/spec/test_mixins/tag.rb +2 -0
- data/spec/test_mixins/update_keys.rb +2 -0
- data/spec/wavefront-sdk/alert_spec.rb +10 -9
- data/spec/wavefront-sdk/api_mixins/user_mixins_spec.rb +1 -0
- data/spec/wavefront-sdk/apitoken_spec.rb +1 -0
- data/spec/wavefront-sdk/cloudintegration_spec.rb +2 -1
- data/spec/wavefront-sdk/core/api_caller_spec.rb +1 -0
- data/spec/wavefront-sdk/core/api_spec.rb +1 -0
- data/spec/wavefront-sdk/core/logger_spec.rb +1 -0
- data/spec/wavefront-sdk/core/response_spec.rb +4 -3
- data/spec/wavefront-sdk/credentials_spec.rb +1 -0
- data/spec/wavefront-sdk/dashboard_spec.rb +1 -0
- data/spec/wavefront-sdk/derivedmetric_spec.rb +1 -0
- data/spec/wavefront-sdk/distribution_spec.rb +6 -5
- data/spec/wavefront-sdk/event_spec.rb +8 -7
- data/spec/wavefront-sdk/externallink_spec.rb +5 -4
- data/spec/wavefront-sdk/integration_spec.rb +1 -0
- data/spec/wavefront-sdk/maintenancewindow_spec.rb +6 -5
- data/spec/wavefront-sdk/message_spec.rb +2 -1
- data/spec/wavefront-sdk/metric_helper_spec.rb +10 -9
- data/spec/wavefront-sdk/metric_spec.rb +1 -0
- data/spec/wavefront-sdk/notificant_spec.rb +1 -0
- data/spec/wavefront-sdk/paginator/base_spec.rb +1 -0
- data/spec/wavefront-sdk/paginator/post_spec.rb +1 -0
- data/spec/wavefront-sdk/proxy_spec.rb +1 -0
- data/spec/wavefront-sdk/query_spec.rb +1 -0
- data/spec/wavefront-sdk/report_spec.rb +1 -0
- data/spec/wavefront-sdk/resources/dummy_points.rb +10 -8
- data/spec/wavefront-sdk/savedsearch_spec.rb +1 -0
- data/spec/wavefront-sdk/search_spec.rb +5 -4
- data/spec/wavefront-sdk/settings_spec.rb +1 -0
- data/spec/wavefront-sdk/source_spec.rb +3 -2
- data/spec/wavefront-sdk/stdlib/array_spec.rb +1 -0
- data/spec/wavefront-sdk/stdlib/hash_spec.rb +1 -0
- data/spec/wavefront-sdk/stdlib/string_spec.rb +1 -0
- data/spec/wavefront-sdk/support/mixins_spec.rb +1 -0
- data/spec/wavefront-sdk/support/parse_time_spec.rb +1 -2
- data/spec/wavefront-sdk/user_spec.rb +1 -0
- data/spec/wavefront-sdk/usergroup_spec.rb +2 -1
- data/spec/wavefront-sdk/validators_spec.rb +1 -2
- data/spec/wavefront-sdk/webhook_spec.rb +7 -6
- data/spec/wavefront-sdk/write_spec.rb +50 -30
- data/spec/wavefront-sdk/writers/api_spec.rb +1 -0
- data/spec/wavefront-sdk/writers/core_spec.rb +1 -0
- data/spec/wavefront-sdk/writers/http_spec.rb +2 -1
- data/spec/wavefront-sdk/writers/socket_spec.rb +1 -0
- data/spec/wavefront-sdk/writers/summary_spec.rb +1 -0
- data/wavefront-sdk.gemspec +4 -2
- metadata +6 -6
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'core/api'
|
2
4
|
require_relative 'api_mixins/user'
|
3
5
|
|
@@ -32,6 +34,7 @@ module Wavefront
|
|
32
34
|
#
|
33
35
|
def create(body)
|
34
36
|
raise ArgumentError unless body.is_a?(Hash)
|
37
|
+
|
35
38
|
api.post('', body, 'application/json')
|
36
39
|
end
|
37
40
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'defs/constants'
|
2
4
|
require_relative 'core/exception'
|
3
5
|
|
@@ -63,6 +65,7 @@ module Wavefront
|
|
63
65
|
#
|
64
66
|
def wf_name?(name)
|
65
67
|
return true if name.is_a?(String) && name.size < 1024 && name =~ /^\w+$/
|
68
|
+
|
66
69
|
raise Wavefront::Exception::InvalidName
|
67
70
|
end
|
68
71
|
|
@@ -93,6 +96,7 @@ module Wavefront
|
|
93
96
|
#
|
94
97
|
def wf_ts?(timestamp)
|
95
98
|
return true if timestamp.is_a?(Time) || timestamp.is_a?(Date)
|
99
|
+
|
96
100
|
raise Wavefront::Exception::InvalidTimestamp
|
97
101
|
end
|
98
102
|
|
@@ -107,6 +111,7 @@ module Wavefront
|
|
107
111
|
#
|
108
112
|
def wf_ms_ts?(timestamp)
|
109
113
|
return true if timestamp.is_a?(Numeric)
|
114
|
+
|
110
115
|
raise Wavefront::Exception::InvalidTimestamp
|
111
116
|
end
|
112
117
|
|
@@ -119,6 +124,7 @@ module Wavefront
|
|
119
124
|
#
|
120
125
|
def wf_epoch?(timestamp)
|
121
126
|
return true if timestamp.is_a?(Numeric)
|
127
|
+
|
122
128
|
raise Wavefront::Exception::InvalidTimestamp
|
123
129
|
end
|
124
130
|
|
@@ -150,6 +156,7 @@ module Wavefront
|
|
150
156
|
#
|
151
157
|
def wf_value?(value)
|
152
158
|
return true if value.is_a?(Numeric)
|
159
|
+
|
153
160
|
raise Wavefront::Exception::InvalidMetricValue
|
154
161
|
end
|
155
162
|
|
@@ -163,6 +170,7 @@ module Wavefront
|
|
163
170
|
def wf_version?(version)
|
164
171
|
version = version.to_i if version.is_a?(String) && version =~ /^\d+$/
|
165
172
|
return true if version.is_a?(Integer) && version.positive?
|
173
|
+
|
166
174
|
raise Wavefront::Exception::InvalidVersion
|
167
175
|
end
|
168
176
|
|
@@ -176,6 +184,7 @@ module Wavefront
|
|
176
184
|
#
|
177
185
|
def wf_point_tags?(tags)
|
178
186
|
raise Wavefront::Exception::InvalidTag unless tags.is_a?(Hash)
|
187
|
+
|
179
188
|
tags.each { |k, v| wf_point_tag?(k, v) }
|
180
189
|
end
|
181
190
|
|
@@ -203,6 +212,7 @@ module Wavefront
|
|
203
212
|
#
|
204
213
|
def wf_proxy_id?(id)
|
205
214
|
return true if uuid?(id)
|
215
|
+
|
206
216
|
raise Wavefront::Exception::InvalidProxyId
|
207
217
|
end
|
208
218
|
|
@@ -218,6 +228,7 @@ module Wavefront
|
|
218
228
|
def wf_alert_id?(id)
|
219
229
|
id = id.to_s if id.is_a?(Numeric)
|
220
230
|
return true if id.is_a?(String) && id.match(/^\d{13}$/)
|
231
|
+
|
221
232
|
raise Wavefront::Exception::InvalidAlertId
|
222
233
|
end
|
223
234
|
|
@@ -231,6 +242,7 @@ module Wavefront
|
|
231
242
|
#
|
232
243
|
def wf_cloudintegration_id?(id)
|
233
244
|
return true if uuid?(id)
|
245
|
+
|
234
246
|
raise Wavefront::Exception::InvalidCloudIntegrationId
|
235
247
|
end
|
236
248
|
|
@@ -245,6 +257,7 @@ module Wavefront
|
|
245
257
|
#
|
246
258
|
def wf_dashboard_id?(id)
|
247
259
|
return true if id.is_a?(String) && id.size < 256 && id.match(/^[\w\-]+$/)
|
260
|
+
|
248
261
|
raise Wavefront::Exception::InvalidDashboardId
|
249
262
|
end
|
250
263
|
|
@@ -274,6 +287,7 @@ module Wavefront
|
|
274
287
|
#
|
275
288
|
def wf_event_id?(id)
|
276
289
|
return true if id.is_a?(String) && id =~ /^\d{13}:.+/
|
290
|
+
|
277
291
|
raise Wavefront::Exception::InvalidEventId
|
278
292
|
end
|
279
293
|
|
@@ -286,6 +300,7 @@ module Wavefront
|
|
286
300
|
#
|
287
301
|
def wf_link_id?(id)
|
288
302
|
return true if id.is_a?(String) && id =~ /^\w{16}$/
|
303
|
+
|
289
304
|
raise Wavefront::Exception::InvalidExternalLinkId
|
290
305
|
end
|
291
306
|
|
@@ -312,6 +327,7 @@ module Wavefront
|
|
312
327
|
#
|
313
328
|
def wf_alert_severity?(severity)
|
314
329
|
return true if %w[INFO SMOKE WARN SEVERE].include?(severity)
|
330
|
+
|
315
331
|
raise Wavefront::Exception::InvalidAlertSeverity
|
316
332
|
end
|
317
333
|
|
@@ -323,6 +339,7 @@ module Wavefront
|
|
323
339
|
#
|
324
340
|
def wf_message_id?(id)
|
325
341
|
return true if id.is_a?(String) && id =~ /^\w+::\w+$/
|
342
|
+
|
326
343
|
raise Wavefront::Exception::InvalidMessageId
|
327
344
|
end
|
328
345
|
|
@@ -335,6 +352,7 @@ module Wavefront
|
|
335
352
|
#
|
336
353
|
def wf_granularity?(granularity)
|
337
354
|
return true if %w[d h m s].include?(granularity.to_s)
|
355
|
+
|
338
356
|
raise Wavefront::Exception::InvalidGranularity
|
339
357
|
end
|
340
358
|
|
@@ -346,6 +364,7 @@ module Wavefront
|
|
346
364
|
#
|
347
365
|
def wf_savedsearch_id?(id)
|
348
366
|
return true if id.is_a?(String) && id =~ /^\w{8}$/
|
367
|
+
|
349
368
|
raise Wavefront::Exception::InvalidSavedSearchId
|
350
369
|
end
|
351
370
|
|
@@ -360,6 +379,7 @@ module Wavefront
|
|
360
379
|
return true if %w[DASHBOARD ALERT MAINTENANCE_WINDOW
|
361
380
|
NOTIFICANT EVENT SOURCE EXTERNAL_LINK AGENT
|
362
381
|
CLOUD_INTEGRATION].include?(id)
|
382
|
+
|
363
383
|
raise Wavefront::Exception::InvalidSavedSearchEntity
|
364
384
|
end
|
365
385
|
|
@@ -387,6 +407,7 @@ module Wavefront
|
|
387
407
|
#
|
388
408
|
def wf_user_id?(user)
|
389
409
|
return true if user.is_a?(String) && user.length < 256 && !user.empty?
|
410
|
+
|
390
411
|
raise Wavefront::Exception::InvalidUserId
|
391
412
|
end
|
392
413
|
|
@@ -398,6 +419,7 @@ module Wavefront
|
|
398
419
|
#
|
399
420
|
def wf_usergroup_id?(gid)
|
400
421
|
return true if uuid?(gid)
|
422
|
+
|
401
423
|
raise Wavefront::Exception::InvalidUserGroupId
|
402
424
|
end
|
403
425
|
|
@@ -409,6 +431,7 @@ module Wavefront
|
|
409
431
|
#
|
410
432
|
def wf_webhook_id?(id)
|
411
433
|
return true if id.is_a?(String) && id =~ /^[a-zA-Z0-9]{16}$/
|
434
|
+
|
412
435
|
raise Wavefront::Exception::InvalidWebhookId
|
413
436
|
end
|
414
437
|
|
@@ -467,6 +490,7 @@ module Wavefront
|
|
467
490
|
#
|
468
491
|
def wf_notificant_id?(id)
|
469
492
|
return true if id.is_a?(String) && id =~ /^\w{16}$/
|
493
|
+
|
470
494
|
raise Wavefront::Exception::InvalidNotificantId
|
471
495
|
end
|
472
496
|
|
@@ -480,6 +504,7 @@ module Wavefront
|
|
480
504
|
#
|
481
505
|
def wf_integration_id?(id)
|
482
506
|
return true if id.is_a?(String) && id =~ /^[a-z0-9]+$/
|
507
|
+
|
483
508
|
raise Wavefront::Exception::InvalidIntegrationId
|
484
509
|
end
|
485
510
|
|
@@ -490,6 +515,7 @@ module Wavefront
|
|
490
515
|
#
|
491
516
|
def wf_distribution_interval?(interval)
|
492
517
|
return true if %i[m h d].include?(interval)
|
518
|
+
|
493
519
|
raise Wavefront::Exception::InvalidDistributionInterval
|
494
520
|
end
|
495
521
|
|
@@ -500,6 +526,7 @@ module Wavefront
|
|
500
526
|
#
|
501
527
|
def wf_distribution_count?(count)
|
502
528
|
return true if count.is_a?(Integer) && count.positive?
|
529
|
+
|
503
530
|
raise Wavefront::Exception::InvalidDistributionCount
|
504
531
|
end
|
505
532
|
|
@@ -510,6 +537,7 @@ module Wavefront
|
|
510
537
|
#
|
511
538
|
def wf_apitoken_id?(id)
|
512
539
|
return true if uuid?(id)
|
540
|
+
|
513
541
|
raise Wavefront::Exception::InvalidApiTokenId
|
514
542
|
end
|
515
543
|
end
|
data/lib/wavefront-sdk/write.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'socket'
|
2
4
|
require_relative 'core/exception'
|
3
5
|
require_relative 'core/logger'
|
@@ -56,15 +58,16 @@ module Wavefront
|
|
56
58
|
@writer = setup_writer
|
57
59
|
end
|
58
60
|
|
61
|
+
# Chunk size gets overriden
|
62
|
+
#
|
59
63
|
def defaults
|
60
|
-
{ tags:
|
61
|
-
writer:
|
62
|
-
noop:
|
63
|
-
novalidate:
|
64
|
-
noauto:
|
65
|
-
verbose:
|
66
|
-
debug:
|
67
|
-
chunk_size: 1000,
|
64
|
+
{ tags: nil,
|
65
|
+
writer: :socket,
|
66
|
+
noop: false,
|
67
|
+
novalidate: false,
|
68
|
+
noauto: false,
|
69
|
+
verbose: false,
|
70
|
+
debug: false,
|
68
71
|
chunk_pause: 0 }
|
69
72
|
end
|
70
73
|
|
@@ -94,7 +97,7 @@ module Wavefront
|
|
94
97
|
# through
|
95
98
|
#
|
96
99
|
def write(points = [], openclose = manage_conn, prefix = nil)
|
97
|
-
resps = [points].flatten.each_slice(
|
100
|
+
resps = [points].flatten.each_slice(chunk_size).map do |chunk|
|
98
101
|
resp = writer.write(chunk, openclose, prefix)
|
99
102
|
sleep(opts[:chunk_pause])
|
100
103
|
resp
|
@@ -105,6 +108,8 @@ module Wavefront
|
|
105
108
|
|
106
109
|
# Compound the responses of all chunked writes into one. It will
|
107
110
|
# be 'ok' only if *everything* passed.
|
111
|
+
# @param responses [Array[Wavefront::Response]]
|
112
|
+
# @return Wavefront::Response
|
108
113
|
#
|
109
114
|
def composite_response(responses)
|
110
115
|
result = responses.all?(&:ok?) ? 'OK' : 'ERROR'
|
@@ -115,7 +120,7 @@ module Wavefront
|
|
115
120
|
end
|
116
121
|
|
117
122
|
Wavefront::Response.new(
|
118
|
-
{ status:
|
123
|
+
{ status: { result: result, message: nil, code: nil },
|
119
124
|
response: summary.to_h }.to_json, nil
|
120
125
|
)
|
121
126
|
end
|
@@ -189,6 +194,10 @@ module Wavefront
|
|
189
194
|
:wf_point?
|
190
195
|
end
|
191
196
|
|
197
|
+
def chunk_size
|
198
|
+
opts[:chunk_size] || writer.chunk_size
|
199
|
+
end
|
200
|
+
|
192
201
|
# Convert a validated point to a string conforming to
|
193
202
|
# https://community.wavefront.com/docs/DOC-1031. No validation
|
194
203
|
# is done here.
|
@@ -197,24 +206,30 @@ module Wavefront
|
|
197
206
|
# the format.
|
198
207
|
#
|
199
208
|
def hash_to_wf(point)
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
209
|
+
raise Wavefront::Exception::InvalidMetricName unless point[:path]
|
210
|
+
raise Wavefront::Exception::InvalidMetricValue unless point[:value]
|
211
|
+
|
212
|
+
format('%<path>s %<value>s %<ts>s source=%<source>s %<tags>s %<opttags>s',
|
213
|
+
point_hash(point)).squeeze(' ').strip
|
204
214
|
end
|
205
215
|
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
216
|
+
def point_hash(point)
|
217
|
+
point.dup.tap do |p|
|
218
|
+
p[:ts] ||= nil
|
219
|
+
p[:source] ||= HOSTNAME
|
220
|
+
p[:tags] = tags_or_nothing(p.fetch(:tags, nil))
|
221
|
+
p[:opttags] = tags_or_nothing(opts.fetch(:tags, nil))
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
def tags_or_nothing(tags)
|
226
|
+
return nil unless tags
|
227
|
+
|
228
|
+
tags.to_wf_tag
|
229
|
+
end
|
230
|
+
|
231
|
+
def data_format
|
232
|
+
:wavefront
|
218
233
|
end
|
219
234
|
|
220
235
|
private
|
@@ -226,8 +241,8 @@ module Wavefront
|
|
226
241
|
def setup_writer
|
227
242
|
writer = opts[:writer].to_s
|
228
243
|
require_relative File.join('writers', writer)
|
229
|
-
Object.const_get(format('Wavefront::Writer
|
230
|
-
writer.capitalize)).new(self)
|
244
|
+
Object.const_get(format('Wavefront::Writer::%<writer_class>s',
|
245
|
+
writer_class: writer.capitalize)).new(self)
|
231
246
|
rescue LoadError
|
232
247
|
raise(Wavefront::Exception::UnsupportedWriter, writer)
|
233
248
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'json'
|
2
4
|
require_relative 'summary'
|
3
5
|
require_relative '../core/response'
|
@@ -68,7 +70,7 @@ module Wavefront
|
|
68
70
|
|
69
71
|
def respond
|
70
72
|
Wavefront::Response.new(
|
71
|
-
{ status:
|
73
|
+
{ status: { result: summary.result, message: nil, code: nil },
|
72
74
|
response: summary.to_h }.to_json, nil, opts
|
73
75
|
)
|
74
76
|
end
|
@@ -130,13 +132,28 @@ module Wavefront
|
|
130
132
|
Wavefront::Exception::InvalidTimestamp,
|
131
133
|
Wavefront::Exception::InvalidSourceId,
|
132
134
|
Wavefront::Exception::InvalidTag => e
|
133
|
-
|
134
|
-
logger.log(e.class, :info)
|
135
|
-
logger.log(format('Invalid point: %s (%s)', point, e.to_s), :debug)
|
135
|
+
log_invalid_point(point, e)
|
136
136
|
summary.rejected += 1
|
137
137
|
false
|
138
138
|
end
|
139
139
|
|
140
|
+
def log_invalid_point(rawpoint, exception)
|
141
|
+
logger.log('Invalid point, skipping.', :info)
|
142
|
+
logger.log(exception.class, :info)
|
143
|
+
logger.log(format('Invalid point: %<rawpoint>s (%<message>s)',
|
144
|
+
rawpoint: rawpoint,
|
145
|
+
message: exception.to_s), :debug)
|
146
|
+
end
|
147
|
+
|
148
|
+
# We divide metrics up into manageable chunks and send them in
|
149
|
+
# batches. This dictates how large those bundles are. You can
|
150
|
+
# override the value with the chunk_size option
|
151
|
+
# @return [Integer]
|
152
|
+
#
|
153
|
+
def chunk_size
|
154
|
+
1000
|
155
|
+
end
|
156
|
+
|
140
157
|
private
|
141
158
|
|
142
159
|
def write_loop(points)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'core'
|
2
4
|
require_relative '../core/api_caller'
|
3
5
|
|
@@ -11,8 +13,9 @@ module Wavefront
|
|
11
13
|
#
|
12
14
|
class Http < Core
|
13
15
|
def open
|
14
|
-
creds[:endpoint] = format('
|
15
|
-
creds[:
|
16
|
+
creds[:endpoint] = format('%<proxy>s:%<port>s',
|
17
|
+
proxy: creds[:proxy],
|
18
|
+
port: creds[:port] || default_port)
|
16
19
|
opts[:scheme] = 'http'
|
17
20
|
@conn = Wavefront::ApiCaller.new(self, creds, opts)
|
18
21
|
end
|
@@ -32,6 +35,10 @@ module Wavefront
|
|
32
35
|
'credentials must contain proxy')
|
33
36
|
end
|
34
37
|
|
38
|
+
def chunk_size
|
39
|
+
100
|
40
|
+
end
|
41
|
+
|
35
42
|
private
|
36
43
|
|
37
44
|
def _send_point(point)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'core'
|
2
4
|
|
3
5
|
module Wavefront
|
@@ -12,7 +14,6 @@ module Wavefront
|
|
12
14
|
# in instance variable @conn.
|
13
15
|
# @return [TCPSocket]
|
14
16
|
#
|
15
|
-
# rubocop:disable Metrics/AbcSize
|
16
17
|
def open
|
17
18
|
if opts[:noop]
|
18
19
|
logger.log('No-op requested. Not opening connection to proxy.')
|
@@ -21,15 +22,8 @@ module Wavefront
|
|
21
22
|
|
22
23
|
port = creds[:port] || default_port
|
23
24
|
logger.log("Connecting to #{creds[:proxy]}:#{port}.", :debug)
|
24
|
-
|
25
|
-
begin
|
26
|
-
@conn = TCPSocket.new(creds[:proxy], port)
|
27
|
-
rescue StandardError => e
|
28
|
-
logger.log(e, :error)
|
29
|
-
raise Wavefront::Exception::InvalidEndpoint
|
30
|
-
end
|
25
|
+
open_socket(creds[:proxy], port)
|
31
26
|
end
|
32
|
-
# rubocop:enable Metrics/AbcSize
|
33
27
|
|
34
28
|
# Close the connection described by the @conn instance variable.
|
35
29
|
#
|
@@ -49,11 +43,19 @@ module Wavefront
|
|
49
43
|
|
50
44
|
private
|
51
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
|
+
|
52
53
|
# @param point [String] point or points in native Wavefront format.
|
53
54
|
# @raise [SocketError] if point cannot be written
|
54
55
|
#
|
55
56
|
def _send_point(point)
|
56
57
|
return if opts[:noop]
|
58
|
+
|
57
59
|
conn.puts(point)
|
58
60
|
rescue StandardError
|
59
61
|
raise Wavefront::Exception::SocketError
|