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.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -17
  3. data/Gemfile +2 -0
  4. data/HISTORY.md +4 -0
  5. data/Rakefile +2 -0
  6. data/lib/wavefront-sdk/alert.rb +5 -2
  7. data/lib/wavefront-sdk/api_mixins/acl.rb +3 -0
  8. data/lib/wavefront-sdk/api_mixins/tag.rb +2 -0
  9. data/lib/wavefront-sdk/api_mixins/user.rb +4 -0
  10. data/lib/wavefront-sdk/apitoken.rb +2 -0
  11. data/lib/wavefront-sdk/cloudintegration.rb +4 -0
  12. data/lib/wavefront-sdk/core/api.rb +3 -0
  13. data/lib/wavefront-sdk/core/api_caller.rb +16 -10
  14. data/lib/wavefront-sdk/core/exception.rb +2 -0
  15. data/lib/wavefront-sdk/core/logger.rb +6 -3
  16. data/lib/wavefront-sdk/core/response.rb +6 -3
  17. data/lib/wavefront-sdk/credentials.rb +5 -2
  18. data/lib/wavefront-sdk/dashboard.rb +3 -0
  19. data/lib/wavefront-sdk/defs/constants.rb +3 -1
  20. data/lib/wavefront-sdk/defs/version.rb +3 -1
  21. data/lib/wavefront-sdk/derivedmetric.rb +3 -0
  22. data/lib/wavefront-sdk/distribution.rb +36 -16
  23. data/lib/wavefront-sdk/event.rb +16 -12
  24. data/lib/wavefront-sdk/externallink.rb +3 -0
  25. data/lib/wavefront-sdk/integration.rb +2 -0
  26. data/lib/wavefront-sdk/maintenancewindow.rb +4 -1
  27. data/lib/wavefront-sdk/message.rb +2 -0
  28. data/lib/wavefront-sdk/metric.rb +3 -0
  29. data/lib/wavefront-sdk/metric_helper.rb +6 -4
  30. data/lib/wavefront-sdk/notificant.rb +3 -0
  31. data/lib/wavefront-sdk/paginator/base.rb +5 -0
  32. data/lib/wavefront-sdk/paginator/delete.rb +2 -0
  33. data/lib/wavefront-sdk/paginator/get.rb +2 -0
  34. data/lib/wavefront-sdk/paginator/post.rb +2 -0
  35. data/lib/wavefront-sdk/paginator/put.rb +2 -0
  36. data/lib/wavefront-sdk/proxy.rb +2 -0
  37. data/lib/wavefront-sdk/query.rb +6 -3
  38. data/lib/wavefront-sdk/report.rb +2 -0
  39. data/lib/wavefront-sdk/savedsearch.rb +4 -0
  40. data/lib/wavefront-sdk/search.rb +4 -1
  41. data/lib/wavefront-sdk/settings.rb +2 -0
  42. data/lib/wavefront-sdk/source.rb +3 -0
  43. data/lib/wavefront-sdk/stdlib/array.rb +2 -0
  44. data/lib/wavefront-sdk/stdlib/hash.rb +5 -1
  45. data/lib/wavefront-sdk/stdlib/string.rb +2 -0
  46. data/lib/wavefront-sdk/support/mixins.rb +5 -1
  47. data/lib/wavefront-sdk/support/parse_time.rb +3 -0
  48. data/lib/wavefront-sdk/types/status.rb +4 -0
  49. data/lib/wavefront-sdk/user.rb +18 -8
  50. data/lib/wavefront-sdk/usergroup.rb +3 -0
  51. data/lib/wavefront-sdk/validators.rb +28 -0
  52. data/lib/wavefront-sdk/webhook.rb +3 -0
  53. data/lib/wavefront-sdk/write.rb +43 -28
  54. data/lib/wavefront-sdk/writers/api.rb +2 -0
  55. data/lib/wavefront-sdk/writers/core.rb +21 -4
  56. data/lib/wavefront-sdk/writers/http.rb +9 -2
  57. data/lib/wavefront-sdk/writers/socket.rb +11 -9
  58. data/lib/wavefront-sdk/writers/summary.rb +2 -0
  59. data/lib/wavefront-sdk/writers/unix.rb +10 -7
  60. data/lib/wavefront_sdk.rb +3 -1
  61. data/spec/.rubocop.yml +10 -14
  62. data/spec/constants.rb +10 -8
  63. data/spec/spec_helper.rb +2 -0
  64. data/spec/support/bad_mocket.rb +2 -0
  65. data/spec/support/hash.rb +2 -0
  66. data/spec/support/minitest_assertions.rb +2 -0
  67. data/spec/support/mocket.rb +2 -0
  68. data/spec/test_mixins/acl.rb +2 -0
  69. data/spec/test_mixins/general.rb +2 -0
  70. data/spec/test_mixins/tag.rb +2 -0
  71. data/spec/test_mixins/update_keys.rb +2 -0
  72. data/spec/wavefront-sdk/alert_spec.rb +10 -9
  73. data/spec/wavefront-sdk/api_mixins/user_mixins_spec.rb +1 -0
  74. data/spec/wavefront-sdk/apitoken_spec.rb +1 -0
  75. data/spec/wavefront-sdk/cloudintegration_spec.rb +2 -1
  76. data/spec/wavefront-sdk/core/api_caller_spec.rb +1 -0
  77. data/spec/wavefront-sdk/core/api_spec.rb +1 -0
  78. data/spec/wavefront-sdk/core/logger_spec.rb +1 -0
  79. data/spec/wavefront-sdk/core/response_spec.rb +4 -3
  80. data/spec/wavefront-sdk/credentials_spec.rb +1 -0
  81. data/spec/wavefront-sdk/dashboard_spec.rb +1 -0
  82. data/spec/wavefront-sdk/derivedmetric_spec.rb +1 -0
  83. data/spec/wavefront-sdk/distribution_spec.rb +6 -5
  84. data/spec/wavefront-sdk/event_spec.rb +8 -7
  85. data/spec/wavefront-sdk/externallink_spec.rb +5 -4
  86. data/spec/wavefront-sdk/integration_spec.rb +1 -0
  87. data/spec/wavefront-sdk/maintenancewindow_spec.rb +6 -5
  88. data/spec/wavefront-sdk/message_spec.rb +2 -1
  89. data/spec/wavefront-sdk/metric_helper_spec.rb +10 -9
  90. data/spec/wavefront-sdk/metric_spec.rb +1 -0
  91. data/spec/wavefront-sdk/notificant_spec.rb +1 -0
  92. data/spec/wavefront-sdk/paginator/base_spec.rb +1 -0
  93. data/spec/wavefront-sdk/paginator/post_spec.rb +1 -0
  94. data/spec/wavefront-sdk/proxy_spec.rb +1 -0
  95. data/spec/wavefront-sdk/query_spec.rb +1 -0
  96. data/spec/wavefront-sdk/report_spec.rb +1 -0
  97. data/spec/wavefront-sdk/resources/dummy_points.rb +10 -8
  98. data/spec/wavefront-sdk/savedsearch_spec.rb +1 -0
  99. data/spec/wavefront-sdk/search_spec.rb +5 -4
  100. data/spec/wavefront-sdk/settings_spec.rb +1 -0
  101. data/spec/wavefront-sdk/source_spec.rb +3 -2
  102. data/spec/wavefront-sdk/stdlib/array_spec.rb +1 -0
  103. data/spec/wavefront-sdk/stdlib/hash_spec.rb +1 -0
  104. data/spec/wavefront-sdk/stdlib/string_spec.rb +1 -0
  105. data/spec/wavefront-sdk/support/mixins_spec.rb +1 -0
  106. data/spec/wavefront-sdk/support/parse_time_spec.rb +1 -2
  107. data/spec/wavefront-sdk/user_spec.rb +1 -0
  108. data/spec/wavefront-sdk/usergroup_spec.rb +2 -1
  109. data/spec/wavefront-sdk/validators_spec.rb +1 -2
  110. data/spec/wavefront-sdk/webhook_spec.rb +7 -6
  111. data/spec/wavefront-sdk/write_spec.rb +50 -30
  112. data/spec/wavefront-sdk/writers/api_spec.rb +1 -0
  113. data/spec/wavefront-sdk/writers/core_spec.rb +1 -0
  114. data/spec/wavefront-sdk/writers/http_spec.rb +2 -1
  115. data/spec/wavefront-sdk/writers/socket_spec.rb +1 -0
  116. data/spec/wavefront-sdk/writers/summary_spec.rb +1 -0
  117. data/wavefront-sdk.gemspec +4 -2
  118. metadata +6 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a664693c583158575cad85b45877d407b0d319e1d6d540b2cc253d3d65907c0c
