wavefront-sdk 5.4.3 → 5.4.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2ece811673855c324e3a66865f9d86b9053b9a0d45ec6e911132fc00222373a6
4
- data.tar.gz: c3db55c441feb6c6b24d3f7eb55037475a44073942799cc459be621d8f4dc471
3
+ metadata.gz: 1f0aafb012ded5a99a13ee3553d686e0552f5c4cae8da39e70139f6882aadcc9
4
+ data.tar.gz: b033a54d99e7a8402d04fd3555d56c53c765b655f89c59c6b1b27e2880ec5945
5
5
  SHA512:
6
- metadata.gz: 77b0ecdbb4457c26f8fa19729dcd0411a8413b202728094f5700c4cd1db4573c92a52b17b409e62901026096b0c6c678113fc4b6885a28149d0b972c8c7dc608
7
- data.tar.gz: a6757a5c5a3189598a418c3a399a634ada40298a5771c16d1741785c064c5557938962efe657bca97c226884f401a0270677e7e7bbb1077ba846c3473d443fc6
6
+ metadata.gz: e647c51a97b626d080d7d666e17b81c6ead709b8780f0bb3f2897fc34d326df65d6c524359f4ea461520ef75cf7d29883f1f822feb774b06a3d822ce7717e882
7
+ data.tar.gz: c6602237acfdf5c18820e086071e1f06cc73199fc45ef02e689f091fec36208936b3618c5ec0d1464fff2773f4424bb49d0be3c9ba394da5d31143a14e2aed71
data/.codeclimate.yml CHANGED
@@ -11,7 +11,7 @@ engines:
11
11
  fixme:
12
12
  enabled: true
13
13
  rubocop:
14
- enabled: true
14
+ enabled: false
15
15
  ratings:
16
16
  paths:
17
17
  - "**.rb"
@@ -9,7 +9,7 @@ jobs:
9
9
  runs-on: ubuntu-latest
10
10
  strategy:
11
11
  matrix:
12
- ruby-version: [2.5.8, 2.6.6, 2.7.2]
12
+ ruby-version: [2.4.10, 2.5.8, 2.6.6, 2.7.2, 3.0.0]
13
13
  steps:
14
14
  - uses: actions/checkout@v2
15
15
  - name: Set up Ruby
data/.rubocop.yml CHANGED
@@ -4,15 +4,17 @@ AllCops:
4
4
  TargetRubyVersion: 2.4
5
5
  NewCops: enable
6
6
 
7
- Metrics/ClassLength:
8
- Max: 150
7
+ require:
8
+ - rubocop-rake
9
+ - rubocop-minitest
10
+ - rubocop-performance
11
+ - rubocop-performance
9
12
 
10
- # Is nothing sacred?
11
13
  Layout/LineLength:
12
14
  Max: 80
13
-
15
+ Metrics/ClassLength:
16
+ Max: 150
14
17
  Style/StringConcatenation:
15
18
  Enabled: false
16
-
17
19
  Style/OptionalBooleanParameter:
18
20
  Enabled: false
data/HISTORY.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 5.4.4 (2021-02-01)
4
+ * Fix credential validation on writer classes.
5
+ * Improve tests for writer classes
6
+ * Change the level of "wire format" messages from `INFO` to `DEBUG`.
7
+ * Officially support Ruby 3.0.0.
8
+ * Move off Travis, and on to Github Actions.
9
+ * Modernise linting and use of linter.
10
+
3
11
  ## 5.4.3 (2021-01-28)
4
12
  * Always pass through invalid timestamp on time-parsing error.
