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.
- checksums.yaml +4 -4
- data/.github/workflows/release.yml +3 -3
- data/.github/workflows/test.yml +2 -2
- data/.rubocop.yml +1 -3
- data/HISTORY.md +17 -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/api_caller.rb +1 -7
- data/lib/wavefront-sdk/core/exception.rb +2 -0
- data/lib/wavefront-sdk/core/response.rb +1 -1
- data/lib/wavefront-sdk/credentials.rb +3 -5
- data/lib/wavefront-sdk/defs/version.rb +1 -1
- data/lib/wavefront-sdk/event.rb +64 -1
- data/lib/wavefront-sdk/maintenancewindow.rb +1 -1
- data/lib/wavefront-sdk/metric.rb +2 -2
- data/lib/wavefront-sdk/metric_helper.rb +1 -1
- data/lib/wavefront-sdk/metricspolicy.rb +57 -0
- data/lib/wavefront-sdk/paginator/base.rb +1 -1
- data/lib/wavefront-sdk/search.rb +3 -3
- data/lib/wavefront-sdk/spy.rb +22 -0
- data/lib/wavefront-sdk/support/mixins.rb +1 -1
- data/lib/wavefront-sdk/support/parse_time.rb +1 -1
- data/lib/wavefront-sdk/user.rb +1 -1
- data/lib/wavefront-sdk/validators.rb +18 -3
- data/lib/wavefront-sdk/write.rb +2 -2
- data/lib/wavefront-sdk/writers/api.rb +1 -1
- data/lib/wavefront-sdk/writers/core.rb +1 -1
- data/lib/wavefront-sdk/writers/proxy.rb +71 -0
- data/lib/wavefront-sdk/writers/socket.rb +15 -27
- data/lib/wavefront_sdk.rb +1 -1
- data/spec/constants.rb +2 -2
- data/spec/test_mixins/general.rb +1 -1
- data/spec/wavefront-sdk/core/api_spec.rb +1 -1
- data/spec/wavefront-sdk/core/response_spec.rb +2 -2
- data/spec/wavefront-sdk/credentials_spec.rb +9 -13
- 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/misc_spec.rb +2 -2
- data/spec/wavefront-sdk/savedsearch_spec.rb +2 -2
- data/spec/wavefront-sdk/spy_spec.rb +27 -0
- data/spec/wavefront-sdk/user_spec.rb +2 -2
- 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 +10 -11
- metadata +27 -97
- 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: 5d89604feef126265df36a17289e1f1320b07e30787f7596d195ea76284526c1
|
4
|
+
data.tar.gz: 393ea7ba3b44646eb1b67c6976713941530b36943ded7e12c4f6a5ee1d87ca7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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@
|
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
|
18
|
+
- name: Set up Ruby 3.0
|
19
19
|
uses: ruby/setup-ruby@v1
|
20
20
|
with:
|
21
|
-
ruby-version:
|
21
|
+
ruby-version: 3.0
|
22
22
|
- run: bundle install
|
23
23
|
|
24
24
|
- name: Run tests
|
data/.github/workflows/test.yml
CHANGED
@@ -9,9 +9,9 @@ jobs:
|
|
9
9
|
runs-on: ubuntu-latest
|
10
10
|
strategy:
|
11
11
|
matrix:
|
12
|
-
ruby-version: [2.
|
12
|
+
ruby-version: [2.7.7, 3.1.3, 3.2.0]
|
13
13
|
steps:
|
14
|
-
- uses: actions/checkout@
|
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
|
+
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/
|
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.
|
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
|
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
|
@@ -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(
|
86
|
-
Pathname.new(
|
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].
|
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),
|
data/lib/wavefront-sdk/metric.rb
CHANGED
@@ -27,10 +27,10 @@ module Wavefront
|
|
27
27
|
if cursor
|
28
28
|
raise ArgumentError unless cursor.is_a?(String)
|
29
29
|
|
30
|
-
query
|
30
|
+
query << [:c, cursor]
|
31
31
|
end
|
32
32
|
|
33
|
-
sources.each { |source| query
|
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]
|
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
|
data/lib/wavefront-sdk/search.rb
CHANGED
@@ -98,7 +98,7 @@ module Wavefront
|
|
98
98
|
end
|
99
99
|
|
100
100
|
path = [entity]
|
101
|
-
path
|
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
|
123
|
-
path
|
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
|
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),
|
@@ -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
|
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)
|
@@ -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 =~ /^[
|
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
|
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')
|
@@ -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
|
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
|