4
- data.tar.gz: f0407b9b17cd69e79a7206c6224e749f3ad60027410d03e997fb5dd60aa1276c
3
+ metadata.gz: 69e5b7ef712204907db606287f0d84d3c89a2784e9d8edbc53415b2277311081
4
+ data.tar.gz: e1f7e4c28c8c1d42194cff7c5ce6a5ec55b25dd838883159fba2b8e2a0faa6ee
5
5
  SHA512:
6
- metadata.gz: ff1bd8a1f5d9a7e57bf04d74ad42e9a168ca285e5eb58e4048089768f88ed44e88814744295bbc63541a27f945d99b246fa063f69f2e0495a1bf8bac9dbf28b9
7
- data.tar.gz: f0f18d99096549065b6eaa1b1c410d62d011fdb81f1c07756076c0aaca6b6261621a0cd9403ab76d1e655dcab1ef44bdb9e3edbae23d8bade01ce02868a7ac42
6
+ metadata.gz: 9c55603c0db5ad279802221f3f7eb945e04f861743fb9599c4bbd97e03d51ca6902956ac9aa35202ef1271a6a0d13ee9d96d8cd26b0f89eb81192d2b65772b33
7
+ data.tar.gz: 2e922eb985d685075076ad3da8100296ae891fb645f00211b8ddb4a03b05f16708ed3f8a5a45761277cebec2394a3bc00cbf63b76b70291e94e456f10cb442cb
@@ -1,22 +1,7 @@
1
1
  ---