5
13
 
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # wavefront-sdk
2
- [![Build Status](https://travis-ci.org/snltd/wavefront-sdk.svg?branch=master)](https://travis-ci.org/snltd/wavefront-sdk) [![Code Climate](https://codeclimate.com/github/snltd/wavefront-sdk/badges/gpa.svg)](https://codeclimate.com/github/snltd/wavefront-sdk) [![Issue Count](https://codeclimate.com/github/snltd/wavefront-sdk/badges/issue_count.svg)](https://codeclimate.com/github/snltd/wavefront-sdk) [![Gem Version](https://badge.fury.io/rb/wavefront-sdk.svg)](https://badge.fury.io/rb/wavefront-sdk) ![](http://ruby-gem-downloads-badge.herokuapp.com/wavefront-sdk?type=total)
2
+ ![Test](https://github.com/snltd/wavefront-sdk/workflows/Test/badge.svg) ![Release](https://github.com/snltd/wavefront-sdk/workflows/Release/badge.svg) [![Code Climate](https://codeclimate.com/github/snltd/wavefront-sdk/badges/gpa.svg)](https://codeclimate.com/github/snltd/wavefront-sdk) [![Issue Count](https://codeclimate.com/github/snltd/wavefront-sdk/badges/issue_count.svg)](https://codeclimate.com/github/snltd/wavefront-sdk) [![Gem Version](https://badge.fury.io/rb/wavefront-sdk.svg)](https://badge.fury.io/rb/wavefront-sdk) ![](http://ruby-gem-downloads-badge.herokuapp.com/wavefront-sdk?type=total)
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
@@ -134,7 +134,7 @@ module Wavefront
134
134
  def post(path, body = nil, ctype = 'text/plain')
135
135
  body = body.to_json unless body.is_a?(String)
136
136
  make_call(mk_conn(path, 'Content-Type': ctype,
137
- 'Accept': 'application/json'),
137
+ Accept: 'application/json'),
138
138
  :post, nil, body)
139
139
  end
140
140
 
@@ -149,7 +149,7 @@ module Wavefront
149
149
  #
150
150
  def put(path, body = nil, ctype = 'application/json')
151
151
  make_call(mk_conn(path, 'Content-Type': ctype,
152
- 'Accept': 'application/json'),
152
+ Accept: 'application/json'),
153
153
  :put, nil, body.to_json)
154
154
  end
155
155
 
@@ -6,61 +6,117 @@ module Wavefront
6
6
  #
7
7
  class Exception
8
8
  class CredentialError < RuntimeError; end
9
+
9
10
  class EmptyMetricName < RuntimeError; end
11
+
10
12
  class EnumerableError < RuntimeError; end
13
+
11
14
  class InvalidAccountId < RuntimeError; end
15
+
12
16
  class InvalidAlertId < RuntimeError; end
17
+
13
18
  class InvalidAlertSeverity < RuntimeError; end
19
+
14
20
  class InvalidApiTokenId < RuntimeError; end
21
+
15
22
  class InvalidAwsExternalId < RuntimeError; end
23
+
16
24
  class InvalidConfigFile < RuntimeError; end
25
+
17
26
  class InvalidCloudIntegrationId < RuntimeError; end
27
+
18
28
  class InvalidDashboardId < RuntimeError; end
29
+
19
30
  class InvalidDerivedMetricId < RuntimeError; end
31
+
20
32
  class InvalidDistribution < RuntimeError; end
33
+
21
34
  class InvalidDistributionInterval < RuntimeError; end
35
+
22
36
  class InvalidDistributionCount < RuntimeError; end
37
+
23
38
  class InvalidEndpoint < RuntimeError; end
39
+
24
40
  class InvalidEventId < RuntimeError; end
41
+
25
42
  class InvalidExternalLinkId < RuntimeError; end
43
+
26
44
  class InvalidGranularity < RuntimeError; end
45
+
27
46
  class InvalidHostname < RuntimeError; end
47
+
28
48
  class InvalidIngestionPolicyId < RuntimeError; end
49
+
29
50
  class InvalidIntegrationId < RuntimeError; end
51
+
30
52
  class InvalidLinkTemplate < RuntimeError; end
53
+
31
54
  class InvalidMaintenanceWindowId < RuntimeError; end
55
+
32
56
  class InvalidMonitoredClusterId < RuntimeError; end
57
+
33
58
  class InvalidMessageId < RuntimeError; end
59
+
34
60
  class InvalidMetricName < RuntimeError; end
61
+
35
62
  class InvalidMetricValue < RuntimeError; end
63
+
36
64
  class InvalidName < RuntimeError; end
65
+
37
66
  class InvalidNotificantId < RuntimeError; end
67
+
38
68
  class InvalidPermission < RuntimeError; end
69
+
39
70
  class InvalidPoint < RuntimeError; end
71
+
40
72
  class InvalidPrefixLength < RuntimeError; end
73
+
41
74
  class InvalidProxyId < RuntimeError; end
75
+
42
76
  class InvalidRoleId < RuntimeError; end
77
+
43
78
  class InvalidRelativeTime < RuntimeError; end
79
+
44
80
  class InvalidSamplingValue < RuntimeError; end
81
+
45
82
  class InvalidSavedSearchEntity < RuntimeError; end
83
+
46
84
  class InvalidSavedSearchId < RuntimeError; end
85
+
47
86
  class InvalidServiceAccountId < RuntimeError; end
87
+
48
88
  class InvalidSourceId < RuntimeError; end
89
+
49
90
  class InvalidString < RuntimeError; end
91
+
50
92
  class InvalidTag < RuntimeError; end
93
+
51
94
  class InvalidTimeFormat < RuntimeError; end
95
+
52
96
  class InvalidTimeUnit < RuntimeError; end
97
+
53
98
  class InvalidTimestamp < RuntimeError; end
99
+
54
100
  class InvalidUserId < RuntimeError; end
101
+
55
102
  class InvalidUserGroupId < RuntimeError; end
103
+
56
104
  class InvalidVersion < RuntimeError; end
105
+
57
106
  class InvalidWebhookId < RuntimeError; end
107
+
58
108
  class MissingConfigProfile < RuntimeError; end
109
+
59
110
  class NetworkTimeout < RuntimeError; end
111
+
60
112
  class NotImplemented < RuntimeError; end
113
+
61
114
  class SocketError < RuntimeError; end
115
+
62
116
  class UnparseableResponse < RuntimeError; end
117
+
63
118
  class UnsupportedWriter < RuntimeError; end
119
+
64
120
  class ValueOutOfRange < RuntimeError; end
65
121
  end
66
122
  end
@@ -65,12 +65,14 @@ module Wavefront
65
65
  # @return void
66
66
  #
67
67
  def populate(raw)
68
+ creds_keys = %i[endpoint token]
69
+ proxy_keys = %i[proxy port]
70
+ all_keys = creds_keys + proxy_keys
71
+
68
72
  @config = Map(raw)
69
- @creds = Map(raw.select { |k, _v| %i[endpoint token].include?(k) })
70
- @proxy = Map(raw.select { |k, _v| %i[proxy port].include?(k) })
71
- @all = Map(raw.select do |k, _v|
72
- %i[proxy port endpoint token].include?(k)
73
- end)
73
+ @creds = Map(raw.select { |k, _v| creds_keys.include?(k) })
74
+ @proxy = Map(raw.select { |k, _v| proxy_keys.include?(k) })
75
+ @all = Map(raw.select { |k, _v| all_keys.include?(k) })
74
76
  end
75
77
 
76
78
  # @return [Array] a list of possible credential files
@@ -2,5 +2,5 @@
2
2
 
3
3
  require 'pathname'
4
4
 
5
- WF_SDK_VERSION = '5.4.3'
5
+ WF_SDK_VERSION = '5.4.4'
6
6
  WF_SDK_LOCATION = Pathname.new(__dir__).parent.parent.parent
@@ -28,6 +28,7 @@ module Wavefront
28
28
  # @param limit [Integer] the number of events to return
29
29
  # @return [Wavefront::Response]
30
30
  #
31
+ # rubocop:disable Metrics/ParameterLists
31
32
  def list(from = nil, to = Time.now, limit = 100, cursor = nil)
32
33
  raise ArgumentError unless from && to
33
34
 
@@ -37,6 +38,7 @@ module Wavefront
37
38
  wf_ms_ts?(body[:latestStartTimeEpochMillis])
38
39
  api.get('', body.cleanse)
39
40
  end
41
+ # rubocop:enable Metrics/ParameterLists
40
42
 
41
43
  # POST /api/v2/event
42
44
  # Create a specific event.
@@ -30,6 +30,7 @@ module Wavefront
30
30
  # @raise [ArgumentError] if query is not a string
31
31
  # @return [Wavefront::Response]
32
32
  #
33
+ # rubocop:disable Metrics/ParameterLists
33
34
  def query(query, granularity = nil, t_start = nil, t_end = nil,
34
35
  options = {})
35
36
 
@@ -45,6 +46,7 @@ module Wavefront
45
46
 
46
47
  api.get('api', options)
47
48
  end
49
+ # rubocop:enable Metrics/ParameterLists
48
50
 
49
51
  # GET /api/v2/chart/raw
50
52
  # Perform a raw data query against Wavefront servers that
@@ -113,6 +113,7 @@ module Wavefront
113
113
  # specified in the body. See the Swagger docs for more
114
114
  # information.
115
115
  #
116
+ # rubocop:disable Metrics/ParameterLists
116
117
  def raw_facet_search(entity = nil, body = nil, deleted = false,
117
118
  facet = false)
118
119
  raise ArgumentError unless entity.is_a?(String) && body.is_a?(Hash)
@@ -122,5 +123,6 @@ module Wavefront
122
123
  path.<< facet || 'facets'
123
124
  api.post(path, body, 'application/json')
124
125
  end
126
+ # rubocop:enable Metrics/ParameterLists
125
127
  end
126
128
  end
@@ -48,8 +48,8 @@ module Wavefront
48
48
  #
49
49
  def wf_metric_name?(metric)
50
50
  if metric.is_a?(String) && metric.size < 1024 &&
51
- (metric.match(/^#{DELTA}?[\w\-.]+$/) ||
52
- metric.match(%r{^"#{DELTA}?[\w\-./,]+"$}))
51
+ (metric.match(/^#{DELTA}?[\w\-.]+$/o) ||
52
+ metric.match(%r{^"#{DELTA}?[\w\-./,]+"$}o))
53
53
  return true
54
54
  end
55
55
 
@@ -118,7 +118,7 @@ module Wavefront
118
118
  summary = { sent: 0, rejected: 0, unsent: 0 }
119
119
 
120
120
  %i[sent rejected unsent].each do |k|
121
- summary[k] = responses.map { |r| r.response[k] }.inject(:+)
121
+ summary[k] = responses.sum { |r| r.response[k] }
122
122
  end
123
123
 
124
124
  Wavefront::Response.new(
@@ -19,12 +19,12 @@ module Wavefront
19
19
  end
20
20
 
21
21
  def validate_credentials(creds)
22
- unless creds.key?(:endpoint)
22
+ unless creds.key?(:endpoint) && creds[:endpoint]
23
23
  raise(Wavefront::Exception::CredentialError,
24
24
  'credentials must contain API endpoint')
25
25
  end
26
26
 
27
- return true if creds.key?(:token)
27
+ return if creds.key?(:token) && creds[:token]
28
28
 
29
29
  raise(Wavefront::Exception::CredentialError,
30
30
  'credentials must contain API token')
@@ -99,7 +99,7 @@ module Wavefront
99
99
  #
100
100
  def hash_to_wf(point)
101
101
  wf_point = calling_class.hash_to_wf(point)
102
- logger.log(wf_point, :info)
102
+ logger.log(wf_point, :debug)
103
103
  wf_point
104
104
  end
105
105
 
@@ -29,10 +29,10 @@ module Wavefront
29
29
  end
30
30
 
31
31
  def validate_credentials(creds)
32
- return true if creds.key?(:proxy)
32
+ return true if creds.key?(:proxy) && creds[:proxy]
33
33
 
34
34
  raise(Wavefront::Exception::CredentialError,
35
- 'credentials must contain proxy')
35
+ 'credentials must contain proxy address')
36
36
  end
37
37
 
38
38
  def chunk_size
@@ -35,10 +35,10 @@ module Wavefront
35
35
  end
36
36
 
37
37
  def validate_credentials(creds)
38
- return true if creds.key?(:proxy)
38
+ return if creds.key?(:proxy) && creds[:proxy]
39
39
 
40
40
  raise(Wavefront::Exception::CredentialError,
41
- 'creds must contain proxy address')
41
+ 'credentials must contain proxy address')
42
42
  end
43
43
 
44
44
  private
@@ -6,8 +6,7 @@ require_relative 'core'
6
6
  module Wavefront
7
7
  module Writer
8
8
  #
9
- # Everything specific to writing points to a Unix datagram
10
- # socket.
9
+ # Everything specific to writing points to a Unix datagram socket.
11
10
  #
12
11
  class Unix < Core
13
12
  # Make a connection to a Unix datagram socket, putting the
@@ -33,10 +32,10 @@ module Wavefront
33
32
  end
34
33
 
35
34
  def validate_credentials(creds)
36
- return true if creds.key?(:socket)
35
+ return if creds.key?(:socket) && creds[:socket]
37
36
 
38
37
  raise(Wavefront::Exception::CredentialError,
39
- 'creds must contain socket file path')
38
+ 'credentials must contain socket file path')
40
39
  end
41
40
 
42
41
  private
@@ -48,10 +47,11 @@ module Wavefront
48
47
  raise Wavefront::Exception::InvalidEndpoint
49
48
  end
50
49
 
51
- # @param point [String] point or points in native Wavefront
52
- # format.
50
+ # @param point [String] point or points in native Wavefront format.
53
51
  #
54
52
  def _send_point(point)
53
+ return if opts[:noop]
54
+
55
55
  conn.write(point)
56
56
  end
57
57
  end
data/spec/.rubocop.yml CHANGED
@@ -1,23 +1,11 @@
1
- AllCops:
2
- NewCops: enable
1
+ inherit_from:
2
+ - ../.rubocop.yml
3
3
 
4
4
  Metrics/AbcSize:
5
5
  Max: 64
6
-
7
- # Configuration parameters: CountComments.
8
6
  Metrics/ClassLength:
9
7
  Max: 400
10
-
11
- # Configuration parameters: CountComments, ExcludedMethods.
12
8
  Metrics/MethodLength:
13
9
  Max: 39
14
-
15
- # Is nothing sacred?
16
- Layout/LineLength:
17
- Max: 80
18
-
19
- Style/StringConcatenation:
20
- Enabled: false
21
-
22
- Style/OptionalBooleanParameter:
10
+ Naming/VariableNumber:
23
11
  Enabled: false
data/spec/constants.rb CHANGED
@@ -26,7 +26,7 @@ U_ACL_1 = 'someone@example.com'
26
26
  U_ACL_2 = 'other@elsewhere.com'
27
27
  GRP_ACL = 'f8dc0c14-91a0-4ca9-8a2a-7d47f4db4672'
28
28
 
29
- DEFAULT_HEADERS = { 'Accept': /.*/,
29
+ DEFAULT_HEADERS = { Accept: /.*/,
30
30
  'Accept-Encoding': /.*/,
31
- 'Authorization': 'Bearer 0123456789-ABCDEF',
31
+ Authorization: 'Bearer 0123456789-ABCDEF',
32
32
  'User-Agent': /wavefront-sdk \d+\.\d+\.\d+/ }.freeze
@@ -1,10 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # A mock socket
3
+ # A mock socket. Stubs TCP sockets and UNIX domain sockets.
4
4
  #
5
5
  class Mocket
6
6
  def puts(socket); end
7
7
 
8
+ def write(socket); end
9
+
8
10
  def close; end
9
11
 
10
12
  def ok?
@@ -115,12 +115,12 @@ class WavefrontMetricHelperTest < MiniTest::Test
115
115
  out = wfd.dists_to_wf(input)
116
116
  assert_instance_of(Array, out)
117
117
  assert_equal(3, out.size)
118
- assert_equal(1, out.select do |o|
118
+ assert_equal(1, out.count do |o|
119
119
  o[:value] == [[2, 10.0], [1, 11.0],
120
120
  [1, 12.0]]
121
- end.size)
122
- assert_equal(1, out.select { |o| o[:tags] == WH_TAGS }.size)
123
- assert_equal(3, out.select { |o| o[:path] == 'test.dist1' }.size)
121
+ end)
122
+ assert_equal(1, out.count { |o| o[:tags] == WH_TAGS })
123
+ assert_equal(3, out.count { |o| o[:path] == 'test.dist1' })
124
124
  end
125
125
 
126
126
  def test_flush_gauges
@@ -84,7 +84,7 @@ class WavefrontValidatorsTest < MiniTest::Test
84
84
  { tag1: 'val 1', tag2: 'val 2' },
85
85
  { TAG1: 'val 1', tag2: 'val 2' },
86
86
  { 'TAG-1': 'val 1', tag2: 'val 2' },
87
- { 'TAG_1': 'val 1', tag_2: 'val 2' },
87
+ { TAG_1: 'val 1', tag_2: 'val 2' },
88
88
  { 'TAG.1': 'val 1', tag_2: 'val 2' },
89
89
  { 'TAG-1': 'val 1', tag2: 'val 2' },
90
90
  { tag1: '(>_<)', tag2: '^_^' }]
@@ -42,5 +42,9 @@ class WavefrontWriterApiTest < MiniTest::Test
42
42
  assert_raises(Wavefront::Exception::CredentialError) do
43
43
  Wavefront::Write.new({ token: 'abcdef' }, writer: :api)
44
44
  end
45
+
46
+ assert_raises(Wavefront::Exception::CredentialError) do
47
+ Wavefront::Write.new({ token: 'abcdef', endpoint: nil }, writer: :api)
48
+ end
45
49
  end
46
50
  end
@@ -6,9 +6,7 @@ require_relative '../../spec_helper'
6
6
  require_relative '../../../lib/wavefront-sdk/writers/core'
7
7
  require_relative '../resources/dummy_points'
8
8
 
9
- # rubocop:disable Style/MutableConstant
10
- WBWT_CREDS = { endpoint: 'stub.wavefront.com', token: 'tkn' }
11
- # rubocop:enable Style/MutableConstant
9
+ WBWT_CREDS = { endpoint: 'stub.wavefront.com', token: 'tkn' }.freeze
12
10
 
13
11
  # Fake class for testing
14
12
  #
@@ -6,6 +6,7 @@ require_relative '../resources/dummy_points'
6
6
  require_relative '../../../lib/wavefront-sdk/write'
7
7
 
8
8
  BODY = 'test.metric 123456 1469987572 source=testhost t1="v1" t2="v2"'
9
+ WH_CREDS = { proxy: 'wavefront-proxy' }.freeze
9
10
 
10
11
  # Test HTTP transport
11
12
  #
@@ -20,27 +21,6 @@ class WavefrontWriterSocketTest < MiniTest::Test
20
21
  assert_instance_of(Wavefront::Writer::Http, wf.writer)
21
22
  end
22
23
 
23
- def test_validate_credentials
24
- assert Wavefront::Write.new({ proxy: 'wavefront' }, writer: :http)
25
- assert_instance_of(Wavefront::Write, wf)
26
-
27
- assert_raises(Wavefront::Exception::CredentialError) do
28
- Wavefront::Write.new(CREDS, writer: :http)
29
- end
30
-
31
- assert_raises(Wavefront::Exception::CredentialError) do
32
- Wavefront::Write.new({}, writer: :http)
33
- end
34
-
35
- assert_raises(Wavefront::Exception::CredentialError) do
36
- Wavefront::Write.new({ endpoint: 'wavefront.com' }, writer: :http)
37
- end
38
-
39
- assert_raises(Wavefront::Exception::CredentialError) do
40
- Wavefront::Write.new({ token: 'abcdef' }, writer: :http)
41
- end
42
- end
43
-
44
24
  def test_write_2878
45
25
  wf1 = Wavefront::Write.new({ proxy: 'wavefront' }, writer: :http)
46
26
 
@@ -67,4 +47,27 @@ class WavefrontWriterSocketTest < MiniTest::Test
67
47
  assert_requested(:post, 'http://wavefront:1234', headers: POST_HEADERS)
68
48
  WebMock.reset!
69
49
  end
50
+
51
+ def test_validate_credentials
52
+ assert(Wavefront::Write.new(WH_CREDS, writer: :http))
53
+
54
+ assert_instance_of(Wavefront::Write,
55
+ Wavefront::Write.new(WH_CREDS, writer: :http))
56
+
57
+ assert_raises(Wavefront::Exception::CredentialError) do
58
+ Wavefront::Write.new({}, writer: :http)
59
+ end
60
+
61
+ assert_raises(Wavefront::Exception::CredentialError) do
62
+ Wavefront::Write.new({ endpoint: 'wavefront.com' }, writer: :http)
63
+ end
64
+
65
+ assert_raises(Wavefront::Exception::CredentialError) do
66
+ Wavefront::Write.new({ token: 'abcdef' }, writer: :http)
67
+ end
68
+
69
+ assert_raises(Wavefront::Exception::CredentialError) do
70
+ Wavefront::Write.new({ proxy: nil }, writer: :http)
71
+ end
72
+ end
70
73
  end
@@ -6,17 +6,14 @@ require 'spy'
6
6
  require 'spy/integration'
7
7
  require 'socket'
8
8
  require 'logger'
9
+ require_relative '../resources/dummy_points'
9
10
  require_relative '../../spec_helper'
10
11
  require_relative '../../../lib/wavefront-sdk/write'
11
- require_relative '../resources/dummy_points'
12
+ require_relative '../../../spec/support/mocket'
12
13
 
13
- # rubocop:disable Style/MutableConstant
14
- WS_CREDS = { proxy: 'wavefront-proxy' }
15
- # rubocop:enable Style/MutableConstant
14
+ WS_CREDS = { proxy: 'wavefront-proxy' }.freeze
16
15
 
17
- # It's not straightforward to test the Writer::Socket class on its
18
- # own. It makes far more sense to test the Write interface which
19
- # calls it.
16
+ # The Socket class writes to a proxy
20
17
  #
21
18
  class WavefrontWriterSocketTest < MiniTest::Test
22
19
  attr_reader :wf, :wf_noop
@@ -106,4 +103,27 @@ class WavefrontWriterSocketTest < MiniTest::Test
106
103
  refute tcp_spy.has_been_called?
107
104
  refute log_spy.has_been_called?
108
105
  end
106
+
107
+ def test_validate_credentials
108
+ assert(Wavefront::Write.new(WS_CREDS, writer: :socket))
109
+
110
+ assert_instance_of(Wavefront::Write,
111
+ Wavefront::Write.new(WS_CREDS, writer: :socket))
112
+
113
+ assert_raises(Wavefront::Exception::CredentialError) do
114
+ Wavefront::Write.new({}, writer: :socket)
115
+ end
116
+
117
+ assert_raises(Wavefront::Exception::CredentialError) do
118
+ Wavefront::Write.new({ endpoint: 'wavefront.com' }, writer: :socket)
119
+ end
120
+
121
+ assert_raises(Wavefront::Exception::CredentialError) do
122
+ Wavefront::Write.new({ token: 'abcdef' }, writer: :socket)
123
+ end
124
+
125
+ assert_raises(Wavefront::Exception::CredentialError) do
126
+ Wavefront::Write.new({ proxy: nil }, writer: :socket)
127
+ end
128
+ end
109
129
  end
@@ -0,0 +1,131 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'webmock/minitest'
5
+ require 'spy'
6
+ require 'spy/integration'
7
+ require 'socket'
8
+ require 'logger'
9
+ require_relative '../resources/dummy_points'
10
+ require_relative '../../spec_helper'
11
+ require_relative '../../../lib/wavefront-sdk/write'
12
+ require_relative '../../../spec/support/mocket'
13
+
14
+ UNIX_SOCK = '/tmp/testsock'
15
+
16
+ WU_CREDS = { socket: UNIX_SOCK }.freeze
17
+
18
+ # Test UNIX Datagram socket writing
19
+ #
20
+ class WavefrontWriterUnixTest < MiniTest::Test
21
+ attr_reader :wf, :wf_noop
22
+
23
+ def setup
24
+ @wf = Wavefront::Write.new(WU_CREDS, writer: :unix)
25
+ @wf_noop = Wavefront::Write.new(WU_CREDS, writer: :unix, noop: true)
26
+ end
27
+
28
+ def test_writer_class
29
+ assert_instance_of(Wavefront::Writer::Unix, wf.writer)
30
+ end
31
+
32
+ def test_write_openclose
33
+ mocket = Mocket.new
34
+ Spy.on(UNIXSocket, :new).and_return(mocket)
35
+ mocket_spy = Spy.on(mocket, :write)
36
+ wf.write(POINT)
37
+ assert mocket_spy.has_been_called?
38
+ end
39
+
40
+ def test_write_noop
41
+ mocket = Mocket.new
42
+ Spy.on(UNIXSocket, :new).and_return(mocket)
43
+ mocket_spy = Spy.on(mocket, :write)
44
+ wf_noop.open
45
+ wf_noop.write(POINT, false)
46
+ refute mocket_spy.has_been_called?
47
+ end
48
+
49
+ def test_write_noop_openclose
50
+ mocket = Mocket.new
51
+ Spy.on(UNIXSocket, :new).and_return(mocket)
52
+ mocket_spy = Spy.on(mocket, :write)
53
+ wf_noop.write(POINT)
54
+ refute mocket_spy.has_been_called?
55
+ end
56
+
57
+ def test_write
58
+ mocket = Mocket.new
59
+ Spy.on(UNIXSocket, :new).and_return(mocket)
60
+ mocket_spy = Spy.on(mocket, :write)
61
+ wf.open
62
+ wf.write(POINT, false)
63
+ assert mocket_spy.has_been_called?
64
+ end
65
+
66
+ def test_write_array
67
+ mocket = Mocket.new
68
+ Spy.on(UNIXSocket, :new).and_return(mocket)
69
+ mocket_spy = Spy.on(mocket, :write)
70
+ wf.open
71
+ wf.write(POINT_A, false)
72
+ assert mocket_spy.has_been_called?
73
+ end
74
+
75
+ def test_noop_send_point
76
+ mocket = Mocket.new
77
+ Spy.on(UNIXSocket, :new).and_return(mocket)
78
+ mocket_spy = Spy.on(mocket, :write)
79
+ wf_noop.open
80
+ wf_noop.send_point(POINT_L)
81
+ refute mocket_spy.has_been_called?
82
+ end
83
+
84
+ def test_open
85
+ tcp_spy = Spy.on(UNIXSocket, :new)
86
+ wf.open
87
+ assert tcp_spy.has_been_called?
88
+ assert_equal([UNIX_SOCK], tcp_spy.calls.first.args)
89
+ end
90
+
91
+ def test_noop_open
92
+ tcp_spy = Spy.on(UNIXSocket, :new)
93
+ log_spy = Spy.on(wf_noop.logger, :log)
94
+ wf_noop.open
95
+ refute tcp_spy.has_been_called?
96
+ assert_equal(['No-op requested. Not opening socket connection.'],
97
+ log_spy.calls.last.args)
98
+ assert_equal(1, log_spy.calls.size)
99
+ end
100
+
101
+ def test_noop_close
102
+ tcp_spy = Spy.on(UNIXSocket, :new)
103
+ log_spy = Spy.on(wf_noop.logger, :log)
104
+ wf_noop.close
105
+ refute tcp_spy.has_been_called?
106
+ refute log_spy.has_been_called?
107
+ end
108
+
109
+ def test_validate_credentials
110
+ assert(Wavefront::Write.new(WU_CREDS, writer: :unix))
111
+
112
+ assert_instance_of(Wavefront::Write,
113
+ Wavefront::Write.new(WU_CREDS, writer: :unix))
114
+
115
+ assert_raises(Wavefront::Exception::CredentialError) do
116
+ Wavefront::Write.new({}, writer: :unix)
117
+ end
118
+
119
+ assert_raises(Wavefront::Exception::CredentialError) do
120
+ Wavefront::Write.new({ endpoint: 'wavefront.com' }, writer: :unix)
121
+ end
122
+
123
+ assert_raises(Wavefront::Exception::CredentialError) do
124
+ Wavefront::Write.new({ token: 'abcdef' }, writer: :unix)
125
+ end
126
+
127
+ assert_raises(Wavefront::Exception::CredentialError) do
128
+ Wavefront::Write.new({ proxy: nil }, writer: :unix)
129
+ end
130
+ end
131
+ end
@@ -29,7 +29,10 @@ Gem::Specification.new do |gem|
29
29
 
30
30
  gem.add_development_dependency 'minitest', '~> 5.14'
31
31
  gem.add_development_dependency 'rake', '~> 13.0'
32
- gem.add_development_dependency 'rubocop', '1.0'
32
+ gem.add_development_dependency 'rubocop', '~> 1.9'
33
+ gem.add_development_dependency 'rubocop-minitest', '~> 0.10'
34
+ gem.add_development_dependency 'rubocop-performance', '~> 1.3'
35
+ gem.add_development_dependency 'rubocop-rake', '~> 0.5'
33
36
  gem.add_development_dependency 'simplecov', '~> 0.18'
34
37
  gem.add_development_dependency 'spy', '1.0.0'
35
38
  gem.add_development_dependency 'webmock', '~> 3.9'
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: 5.4.3
4
+ version: 5.4.4
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-01-28 00:00:00.000000000 Z
11
+ date: 2021-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -98,16 +98,58 @@ dependencies:
98
98
  name: rubocop
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - '='
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '1.0'
103
+ version: '1.9'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - '='
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.9'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop-minitest
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.10'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.10'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop-performance
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1.3'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '1.3'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop-rake
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '0.5'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
109
151
  - !ruby/object:Gem::Version
110
- version: '1.0'
152
+ version: '0.5'
111
153
  - !ruby/object:Gem::Dependency
112
154
  name: simplecov
113
155
  requirement: !ruby/object:Gem::Requirement
@@ -175,7 +217,6 @@ files:
175
217
  - ".github/workflows/test.yml"
176
218
  - ".gitignore"
177
219
  - ".rubocop.yml"
178
- - ".travis.yml"
179
220
  - Gemfile
180
221
  - HISTORY.md
181
222
  - LICENSE.txt
@@ -318,6 +359,7 @@ files:
318
359
  - spec/wavefront-sdk/writers/http_spec.rb
319
360
  - spec/wavefront-sdk/writers/socket_spec.rb
320
361
  - spec/wavefront-sdk/writers/summary_spec.rb
362
+ - spec/wavefront-sdk/writers/unix_spec.rb
321
363
  - wavefront-sdk.gemspec
322
364
  homepage: https://github.com/snltd/wavefront-sdk
323
365
  licenses:
@@ -415,3 +457,4 @@ test_files:
415
457
  - spec/wavefront-sdk/writers/http_spec.rb
416
458
  - spec/wavefront-sdk/writers/socket_spec.rb
417
459
  - spec/wavefront-sdk/writers/summary_spec.rb
460
+ - spec/wavefront-sdk/writers/unix_spec.rb
data/.travis.yml DELETED
@@ -1,21 +0,0 @@
1
- language: ruby
2
- cache: bundler
3
- rvm:
4
- - 2.4.9
5
- - 2.5.8
6
- - 2.6.6
7
- - 2.7.2
8
- before_install: gem install bundler --no-document
9
- deploy:
10
- provider: rubygems
11
- api_key:
12
- secure: dfmL5JwBn+u3cUmyAaDsApDa7ljGajGNz3GDcKd2J8FOt7+a758/lmL8EQ34sDT1ZFotrxn/y1RbgXlaDxAE1XDfrZbjckmx7a6wa2sqR3kBraJ2tx7CiXodbw3Z8XZf9WLb0kYGmlLtI73GNcuunMt/9f1cobqWISRLHw6b7amlO7GW2ZBZgzRS+N8TSS2dicIvKMo5HoMYU+uWLM4zDFBPnGNcMiWxh8ysLzJoKqA9kbBUyCVEZ03MlV7G71ObvWCLasKnZ3W5U+K1NbgU7mgMYfl9KIcA4y9hQ9hUCijk40SmT7ffy3P2gq8zblC/4x5Eefpau9X/bdLwXoRCIzqk05t4f45wstj2auHGK0HJwOYRtx8apdaLSgyJ5lQpGcbCRu40WR9mDkaM8m9n3u2o6GJmftCg3AN1QtsourmQB84x67LEbHzValMaokrbCol4XeWqlC+dCNLPixemQRBvcNfI3V9C6RqVGfjpoGlSTI+RkQqwm01PcxpeqIVfdMd1wnfUuAOywUO6UpvtK9TZaxg0NnVElXpPseQbtzulLwZ7R5Y3A4Ss8Z7w43c1KHxTkg54FWUOp065ItjAc4lmyORXq/2+F7sMvRN6dtCLaXTUlkYuU3cjFLIPlLGFYgqq4T4xQa+e5NEK1XW7nghv+IRfKfyVeZsB0WpY+uc=
13
- gem: wavefront-sdk
14
- on:
15
- tags: true
16
- repo: snltd/wavefront-sdk
17
- ruby: 2.6.6
18
- notifications:
19
- email: false
20
- slack:
21
- secure: cTG5e5NsnfZCNF6mUbnz8rdxmiPvrihJJN/7vEltO6rSCR4ew+9dfga9n7N5wCu7nae3lEysbRw7vPw605VVkZrfA4gn+HUsoHbKzaKNOB6AV9a8kkbjC4y6MH7EWSD2qsUWeeINP7dNs80cqvEwU2tgtIiBWNAP+e/eCjTEQCq4UIXnEB0f0UIP4bvl3w7/fSd0iFykBiVTiXvGBWKkqbetSAcAvsV5wxbPGqrhBp5AQQ9izm0Uh/P/hv8gaqMariFYA6rIpunWmwxPCHf3B87CTdl6T8uC5bi4bfgb3mFbQUiP9TTblz2XTI3Q9tRDbcFcr4BGpjB1Lyfdy1puRi3QzP5VME5AXvDTr9GVgi9TS6EWqy7P4HC//qZziWllTLlst6R9r/NlagTsiDB/mcnxkJBvOBYAvmzXS5ID6DfNxx/xCfCZuQzp5ISoWawGCvuGHBSOlzZZXKD4AAT8/69SIVybM23Hj/YBPKVvR9brpCmIlK4YXi14SA5sInjD4zn20u/p22vlEybjlnM8td7ryuhmCYm1ptk8y0tZ4oRoK2fBNo2VTD73aXq6P2q3AKuT6A9hRbypEJgawNgOAKJEWDHdu29LfeJIUnm25MzaFzx145it2hDU2/hOUlpFq9QKsmR2pAiI17sAMgHJ15cgaeOv1soWaYJsMOZil74=