wavefront-sdk 5.4.4 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +1 -1
- data/.rubocop.yml +1 -1
- data/HISTORY.md +12 -0
- data/README.md +5 -5
- data/lib/wavefront-sdk/api_mixins/acl.rb +1 -1
- data/lib/wavefront-sdk/core/api.rb +1 -1
- data/lib/wavefront-sdk/core/exception.rb +2 -0
- data/lib/wavefront-sdk/credentials.rb +1 -3
- data/lib/wavefront-sdk/defs/version.rb +1 -1
- data/lib/wavefront-sdk/event.rb +64 -1
- data/lib/wavefront-sdk/metricspolicy.rb +57 -0
- data/lib/wavefront-sdk/spy.rb +22 -0
- data/lib/wavefront-sdk/user.rb +1 -1
- data/lib/wavefront-sdk/validators.rb +15 -0
- data/lib/wavefront-sdk/write.rb +2 -2
- data/lib/wavefront-sdk/writers/api.rb +1 -1
- data/lib/wavefront-sdk/writers/proxy.rb +71 -0
- data/lib/wavefront-sdk/writers/socket.rb +15 -27
- data/spec/test_mixins/general.rb +1 -1
- data/spec/wavefront-sdk/core/response_spec.rb +2 -2
- data/spec/wavefront-sdk/event_spec.rb +46 -0
- data/spec/wavefront-sdk/metric_helper_spec.rb +2 -0
- data/spec/wavefront-sdk/metricspolicy_spec.rb +94 -0
- data/spec/wavefront-sdk/spy_spec.rb +27 -0
- data/spec/wavefront-sdk/validators_spec.rb +10 -0
- data/spec/wavefront-sdk/write_spec.rb +1 -1
- data/spec/wavefront-sdk/writers/{unix_spec.rb → proxy_spec.rb} +29 -31
- data/spec/wavefront-sdk/writers/socket_spec.rb +26 -24
- data/wavefront-sdk.gemspec +2 -3
- metadata +12 -9
- data/lib/wavefront-sdk/writers/unix.rb +0 -59
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 839f24e0a1a324b6965cb8aec1c0516bcb7c193215bc3cb6c1351f888bd49863
|
4
|
+
data.tar.gz: 97ba3cce211abdef8d1b08265279a2998f968a6f85a58290efe26d8109314940
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d72451c46077024d79451aaea09efec073db0dcfb6dfb7601382973f80b14c99cd3b732bf57ec09a1ec962938b2219470676ba84c47b27051b5d2970cdeb8ef
|
7
|
+
data.tar.gz: fdf2b294468db11835722f3ffbcbac2e77a42a12d8083c4e7536f637659bf8e063de0b75f023e71a46d2a25e942ad197e16e70a4229db5142b741542dbaaf2f7
|
data/.github/workflows/test.yml
CHANGED
data/.rubocop.yml
CHANGED
data/HISTORY.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 6.0.0 (2021-07-16)
|
4
|
+
* Drop support for Ruby 2.4. (Breaking change.)
|
5
|
+
* Change the name of the proxy writer from `socket` to `proxy`. (Breaking
|
6
|
+
change.)
|
7
|
+
* Change the name of the Unix datagram socket writer from `unix` to `socket`.
|
8
|
+
* added `Wavefront::Event#alert_firing_details`.
|
9
|
+
* added `Wavefront::Event#alert_queries_slug`.
|
10
|
+
* added `Wavefront::Event#events`.
|
11
|
+
* added `Wavefront::Event#alert_firings`.
|
12
|
+
* Add `Wavefront::MetricsPolicy`.
|
13
|
+
* Add `Wavefront::Spy#deltas`.
|
14
|
+
|
3
15
|
## 5.4.4 (2021-02-01)
|
4
16
|
* Fix credential validation on writer classes.
|
5
17
|
* Improve tests for writer classes
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# wavefront-sdk
|
2
|
-
](https://github.com/snltd/wavefront-sdk/actions/workflows/test.yml) [](https://github.com/snltd/wavefront-sdk/actions/workflows/release.yml) [](https://codeclimate.com/github/snltd/wavefront-sdk) [](https://codeclimate.com/github/snltd/wavefront-sdk) [](https://badge.fury.io/rb/wavefront-sdk) 
|
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.
|
27
|
+
`wavefront-sdk` requires Ruby >= 2.5. 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
|
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
|
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: :
|
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)
|
@@ -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
|
-
|
97
|
+
old.merge(new).transform_keys(&:to_sym).select do |k, _v|
|
98
98
|
update_keys.include?(k)
|
99
99
|
end
|
100
100
|
end
|
@@ -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].
|
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
|
data/lib/wavefront-sdk/event.rb
CHANGED
@@ -117,12 +117,75 @@ module Wavefront
|
|
117
117
|
api.post([id, 'close'].uri_concat)
|
118
118
|
end
|
119
119
|
|
120
|
-
|
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),
|
@@ -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('', 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)
|
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
|
data/lib/wavefront-sdk/spy.rb
CHANGED
@@ -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),
|
data/lib/wavefront-sdk/user.rb
CHANGED
@@ -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
|
-
|
22
|
+
'next major release. Please use Wavefront::Account.', :warn)
|
23
23
|
end
|
24
24
|
|
25
25
|
def post_initialize(_creds, _opts)
|
@@ -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
|
data/lib/wavefront-sdk/write.rb
CHANGED
@@ -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 :
|
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: :
|
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')
|
@@ -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
|
@@ -1,70 +1,58 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'socket'
|
3
4
|
require_relative 'core'
|
4
5
|
|
5
6
|
module Wavefront
|
6
7
|
module Writer
|
7
8
|
#
|
8
|
-
# Everything specific to writing points to a
|
9
|
-
# native Wavefront format, to a socket. (The original and,
|
10
|
-
# once, only way to send points.)
|
9
|
+
# Everything specific to writing points to a Unix datagram socket.
|
11
10
|
#
|
12
11
|
class Socket < Core
|
13
|
-
#
|
14
|
-
# in instance variable @conn.
|
15
|
-
#
|
12
|
+
# Make a connection to a Unix datagram socket, putting the
|
13
|
+
# descriptor in instance variable @conn.
|
14
|
+
# This requires the name of the socket file in creds[:socket]
|
15
|
+
# @return [UnixSocket]
|
16
16
|
#
|
17
17
|
def open
|
18
18
|
if opts[:noop]
|
19
|
-
logger.log('No-op requested. Not opening connection
|
19
|
+
logger.log('No-op requested. Not opening socket connection.')
|
20
20
|
return true
|
21
21
|
end
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
open_socket(creds[:proxy], port)
|
23
|
+
logger.log("Connecting to #{creds[:socket]}.", :debug)
|
24
|
+
open_socket(creds[:socket])
|
26
25
|
end
|
27
26
|
|
28
|
-
# Close the connection described by the @conn instance variable.
|
29
|
-
#
|
30
27
|
def close
|
31
28
|
return if opts[:noop]
|
32
29
|
|
33
|
-
logger.log('Closing connection
|
30
|
+
logger.log('Closing socket connection.', :debug)
|
34
31
|
conn.close
|
35
32
|
end
|
36
33
|
|
37
34
|
def validate_credentials(creds)
|
38
|
-
return if creds.key?(:
|
35
|
+
return true if creds.key?(:socket) && creds[:socket]
|
39
36
|
|
40
37
|
raise(Wavefront::Exception::CredentialError,
|
41
|
-
'credentials must contain
|
38
|
+
'credentials must contain socket file path')
|
42
39
|
end
|
43
40
|
|
44
41
|
private
|
45
42
|
|
46
|
-
def open_socket(
|
47
|
-
@conn =
|
43
|
+
def open_socket(socket)
|
44
|
+
@conn = UNIXSocket.new(socket)
|
48
45
|
rescue StandardError => e
|
49
46
|
logger.log(e, :error)
|
50
47
|
raise Wavefront::Exception::InvalidEndpoint
|
51
48
|
end
|
52
49
|
|
53
50
|
# @param point [String] point or points in native Wavefront format.
|
54
|
-
# @raise [SocketError] if point cannot be written
|
55
51
|
#
|
56
52
|
def _send_point(point)
|
57
53
|
return if opts[:noop]
|
58
54
|
|
59
|
-
conn.
|
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
|
55
|
+
conn.write(point)
|
68
56
|
end
|
69
57
|
end
|
70
58
|
end
|
data/spec/test_mixins/general.rb
CHANGED
@@ -7,8 +7,8 @@ require_relative '../../../lib/wavefront-sdk/core/exception'
|
|
7
7
|
require_relative '../../../lib/wavefront-sdk/core/response'
|
8
8
|
|
9
9
|
GOOD_RESP = '{"status":{"result":"OK","message":"","code":200},' \
|
10
|
-
|
11
|
-
|
10
|
+
'"response":{"items":[{"name":"test agent"}],"offset":0,' \
|
11
|
+
'"limit":100,"totalItems":3,"moreItems":false}}'
|
12
12
|
|
13
13
|
BAD_RESP = "error='not_found'
|
14
14
|
message='resource cannot be found'
|
@@ -43,12 +43,58 @@ class WavefrontEventTest < WavefrontTestBase
|
|
43
43
|
assert_raises(ArgumentError) { wf.close }
|
44
44
|
end
|
45
45
|
|
46
|
+
def test_alert_firing_details
|
47
|
+
assert_gets("/api/v2/event/#{id}/alertFiringDetails") do
|
48
|
+
wf.alert_firing_details(id)
|
49
|
+
end
|
50
|
+
|
51
|
+
assert_raises(Wavefront::Exception::InvalidEventId) do
|
52
|
+
wf.alert_firing_details(invalid_id)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_alert_queries_slug
|
57
|
+
assert_gets("/api/v2/event/#{id}/alertQueriesSlug") do
|
58
|
+
wf.alert_queries_slug(id)
|
59
|
+
end
|
60
|
+
|
61
|
+
assert_raises(Wavefront::Exception::InvalidEventId) do
|
62
|
+
wf.alert_queries_slug(invalid_id)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_events
|
67
|
+
assert_gets(
|
68
|
+
"/api/v2/event/#{id}/events?isOverlapped=false&renderingMethod=HOST"
|
69
|
+
) do
|
70
|
+
wf.events(id)
|
71
|
+
end
|
72
|
+
|
73
|
+
assert_raises(Wavefront::Exception::InvalidEventId) do
|
74
|
+
wf.events(invalid_id)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_alert_firings
|
79
|
+
assert_gets("/api/v2/event/alertFirings?alertId=#{alert_id}&asc=true") do
|
80
|
+
wf.alert_firings(alert_id, asc: true)
|
81
|
+
end
|
82
|
+
|
83
|
+
assert_raises(Wavefront::Exception::InvalidAlertId) do
|
84
|
+
wf.alert_firings(invalid_id)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
46
88
|
private
|
47
89
|
|
48
90
|
def id
|
49
91
|
'1481553823153:testev'
|
50
92
|
end
|
51
93
|
|
94
|
+
def alert_id
|
95
|
+
'1481553823153'
|
96
|
+
end
|
97
|
+
|
52
98
|
def invalid_id
|
53
99
|
'nonsense'
|
54
100
|
end
|
@@ -4,6 +4,8 @@
|
|
4
4
|
require 'minitest/autorun'
|
5
5
|
require_relative '../spec_helper'
|
6
6
|
require_relative '../../lib/wavefront-sdk/metric_helper'
|
7
|
+
require_relative '../support/mocket'
|
8
|
+
require_relative '../support/bad_mocket'
|
7
9
|
|
8
10
|
ND_CREDS = { proxy: 'wavefront' }.freeze
|
9
11
|
WH_TAGS = { t1: 'v1', t2: 'v2' }.freeze
|
@@ -0,0 +1,94 @@
|
|
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 MetricsPolicy class
|
8
|
+
#
|
9
|
+
class WavefrontMetricsPolicyTest < WavefrontTestBase
|
10
|
+
def test_describe
|
11
|
+
assert_gets('/api/v2/metricspolicy') { wf.describe }
|
12
|
+
|
13
|
+
assert_gets('/api/v2/metricspolicy/history/5') { wf.describe(5) }
|
14
|
+
|
15
|
+
assert_raises(Wavefront::Exception::InvalidVersion) do
|
16
|
+
wf.describe('v5')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_history
|
21
|
+
assert_gets('/api/v2/metricspolicy?offset=10&limit=100') do
|
22
|
+
wf.history(10)
|
23
|
+
end
|
24
|
+
|
25
|
+
assert_gets('/api/v2/metricspolicy?offset=12&limit=34') do
|
26
|
+
wf.history(12, 34)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_revert
|
31
|
+
assert_posts('/api/v2/metricspolicy/revert/5') do
|
32
|
+
wf.revert(5)
|
33
|
+
end
|
34
|
+
|
35
|
+
assert_raises(Wavefront::Exception::InvalidVersion) do
|
36
|
+
wf.revert('v5')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_update
|
41
|
+
assert_puts('/api/v2/metricspolicy', payload.to_json) do
|
42
|
+
wf.update(payload)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def api_class
|
49
|
+
'metricspolicy'
|
50
|
+
end
|
51
|
+
|
52
|
+
def id
|
53
|
+
'a7d2e651-cec1-4154-a5e8-1946f57ef5b3'
|
54
|
+
end
|
55
|
+
|
56
|
+
def invalid_id
|
57
|
+
'+-+-+-+'
|
58
|
+
end
|
59
|
+
|
60
|
+
def payload
|
61
|
+
{
|
62
|
+
policyRules: [
|
63
|
+
{
|
64
|
+
name: 'Policy rule1 name',
|
65
|
+
description: 'Policy rule1 description',
|
66
|
+
prefixes: ['revenue.*'],
|
67
|
+
tags: [
|
68
|
+
{
|
69
|
+
key: 'sensitive',
|
70
|
+
value: 'false'
|
71
|
+
},
|
72
|
+
{
|
73
|
+
key: 'source',
|
74
|
+
value: 'app1'
|
75
|
+
}
|
76
|
+
],
|
77
|
+
tagsAnded: 'true',
|
78
|
+
accessType: 'ALLOW',
|
79
|
+
accounts: %w[accountId1 accountId2],
|
80
|
+
userGroups: ['userGroupId1'],
|
81
|
+
roles: ['roleId']
|
82
|
+
},
|
83
|
+
{
|
84
|
+
name: 'Policy rule2 name',
|
85
|
+
description: 'Policy rule2 description',
|
86
|
+
prefixes: ['revenue.*'],
|
87
|
+
accessType: 'BLOCK',
|
88
|
+
accounts: ['accountId3'],
|
89
|
+
userGroups: ['userGroupId1']
|
90
|
+
}
|
91
|
+
]
|
92
|
+
}
|
93
|
+
end
|
94
|
+
end
|
@@ -38,6 +38,33 @@ class WavefrontSpyTest < MiniTest::Test
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
+
def test_deltas
|
42
|
+
capture_io do
|
43
|
+
assert_gets('/api/spy/deltas?sampling=0.01') { wf.deltas }
|
44
|
+
assert_gets('/api/spy/deltas?sampling=0.05') { wf.deltas(0.05) }
|
45
|
+
|
46
|
+
assert_gets('/api/spy/deltas?sampling=0.05&counter=my_prefix') do
|
47
|
+
wf.deltas(0.05, prefix: 'my_prefix')
|
48
|
+
end
|
49
|
+
|
50
|
+
assert_gets(
|
51
|
+
'/api/spy/deltas?sampling=0.05&counter=my_prefix&host=h1'
|
52
|
+
) do
|
53
|
+
wf.deltas(0.05, prefix: 'my_prefix', host: 'h1')
|
54
|
+
end
|
55
|
+
|
56
|
+
assert_gets('/api/spy/deltas?sampling=0.02&counter=my_prefix&' \
|
57
|
+
'counterTagKey=the_tag') do
|
58
|
+
wf.deltas(0.02, prefix: 'my_prefix', tag_key: 'the_tag')
|
59
|
+
end
|
60
|
+
|
61
|
+
assert_gets('/api/spy/deltas?sampling=0.02&counter=my_prefix&' \
|
62
|
+
'counterTagKey=tag1&counterTagKey=tag2') do
|
63
|
+
wf.deltas(0.02, prefix: 'my_prefix', tag_key: %w[tag1 tag2])
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
41
68
|
def test_histograms
|
42
69
|
capture_io do
|
43
70
|
assert_gets('/api/spy/histograms?sampling=0.01') { wf.histograms }
|
@@ -417,4 +417,14 @@ class WavefrontValidatorsTest < MiniTest::Test
|
|
417
417
|
bad = %w[h5Z9dkr46jbvLtJ HqOM4mru5svd3uFp3 c!lBx!LC*NxLKdx*]
|
418
418
|
good_and_bad('wf_aws_external_id?', 'InvalidAwsExternalId', good, bad)
|
419
419
|
end
|
420
|
+
|
421
|
+
def test_wf_metricspolicy_id
|
422
|
+
good = %w[2bfdcac7-1c9c-4c4b-9b56-c41c22c586dc
|
423
|
+
a7d2e651-cec1-4154-a5e8-1946f57ef5b3
|
424
|
+
fca312fb-5ff4-420d-862d-5d6d99ed6bcf
|
425
|
+
3a1957e0-459e-49e5-9209-3888a4e8ac5b]
|
426
|
+
|
427
|
+
bad = %w[fa312fb-5ff4-420d-862d-5d6d99ed6bcf thing 123]
|
428
|
+
good_and_bad('wf_metricspolicy_id?', 'InvalidMetricsPolicyId', good, bad)
|
429
|
+
end
|
420
430
|
end
|
@@ -27,7 +27,7 @@ class WavefrontWriteTest < MiniTest::Test
|
|
27
27
|
refute(wf.opts[:noop])
|
28
28
|
assert(wf_noop.opts[:noop])
|
29
29
|
assert_equal(wf_tags.opts[:tags], TAGS)
|
30
|
-
assert_instance_of(Wavefront::Writer::
|
30
|
+
assert_instance_of(Wavefront::Writer::Proxy, wf.writer)
|
31
31
|
end
|
32
32
|
|
33
33
|
def test_composite_response
|
@@ -11,36 +11,34 @@ require_relative '../../spec_helper'
|
|
11
11
|
require_relative '../../../lib/wavefront-sdk/write'
|
12
12
|
require_relative '../../../spec/support/mocket'
|
13
13
|
|
14
|
-
|
14
|
+
WS_CREDS = { proxy: 'wavefront-proxy' }.freeze
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
# Test UNIX Datagram socket writing
|
16
|
+
# The Proxy class writes to a proxy TCP socket
|
19
17
|
#
|
20
|
-
class
|
18
|
+
class WavefrontWriterSocketTest < MiniTest::Test
|
21
19
|
attr_reader :wf, :wf_noop
|
22
20
|
|
23
21
|
def setup
|
24
|
-
@wf = Wavefront::Write.new(
|
25
|
-
@wf_noop = Wavefront::Write.new(
|
22
|
+
@wf = Wavefront::Write.new(WS_CREDS, writer: :proxy)
|
23
|
+
@wf_noop = Wavefront::Write.new(WS_CREDS, writer: :proxy, noop: true)
|
26
24
|
end
|
27
25
|
|
28
26
|
def test_writer_class
|
29
|
-
assert_instance_of(Wavefront::Writer::
|
27
|
+
assert_instance_of(Wavefront::Writer::Proxy, wf.writer)
|
30
28
|
end
|
31
29
|
|
32
30
|
def test_write_openclose
|
33
31
|
mocket = Mocket.new
|
34
|
-
Spy.on(
|
35
|
-
mocket_spy = Spy.on(mocket, :
|
32
|
+
Spy.on(TCPSocket, :new).and_return(mocket)
|
33
|
+
mocket_spy = Spy.on(mocket, :puts)
|
36
34
|
wf.write(POINT)
|
37
35
|
assert mocket_spy.has_been_called?
|
38
36
|
end
|
39
37
|
|
40
38
|
def test_write_noop
|
41
39
|
mocket = Mocket.new
|
42
|
-
Spy.on(
|
43
|
-
mocket_spy = Spy.on(mocket, :
|
40
|
+
Spy.on(TCPSocket, :new).and_return(mocket)
|
41
|
+
mocket_spy = Spy.on(mocket, :puts)
|
44
42
|
wf_noop.open
|
45
43
|
wf_noop.write(POINT, false)
|
46
44
|
refute mocket_spy.has_been_called?
|
@@ -48,16 +46,16 @@ class WavefrontWriterUnixTest < MiniTest::Test
|
|
48
46
|
|
49
47
|
def test_write_noop_openclose
|
50
48
|
mocket = Mocket.new
|
51
|
-
Spy.on(
|
52
|
-
mocket_spy = Spy.on(mocket, :
|
49
|
+
Spy.on(TCPSocket, :new).and_return(mocket)
|
50
|
+
mocket_spy = Spy.on(mocket, :puts)
|
53
51
|
wf_noop.write(POINT)
|
54
52
|
refute mocket_spy.has_been_called?
|
55
53
|
end
|
56
54
|
|
57
55
|
def test_write
|
58
56
|
mocket = Mocket.new
|
59
|
-
Spy.on(
|
60
|
-
mocket_spy = Spy.on(mocket, :
|
57
|
+
Spy.on(TCPSocket, :new).and_return(mocket)
|
58
|
+
mocket_spy = Spy.on(mocket, :puts)
|
61
59
|
wf.open
|
62
60
|
wf.write(POINT, false)
|
63
61
|
assert mocket_spy.has_been_called?
|
@@ -65,8 +63,8 @@ class WavefrontWriterUnixTest < MiniTest::Test
|
|
65
63
|
|
66
64
|
def test_write_array
|
67
65
|
mocket = Mocket.new
|
68
|
-
Spy.on(
|
69
|
-
mocket_spy = Spy.on(mocket, :
|
66
|
+
Spy.on(TCPSocket, :new).and_return(mocket)
|
67
|
+
mocket_spy = Spy.on(mocket, :puts)
|
70
68
|
wf.open
|
71
69
|
wf.write(POINT_A, false)
|
72
70
|
assert mocket_spy.has_been_called?
|
@@ -74,32 +72,32 @@ class WavefrontWriterUnixTest < MiniTest::Test
|
|
74
72
|
|
75
73
|
def test_noop_send_point
|
76
74
|
mocket = Mocket.new
|
77
|
-
Spy.on(
|
78
|
-
mocket_spy = Spy.on(mocket, :
|
75
|
+
Spy.on(TCPSocket, :new).and_return(mocket)
|
76
|
+
mocket_spy = Spy.on(mocket, :puts)
|
79
77
|
wf_noop.open
|
80
78
|
wf_noop.send_point(POINT_L)
|
81
79
|
refute mocket_spy.has_been_called?
|
82
80
|
end
|
83
81
|
|
84
82
|
def test_open
|
85
|
-
tcp_spy = Spy.on(
|
83
|
+
tcp_spy = Spy.on(TCPSocket, :new)
|
86
84
|
wf.open
|
87
85
|
assert tcp_spy.has_been_called?
|
88
|
-
assert_equal([
|
86
|
+
assert_equal(['wavefront-proxy', 2878], tcp_spy.calls.first.args)
|
89
87
|
end
|
90
88
|
|
91
89
|
def test_noop_open
|
92
|
-
tcp_spy = Spy.on(
|
90
|
+
tcp_spy = Spy.on(TCPSocket, :new)
|
93
91
|
log_spy = Spy.on(wf_noop.logger, :log)
|
94
92
|
wf_noop.open
|
95
93
|
refute tcp_spy.has_been_called?
|
96
|
-
assert_equal(['No-op requested. Not opening
|
94
|
+
assert_equal(['No-op requested. Not opening connection to proxy.'],
|
97
95
|
log_spy.calls.last.args)
|
98
96
|
assert_equal(1, log_spy.calls.size)
|
99
97
|
end
|
100
98
|
|
101
99
|
def test_noop_close
|
102
|
-
tcp_spy = Spy.on(
|
100
|
+
tcp_spy = Spy.on(TCPSocket, :new)
|
103
101
|
log_spy = Spy.on(wf_noop.logger, :log)
|
104
102
|
wf_noop.close
|
105
103
|
refute tcp_spy.has_been_called?
|
@@ -107,25 +105,25 @@ class WavefrontWriterUnixTest < MiniTest::Test
|
|
107
105
|
end
|
108
106
|
|
109
107
|
def test_validate_credentials
|
110
|
-
assert(Wavefront::Write.new(
|
108
|
+
assert(Wavefront::Write.new(WS_CREDS, writer: :proxy))
|
111
109
|
|
112
110
|
assert_instance_of(Wavefront::Write,
|
113
|
-
Wavefront::Write.new(
|
111
|
+
Wavefront::Write.new(WS_CREDS, writer: :proxy))
|
114
112
|
|
115
113
|
assert_raises(Wavefront::Exception::CredentialError) do
|
116
|
-
Wavefront::Write.new({}, writer: :
|
114
|
+
Wavefront::Write.new({}, writer: :proxy)
|
117
115
|
end
|
118
116
|
|
119
117
|
assert_raises(Wavefront::Exception::CredentialError) do
|
120
|
-
Wavefront::Write.new({ endpoint: 'wavefront.com' }, writer: :
|
118
|
+
Wavefront::Write.new({ endpoint: 'wavefront.com' }, writer: :proxy)
|
121
119
|
end
|
122
120
|
|
123
121
|
assert_raises(Wavefront::Exception::CredentialError) do
|
124
|
-
Wavefront::Write.new({ token: 'abcdef' }, writer: :
|
122
|
+
Wavefront::Write.new({ token: 'abcdef' }, writer: :proxy)
|
125
123
|
end
|
126
124
|
|
127
125
|
assert_raises(Wavefront::Exception::CredentialError) do
|
128
|
-
Wavefront::Write.new({ proxy: nil }, writer: :
|
126
|
+
Wavefront::Write.new({ proxy: nil }, writer: :proxy)
|
129
127
|
end
|
130
128
|
end
|
131
129
|
end
|
@@ -11,16 +11,18 @@ require_relative '../../spec_helper'
|
|
11
11
|
require_relative '../../../lib/wavefront-sdk/write'
|
12
12
|
require_relative '../../../spec/support/mocket'
|
13
13
|
|
14
|
-
|
14
|
+
UNIX_SOCK = '/tmp/testsock'
|
15
15
|
|
16
|
-
|
16
|
+
WU_CREDS = { socket: UNIX_SOCK }.freeze
|
17
|
+
|
18
|
+
# Test UNIX Datagram socket writing
|
17
19
|
#
|
18
|
-
class
|
20
|
+
class WavefrontWriterUnixTest < MiniTest::Test
|
19
21
|
attr_reader :wf, :wf_noop
|
20
22
|
|
21
23
|
def setup
|
22
|
-
@wf = Wavefront::Write.new(
|
23
|
-
@wf_noop = Wavefront::Write.new(
|
24
|
+
@wf = Wavefront::Write.new(WU_CREDS, writer: :socket)
|
25
|
+
@wf_noop = Wavefront::Write.new(WU_CREDS, writer: :socket, noop: true)
|
24
26
|
end
|
25
27
|
|
26
28
|
def test_writer_class
|
@@ -29,16 +31,16 @@ class WavefrontWriterSocketTest < MiniTest::Test
|
|
29
31
|
|
30
32
|
def test_write_openclose
|
31
33
|
mocket = Mocket.new
|
32
|
-
Spy.on(
|
33
|
-
mocket_spy = Spy.on(mocket, :
|
34
|
+
Spy.on(UNIXSocket, :new).and_return(mocket)
|
35
|
+
mocket_spy = Spy.on(mocket, :write)
|
34
36
|
wf.write(POINT)
|
35
37
|
assert mocket_spy.has_been_called?
|
36
38
|
end
|
37
39
|
|
38
40
|
def test_write_noop
|
39
41
|
mocket = Mocket.new
|
40
|
-
Spy.on(
|
41
|
-
mocket_spy = Spy.on(mocket, :
|
42
|
+
Spy.on(UNIXSocket, :new).and_return(mocket)
|
43
|
+
mocket_spy = Spy.on(mocket, :write)
|
42
44
|
wf_noop.open
|
43
45
|
wf_noop.write(POINT, false)
|
44
46
|
refute mocket_spy.has_been_called?
|
@@ -46,16 +48,16 @@ class WavefrontWriterSocketTest < MiniTest::Test
|
|
46
48
|
|
47
49
|
def test_write_noop_openclose
|
48
50
|
mocket = Mocket.new
|
49
|
-
Spy.on(
|
50
|
-
mocket_spy = Spy.on(mocket, :
|
51
|
+
Spy.on(UNIXSocket, :new).and_return(mocket)
|
52
|
+
mocket_spy = Spy.on(mocket, :write)
|
51
53
|
wf_noop.write(POINT)
|
52
54
|
refute mocket_spy.has_been_called?
|
53
55
|
end
|
54
56
|
|
55
57
|
def test_write
|
56
58
|
mocket = Mocket.new
|
57
|
-
Spy.on(
|
58
|
-
mocket_spy = Spy.on(mocket, :
|
59
|
+
Spy.on(UNIXSocket, :new).and_return(mocket)
|
60
|
+
mocket_spy = Spy.on(mocket, :write)
|
59
61
|
wf.open
|
60
62
|
wf.write(POINT, false)
|
61
63
|
assert mocket_spy.has_been_called?
|
@@ -63,8 +65,8 @@ class WavefrontWriterSocketTest < MiniTest::Test
|
|
63
65
|
|
64
66
|
def test_write_array
|
65
67
|
mocket = Mocket.new
|
66
|
-
Spy.on(
|
67
|
-
mocket_spy = Spy.on(mocket, :
|
68
|
+
Spy.on(UNIXSocket, :new).and_return(mocket)
|
69
|
+
mocket_spy = Spy.on(mocket, :write)
|
68
70
|
wf.open
|
69
71
|
wf.write(POINT_A, false)
|
70
72
|
assert mocket_spy.has_been_called?
|
@@ -72,32 +74,32 @@ class WavefrontWriterSocketTest < MiniTest::Test
|
|
72
74
|
|
73
75
|
def test_noop_send_point
|
74
76
|
mocket = Mocket.new
|
75
|
-
Spy.on(
|
76
|
-
mocket_spy = Spy.on(mocket, :
|
77
|
+
Spy.on(UNIXSocket, :new).and_return(mocket)
|
78
|
+
mocket_spy = Spy.on(mocket, :write)
|
77
79
|
wf_noop.open
|
78
80
|
wf_noop.send_point(POINT_L)
|
79
81
|
refute mocket_spy.has_been_called?
|
80
82
|
end
|
81
83
|
|
82
84
|
def test_open
|
83
|
-
tcp_spy = Spy.on(
|
85
|
+
tcp_spy = Spy.on(UNIXSocket, :new)
|
84
86
|
wf.open
|
85
87
|
assert tcp_spy.has_been_called?
|
86
|
-
assert_equal([
|
88
|
+
assert_equal([UNIX_SOCK], tcp_spy.calls.first.args)
|
87
89
|
end
|
88
90
|
|
89
91
|
def test_noop_open
|
90
|
-
tcp_spy = Spy.on(
|
92
|
+
tcp_spy = Spy.on(UNIXSocket, :new)
|
91
93
|
log_spy = Spy.on(wf_noop.logger, :log)
|
92
94
|
wf_noop.open
|
93
95
|
refute tcp_spy.has_been_called?
|
94
|
-
assert_equal(['No-op requested. Not opening connection
|
96
|
+
assert_equal(['No-op requested. Not opening socket connection.'],
|
95
97
|
log_spy.calls.last.args)
|
96
98
|
assert_equal(1, log_spy.calls.size)
|
97
99
|
end
|
98
100
|
|
99
101
|
def test_noop_close
|
100
|
-
tcp_spy = Spy.on(
|
102
|
+
tcp_spy = Spy.on(UNIXSocket, :new)
|
101
103
|
log_spy = Spy.on(wf_noop.logger, :log)
|
102
104
|
wf_noop.close
|
103
105
|
refute tcp_spy.has_been_called?
|
@@ -105,10 +107,10 @@ class WavefrontWriterSocketTest < MiniTest::Test
|
|
105
107
|
end
|
106
108
|
|
107
109
|
def test_validate_credentials
|
108
|
-
assert(Wavefront::Write.new(
|
110
|
+
assert(Wavefront::Write.new(WU_CREDS, writer: :socket))
|
109
111
|
|
110
112
|
assert_instance_of(Wavefront::Write,
|
111
|
-
Wavefront::Write.new(
|
113
|
+
Wavefront::Write.new(WU_CREDS, writer: :socket))
|
112
114
|
|
113
115
|
assert_raises(Wavefront::Exception::CredentialError) do
|
114
116
|
Wavefront::Write.new({}, writer: :socket)
|
data/wavefront-sdk.gemspec
CHANGED
@@ -7,7 +7,6 @@ require_relative 'lib/wavefront-sdk/defs/version'
|
|
7
7
|
Gem::Specification.new do |gem|
|
8
8
|
gem.name = 'wavefront-sdk'
|
9
9
|
gem.version = WF_SDK_VERSION
|
10
|
-
gem.date = Date.today.to_s
|
11
10
|
|
12
11
|
gem.summary = 'SDK for Wavefront API v2'
|
13
12
|
gem.description = 'SDK for Wavefront (wavefront.com) API v2 '
|
@@ -29,7 +28,7 @@ Gem::Specification.new do |gem|
|
|
29
28
|
|
30
29
|
gem.add_development_dependency 'minitest', '~> 5.14'
|
31
30
|
gem.add_development_dependency 'rake', '~> 13.0'
|
32
|
-
gem.add_development_dependency 'rubocop', '~> 1.
|
31
|
+
gem.add_development_dependency 'rubocop', '~> 1.17'
|
33
32
|
gem.add_development_dependency 'rubocop-minitest', '~> 0.10'
|
34
33
|
gem.add_development_dependency 'rubocop-performance', '~> 1.3'
|
35
34
|
gem.add_development_dependency 'rubocop-rake', '~> 0.5'
|
@@ -38,5 +37,5 @@ Gem::Specification.new do |gem|
|
|
38
37
|
gem.add_development_dependency 'webmock', '~> 3.9'
|
39
38
|
gem.add_development_dependency 'yard', '~> 0.9'
|
40
39
|
|
41
|
-
gem.required_ruby_version = Gem::Requirement.new('>= 2.
|
40
|
+
gem.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
|
42
41
|
end
|
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
|
+
version: 6.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: 2021-
|
11
|
+
date: 2021-07-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -100,14 +100,14 @@ dependencies:
|
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '1.
|
103
|
+
version: '1.17'
|
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: '1.
|
110
|
+
version: '1.17'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: rubocop-minitest
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -248,6 +248,7 @@ files:
|
|
248
248
|
- lib/wavefront-sdk/message.rb
|
249
249
|
- lib/wavefront-sdk/metric.rb
|
250
250
|
- lib/wavefront-sdk/metric_helper.rb
|
251
|
+
- lib/wavefront-sdk/metricspolicy.rb
|
251
252
|
- lib/wavefront-sdk/notificant.rb
|
252
253
|
- lib/wavefront-sdk/paginator/base.rb
|
253
254
|
- lib/wavefront-sdk/paginator/delete.rb
|
@@ -283,9 +284,9 @@ files:
|
|
283
284
|
- lib/wavefront-sdk/writers/api.rb
|
284
285
|
- lib/wavefront-sdk/writers/core.rb
|
285
286
|
- lib/wavefront-sdk/writers/http.rb
|
287
|
+
- lib/wavefront-sdk/writers/proxy.rb
|
286
288
|
- lib/wavefront-sdk/writers/socket.rb
|
287
289
|
- lib/wavefront-sdk/writers/summary.rb
|
288
|
-
- lib/wavefront-sdk/writers/unix.rb
|
289
290
|
- lib/wavefront_sdk.rb
|
290
291
|
- spec/.rubocop.yml
|
291
292
|
- spec/constants.rb
|
@@ -318,6 +319,7 @@ files:
|
|
318
319
|
- spec/wavefront-sdk/message_spec.rb
|
319
320
|
- spec/wavefront-sdk/metric_helper_spec.rb
|
320
321
|
- spec/wavefront-sdk/metric_spec.rb
|
322
|
+
- spec/wavefront-sdk/metricspolicy_spec.rb
|
321
323
|
- spec/wavefront-sdk/misc_spec.rb
|
322
324
|
- spec/wavefront-sdk/notificant_spec.rb
|
323
325
|
- spec/wavefront-sdk/paginator/base_spec.rb
|
@@ -357,9 +359,9 @@ files:
|
|
357
359
|
- spec/wavefront-sdk/writers/api_spec.rb
|
358
360
|
- spec/wavefront-sdk/writers/core_spec.rb
|
359
361
|
- spec/wavefront-sdk/writers/http_spec.rb
|
362
|
+
- spec/wavefront-sdk/writers/proxy_spec.rb
|
360
363
|
- spec/wavefront-sdk/writers/socket_spec.rb
|
361
364
|
- spec/wavefront-sdk/writers/summary_spec.rb
|
362
|
-
- spec/wavefront-sdk/writers/unix_spec.rb
|
363
365
|
- wavefront-sdk.gemspec
|
364
366
|
homepage: https://github.com/snltd/wavefront-sdk
|
365
367
|
licenses:
|
@@ -373,14 +375,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
373
375
|
requirements:
|
374
376
|
- - ">="
|
375
377
|
- !ruby/object:Gem::Version
|
376
|
-
version: 2.
|
378
|
+
version: 2.5.0
|
377
379
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
378
380
|
requirements:
|
379
381
|
- - ">="
|
380
382
|
- !ruby/object:Gem::Version
|
381
383
|
version: '0'
|
382
384
|
requirements: []
|
383
|
-
rubygems_version: 3.1.
|
385
|
+
rubygems_version: 3.1.6
|
384
386
|
signing_key:
|
385
387
|
specification_version: 4
|
386
388
|
summary: SDK for Wavefront API v2
|
@@ -416,6 +418,7 @@ test_files:
|
|
416
418
|
- spec/wavefront-sdk/message_spec.rb
|
417
419
|
- spec/wavefront-sdk/metric_helper_spec.rb
|
418
420
|
- spec/wavefront-sdk/metric_spec.rb
|
421
|
+
- spec/wavefront-sdk/metricspolicy_spec.rb
|
419
422
|
- spec/wavefront-sdk/misc_spec.rb
|
420
423
|
- spec/wavefront-sdk/notificant_spec.rb
|
421
424
|
- spec/wavefront-sdk/paginator/base_spec.rb
|
@@ -455,6 +458,6 @@ test_files:
|
|
455
458
|
- spec/wavefront-sdk/writers/api_spec.rb
|
456
459
|
- spec/wavefront-sdk/writers/core_spec.rb
|
457
460
|
- spec/wavefront-sdk/writers/http_spec.rb
|
461
|
+
- spec/wavefront-sdk/writers/proxy_spec.rb
|
458
462
|
- spec/wavefront-sdk/writers/socket_spec.rb
|
459
463
|
- spec/wavefront-sdk/writers/summary_spec.rb
|
460
|
-
- spec/wavefront-sdk/writers/unix_spec.rb
|
@@ -1,59 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'socket'
|
4
|
-
require_relative 'core'
|
5
|
-
|
6
|
-
module Wavefront
|
7
|
-
module Writer
|
8
|
-
#
|
9
|
-
# Everything specific to writing points to a Unix datagram socket.
|
10
|
-
#
|
11
|
-
class Unix < Core
|
12
|
-
# Make a connection to a Unix datagram socket, putting the
|
13
|
-
# descriptor in instance variable @conn.
|
14
|
-
# This requires the name of the socket file in creds[:socket]
|
15
|
-
# @return [UnixSocket]
|
16
|
-
#
|
17
|
-
def open
|
18
|
-
if opts[:noop]
|
19
|
-
logger.log('No-op requested. Not opening socket connection.')
|
20
|
-
return true
|
21
|
-
end
|
22
|
-
|
23
|
-
logger.log("Connecting to #{creds[:socket]}.", :debug)
|
24
|
-
open_socket(creds[:socket])
|
25
|
-
end
|
26
|
-
|
27
|
-
def close
|
28
|
-
return if opts[:noop]
|
29
|
-
|
30
|
-
logger.log('Closing socket connection.', :debug)
|
31
|
-
conn.close
|
32
|
-
end
|
33
|
-
|
34
|
-
def validate_credentials(creds)
|
35
|
-
return if creds.key?(:socket) && creds[:socket]
|
36
|
-
|
37
|
-
raise(Wavefront::Exception::CredentialError,
|
38
|
-
'credentials must contain socket file path')
|
39
|
-
end
|
40
|
-
|
41
|
-
private
|
42
|
-
|
43
|
-
def open_socket(socket)
|
44
|
-
@conn = UNIXSocket.new(socket)
|
45
|
-
rescue StandardError => e
|
46
|
-
logger.log(e, :error)
|
47
|
-
raise Wavefront::Exception::InvalidEndpoint
|
48
|
-
end
|
49
|
-
|
50
|
-
# @param point [String] point or points in native Wavefront format.
|
51
|
-
#
|
52
|
-
def _send_point(point)
|
53
|
-
return if opts[:noop]
|
54
|
-
|
55
|
-
conn.write(point)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|