2
+
2
3
  AllCops:
3
- DisplayStyleGuide: true
4
4
  TargetRubyVersion: 2.3
5
5
 
6
- Style/FrozenStringLiteralComment:
7
- Enabled: false
8
-
9
- Style/FormatStringToken:
10
- Enabled: false
11
-
12
6
  Metrics/ClassLength:
13
- Enabled: false
14
-
15
- Metrics/MethodLength:
16
- Max: 13
17
-
18
- Style/DoubleNegation:
19
- Enabled: false
20
-
21
- Style/NumericLiterals:
22
- Enabled: false
7
+ Max: 124
data/Gemfile CHANGED
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
  gemspec
data/HISTORY.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.3.4 (2019-09-18)
4
+ * Upgrade Rubocop dev dependency to 0.74.0, and make codebase compliant with
5
+ those standards. No interfaces are changed.
6
+
3
7
  ## 3.3.3 (2019-09-10)
4
8
  * Fix slightly misleading verbose message when using recursive or
5
9
  lazy calls
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'yard'
2
4
  require 'rake/testtask'
3
5
  require 'bundler/gem_tasks'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'defs/constants'
2
4
  require_relative 'core/api'
3
5
  require_relative 'api_mixins/acl'
@@ -38,6 +40,7 @@ module Wavefront
38
40
  #
39
41
  def create(body)
40
42
  raise ArgumentError unless body.is_a?(Hash)
43
+
41
44
  api.post('', body, 'application/json')
42
45
  end
43
46
 
@@ -120,9 +123,9 @@ module Wavefront
120
123
  wf_version?(version) if version
121
124
 
122
125
  api.post([id, 'clone'].uri_concat,
123
- { id: id,
126
+ { id: id,
124
127
  name: nil,
125
- v: version }, 'application/json')
128
+ v: version }, 'application/json')
126
129
  end
127
130
 
128
131
  # GET /api/v2/alert/id/history
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Wavefront
2
4
  module Mixin
3
5
  #
@@ -79,6 +81,7 @@ module Wavefront
79
81
 
80
82
  def valid_acl_body?(list)
81
83
  return true if list.is_a?(Array) && list.all? { |h| h.is_a?(String) }
84
+
82
85
  raise ArgumentError
83
86
  end
84
87
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Wavefront
2
4
  module Mixin
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Wavefront
2
4
  module Mixin
3
5
  #
@@ -10,6 +12,7 @@ module Wavefront
10
12
  #
11
13
  def validate_user_list(list)
12
14
  raise ArgumentError unless list.is_a?(Array)
15
+
13
16
  list.each { |id| wf_user_id?(id) }
14
17
  end
15
18
 
@@ -19,6 +22,7 @@ module Wavefront
19
22
  #
20
23
  def validate_usergroup_list(list)
21
24
  raise ArgumentError unless list.is_a?(Array)
25
+
22
26
  list.each { |id| wf_usergroup_id?(id) }
23
27
  end
24
28
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'core/api'
2
4
 
3
5
  module Wavefront
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'core/api'
2
4
 
3
5
  module Wavefront
@@ -26,6 +28,7 @@ module Wavefront
26
28
  #
27
29
  def create(body)
28
30
  raise ArgumentError unless body.is_a?(Hash)
31
+
29
32
  api.post('', body, 'application/json')
30
33
  end
31
34
 
@@ -64,6 +67,7 @@ module Wavefront
64
67
  def update(id, body)
65
68
  wf_cloudintegration_id?(id)
66
69
  raise ArgumentError unless body.is_a?(Hash)
70
+
67
71
  api.put(id, body)
68
72
  end
69
73
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'logger'
2
4
  require_relative 'api_caller'
3
5
  require_relative 'exception'
@@ -75,6 +77,7 @@ module Wavefront
75
77
  def time_to_ms(time)
76
78
  return false unless time.is_a?(Integer)
77
79
  return time if time.to_s.size == 13
80
+
78
81
  (time.to_f * 1000).round
79
82
  end
80
83
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'json'
2
4
  require 'faraday'
3
5
  require 'addressable'
@@ -45,9 +47,11 @@ module Wavefront
45
47
  # @return [URI::HTTPS]
46
48
  #
47
49
  def mk_conn(path, headers = {}, opts = {})
48
- url = format('%s://%s%s', net[:scheme], net[:endpoint],
49
- [net[:api_base], path].uri_concat)
50
- set_opts = { url: Addressable::URI.encode(url),
50
+ url = format('%<scheme>s://%<endpoint>s%<path>s',
51
+ scheme: net[:scheme],
52
+ endpoint: net[:endpoint],
53
+ path: [net[:api_base], path].uri_concat)
54
+ set_opts = { url: Addressable::URI.encode(url),
51
55
  headers: net[:headers].merge(headers) }
52
56
  Faraday.new(set_opts.merge(opts))
53
57
  end
@@ -79,7 +83,7 @@ module Wavefront
79
83
  request: {
80
84
  params_encoder: Faraday::FlatParamsEncoder
81
85
  },
82
- params: query)
86
+ params: query)
83
87
 
84
88
  make_call(conn, :get)
85
89
  end
@@ -149,7 +153,9 @@ module Wavefront
149
153
  def verbosity(conn, method, *args)
150
154
  return unless noop || verbose
151
155
 
152
- log format('uri: %s %s', method.upcase, conn.url_prefix)
156
+ log format('uri: %<method>s %<path>s',
157
+ method: method.upcase,
158
+ path: conn.url_prefix)
153
159
 
154
160
  return unless args.last && !args.last.empty?
155
161
 
@@ -160,8 +166,8 @@ module Wavefront
160
166
 
161
167
  def paginator_class(method)
162
168
  require_relative File.join('..', 'paginator', method.to_s)
163
- Object.const_get(format('Wavefront::Paginator::%s',
164
- method.to_s.capitalize))
169
+ Object.const_get(format('Wavefront::Paginator::%<method>s',
170
+ method: method.to_s.capitalize))
165
171
  end
166
172
 
167
173
  # A dispatcher for making API calls. We now have three methods
@@ -206,8 +212,8 @@ module Wavefront
206
212
  creds[:agent] = "wavefront-sdk #{WF_SDK_VERSION}"
207
213
  end
208
214
 
209
- @net = { headers: headers(creds),
210
- scheme: opts[:scheme] || 'https',
215
+ @net = { headers: headers(creds),
216
+ scheme: opts[:scheme] || 'https',
211
217
  endpoint: creds[:endpoint],
212
218
  api_base: calling_class.api_path }
213
219
  end
@@ -230,7 +236,7 @@ module Wavefront
230
236
  %w[endpoint token].each do |k|
231
237
  unless creds.key?(k.to_sym)
232
238
  raise(Wavefront::Exception::CredentialError,
233
- format('credentials must contain %s', k))
239
+ format('credentials must contain %<key>s', key: k))
234
240
  end
235
241
  end
236
242
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Wavefront
2
4
  #
3
5
  # Simple exception classes
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Wavefront
2
4
  #
3
5
  # Log to a user-supplied Ruby logger, or to standard output.
@@ -30,19 +32,20 @@ module Wavefront
30
32
  end
31
33
 
32
34
  def print_message(level, msg)
33
- method = format('print_%s_message', level).to_sym
35
+ method = format('print_%<level>s_message', level: level).to_sym
34
36
  msg = format_message(level, msg)
35
37
 
36
38
  if respond_to?(:method)
37
39
  send(method, msg)
38
40
  else
39
- print_warn_message(format('undefined message level:%s', level))
41
+ print_warn_message(format('undefined message level:%<level>s',
42
+ level: level))
40
43
  print_warn_message(msg)
41
44
  end
42
45
  end
43
46
 
44
47
  def format_message(level, msg)
45
- format('SDK %s: %s', level.to_s.upcase, msg)
48
+ format('SDK %<level>s: %<msg>s', level: level.to_s.upcase, msg: msg)
46
49
  end
47
50
 
48
51
  def print_debug_message(msg)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'json'
2
4
  require 'map'
3
5
  require_relative 'logger'
@@ -40,7 +42,7 @@ module Wavefront
40
42
  @response = build_response(raw)
41
43
  logger.log(self, :debug)
42
44
  rescue StandardError => e
43
- logger.log(format("could not parse:\n%s", json), :debug)
45
+ logger.log(format("could not parse:\n%<str>s", str: json), :debug)
44
46
  logger.log(e.message.to_s, :debug)
45
47
  raise Wavefront::Exception::UnparseableResponse
46
48
  end
@@ -64,8 +66,7 @@ module Wavefront
64
66
  # @return [Bool]
65
67
  #
66
68
  def more_items?
67
- return false unless response.key?(:moreItems)
68
- !!response.moreItems
69
+ response.moreItems ? true : false
69
70
  rescue StandardError
70
71
  false
71
72
  end
@@ -78,6 +79,7 @@ module Wavefront
78
79
  def next_item
79
80
  return nil unless more_items?
80
81
  return response.cursor if response.respond_to?(:cursor)
82
+
81
83
  response.offset + response.limit
82
84
  rescue StandardError
83
85
  nil
@@ -116,6 +118,7 @@ module Wavefront
116
118
  return Map.new unless raw.is_a?(Hash)
117
119
  return Map.new(raw) unless raw.key?(:response)
118
120
  return raw[:response] unless raw[:response].is_a?(Hash)
121
+
119
122
  Map(raw[:response])
120
123
  end
121
124
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pathname'
2
4
  require 'inifile'
3
5
  require 'map'
@@ -45,8 +47,8 @@ module Wavefront
45
47
  #
46
48
  def env_override(raw)
47
49
  { endpoint: 'WAVEFRONT_ENDPOINT',
48
- token: 'WAVEFRONT_TOKEN',
49
- proxy: 'WAVEFRONT_PROXY' }.each { |k, v| raw[k] = ENV[v] if ENV[v] }
50
+ token: 'WAVEFRONT_TOKEN',
51
+ proxy: 'WAVEFRONT_PROXY' }.each { |k, v| raw[k] = ENV[v] if ENV[v] }
50
52
  raw
51
53
  end
52
54
 
@@ -88,6 +90,7 @@ module Wavefront
88
90
 
89
91
  files.each do |f|
90
92
  next unless f.exist? && f.file?
93
+
91
94
  ret = load_profile(f, profile)
92
95
  ret[:file] = f
93
96
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'core/api'
2
4
  require_relative 'api_mixins/acl'
3
5
  require_relative 'api_mixins/tag'
@@ -34,6 +36,7 @@ module Wavefront
34
36
  #
35
37
  def create(body)
36
38
  raise ArgumentError unless body.is_a?(Hash)
39
+
37
40
  api.post('', body, 'application/json')
38
41
  end
39
42
 
@@ -1,4 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Constants
2
4
  #
3
- DELTA = "\u2206".freeze # "Increment" -- alt-J on a Mac
5
+ DELTA = "\u2206" # "Increment" -- alt-J on a Mac
4
6
  PAGE_SIZE = 999
@@ -1,4 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pathname'
2
4
 
3
- WF_SDK_VERSION = '3.3.3'.freeze
5
+ WF_SDK_VERSION = '3.3.4'
4
6
  WF_SDK_LOCATION = Pathname.new(__dir__).parent.parent.parent
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'core/api'
2
4
  require_relative 'api_mixins/tag'
3
5
 
@@ -28,6 +30,7 @@ module Wavefront
28
30
  #
29
31
  def create(body)
30
32
  raise ArgumentError unless body.is_a?(Hash)
33
+
31
34
  api.post('', body, 'application/json')
32
35
  end
33
36
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'write'
2
4
  require_relative 'support/mixins'
3
5
 
@@ -38,39 +40,57 @@ module Wavefront
38
40
  end
39
41
 
40
42
  def default_port
41
- 40000
43
+ 40_000
44
+ end
45
+
46
+ def data_format
47
+ :histogram
42
48
  end
43
49
 
44
50
  # Convert a validated point to a string conforming to
45
51
  # https://docs.wavefront.com/proxies_histograms.html. No
46
52
  # validation is done here.
47
53
  #
48
- # @param point [Hash] a hash describing a distribution. See
54
+ # @param dist [Hash] a hash describing a distribution. See
49
55
  # #write() for the format.
50
56
  #
51
- # rubocop:disable Metrics/AbcSize
52
57
  def hash_to_wf(dist)
53
58
  logger.log("writer subclass #{writer}", :debug)
54
- raise unless dist.key?(:interval)
55
-
56
- format('!%s %i %s %s source=%s %s %s',
57
- dist[:interval].to_s.upcase,
58
- parse_time(dist.fetch(:ts, Time.now)),
59
- array2dist(dist[:value]),
60
- dist[:path] || raise,
61
- dist.fetch(:source, HOSTNAME),
62
- dist[:tags]&.to_wf_tag,
63
- opts[:tags]&.to_wf_tag).squeeze(' ').strip
64
- rescue StandardError
59
+
60
+ raise unless dist.key?(:interval) && dist.key?(:path)
61
+
62
+ format('!%<interval>s %<ts>i %<value>s %<path>s source=%<source>s ' \
63
+ '%<tags>s %<opttags>s', dist_hash(dist)).squeeze(' ').strip
64
+ rescue RuntimeError
65
65
  raise Wavefront::Exception::InvalidDistribution
66
66
  end
67
- # rubocop:enable Metrics/AbcSize
67
+
68
+ def dist_hash(dist)
69
+ dist.dup.tap do |d|
70
+ d[:interval] = distribution_interval(dist)
71
+ d[:ts] = distribution_timestamp(dist)
72
+ d[:value] = array2dist(dist[:value])
73
+ d[:source] ||= HOSTNAME
74
+ d[:tags] = tags_or_nothing(d[:tags])
75
+ d[:opttags] = tags_or_nothing(opts[:tags])
76
+ end
77
+ end
78
+
79
+ def distribution_timestamp(dist)
80
+ parse_time(dist.fetch(:ts, Time.now))
81
+ end
82
+
83
+ def distribution_interval(dist)
84
+ dist[:interval].to_s.upcase
85
+ end
68
86
 
69
87
  # Turn an array of arrays into a the values part of a distribution
70
88
  # @return [String]
71
89
  #
72
90
  def array2dist(values)
73
- values.map { |x, v| format('#%i %s', x, v) }.join(' ')
91
+ values.map do |x, v|
92
+ format('#%<count>i %<value>s', count: x, value: v)
93
+ end.join(' ')
74
94
  end
75
95
  end
76
96
  end