signalfx 2.0.3 → 3.1.0

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
- SHA1:
3
- metadata.gz: 02ff8227fddf6b0eafc8e327ad06edebd72b17c5
4
- data.tar.gz: 445cc12623762e477d26ae56349b6ff650781def
2
+ SHA256:
3
+ metadata.gz: ecf79d2352800c32de61e1b0b873f9641c9b34ac03736895b7c0018b23dcaddb
4
+ data.tar.gz: 07423e7f0e61326c1fef4cacd5d019ac686f96d81c967045363b9449c4ef2479
5
5
  SHA512:
6
- metadata.gz: 11f87025f8f3599c80f5eb5b86273b55287bb1d0c5eccb09a28441c49bf81fa63f3f653185f772e95b561a77a9e1dfdb9942def521831444a4ace4d4886a125c
7
- data.tar.gz: 13925b3568a355c95ddfe9597cb5a6a15e2ea5e546979e330e4a4668fd3b9eb8f59bbff099dccf4dce30dfdbdbc2cc878202f87a6a2fa4c42c508e0260e22891
6
+ metadata.gz: '035494c0490ef9457eee5f2d77cc6ee12ad5054543fa6a906ebd2bc1ebe4dab4d7e982d937d0b53da5b1791e183ccb5d1a5317843589690d705f096a6ef188c6'
7
+ data.tar.gz: 11c7cc82509d5deaa788f2729220a5515583b5f13cf9a4ea1e66e6cd150eb4c9312e726851ea876ff1315f2290c31f026ef976bf42d3b02818b9a875913b5535
@@ -1,6 +1,14 @@
1
- sudo: required
2
1
  language: ruby
3
- dist: trusty
2
+ dist: xenial
3
+ os: linux
4
+
5
+ # See: https://docs.travis-ci.com/user/languages/ruby/#bundler-20
6
+ before_install:
7
+ - gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
8
+ - gem install bundler -v '< 2'
4
9
 
5
10
  rvm:
6
11
  - 2.2.3
12
+ - 2.3
13
+ - 2.4
14
+ - 2.5
@@ -1,48 +1,52 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- signalfx (2.0.3)
4
+ signalfx (3.1.0)
5
+ activesupport (>= 3.2, < 6)
6
+ faye-websocket (>= 0.10.7, < 0.12.0)
7
+ i18n (= 1.1.0)
5
8
  protobuf (>= 3.5.1)
6
9
  rest-client (~> 2.0)
7
- websocket-client-simple (~> 0.3.0)
10
+ thor (= 0.20.0)
8
11
 
9
12
  GEM
10
13
  remote: https://rubygems.org/
11
14
  specs:
12
- activesupport (5.1.5)
15
+ activesupport (5.2.4.3)
13
16
  concurrent-ruby (~> 1.0, >= 1.0.2)
14
- i18n (~> 0.7)
17
+ i18n (>= 0.7, < 2)
15
18
  minitest (~> 5.1)
16
19
  tzinfo (~> 1.1)
17
- addressable (2.4.0)
20
+ addressable (2.5.2)
21
+ public_suffix (>= 2.0.2, < 4.0)
18
22
  coderay (1.1.1)
19
- concurrent-ruby (1.0.5)
23
+ concurrent-ruby (1.1.7)
20
24
  crack (0.4.3)
21
25
  safe_yaml (~> 1.0.0)
22
26
  daemons (1.2.4)
23
- diff-lcs (1.2.5)
24
- docile (1.1.5)
25
- domain_name (0.5.20170404)
27
+ diff-lcs (1.3)
28
+ docile (1.3.1)
29
+ domain_name (0.5.20190701)
26
30
  unf (>= 0.0.5, < 1.0.0)
27
- event_emitter (0.2.6)
28
- eventmachine (1.2.5)
29
- faye-websocket (0.10.7)
31
+ eventmachine (1.2.7)
32
+ faye-websocket (0.11.0)
30
33
  eventmachine (>= 0.12.0)
31
34
  websocket-driver (>= 0.5.1)
32
- hashdiff (0.3.0)
35
+ hashdiff (0.3.7)
36
+ http-accept (1.7.0)
33
37
  http-cookie (1.0.3)
34
38
  domain_name (~> 0.5)
35
- i18n (0.9.5)
39
+ i18n (1.1.0)
36
40
  concurrent-ruby (~> 1.0)
37
- json (1.8.6)
41
+ json (2.1.0)
38
42
  method_source (0.8.2)
39
43
  middleware (0.1.0)
40
- mime-types (3.1)
44
+ mime-types (3.3.1)
41
45
  mime-types-data (~> 3.2015)
42
- mime-types-data (3.2016.0521)
43
- minitest (5.11.3)
46
+ mime-types-data (3.2020.0512)
47
+ minitest (5.14.2)
44
48
  netrc (0.11.0)
45
- protobuf (3.8.1)
49
+ protobuf (3.10.3)
46
50
  activesupport (>= 3.2)
47
51
  middleware
48
52
  thor
@@ -51,31 +55,33 @@ GEM
51
55
  coderay (~> 1.1.0)
52
56
  method_source (~> 0.8.1)
53
57
  slop (~> 3.4)
58
+ public_suffix (3.0.2)
54
59
  rack (2.0.3)
55
60
  rake (10.4.2)
56
- rest-client (2.0.2)
61
+ rest-client (2.1.0)
62
+ http-accept (>= 1.7.0, < 2.0)
57
63
  http-cookie (>= 1.0.2, < 2.0)
58
64
  mime-types (>= 1.16, < 4.0)
59
65
  netrc (~> 0.8)
60
- rspec (3.3.0)
61
- rspec-core (~> 3.3.0)
62
- rspec-expectations (~> 3.3.0)
63
- rspec-mocks (~> 3.3.0)
64
- rspec-core (3.3.2)
65
- rspec-support (~> 3.3.0)
66
- rspec-expectations (3.3.1)
66
+ rspec (3.9.0)
67
+ rspec-core (~> 3.9.0)
68
+ rspec-expectations (~> 3.9.0)
69
+ rspec-mocks (~> 3.9.0)
70
+ rspec-core (3.9.0)
71
+ rspec-support (~> 3.9.0)
72
+ rspec-expectations (3.9.0)
67
73
  diff-lcs (>= 1.2.0, < 2.0)
68
- rspec-support (~> 3.3.0)
69
- rspec-mocks (3.3.2)
74
+ rspec-support (~> 3.9.0)
75
+ rspec-mocks (3.9.0)
70
76
  diff-lcs (>= 1.2.0, < 2.0)
71
- rspec-support (~> 3.3.0)
72
- rspec-support (3.3.0)
77
+ rspec-support (~> 3.9.0)
78
+ rspec-support (3.9.0)
73
79
  safe_yaml (1.0.4)
74
- simplecov (0.10.0)
75
- docile (~> 1.1.0)
76
- json (~> 1.8)
80
+ simplecov (0.16.1)
81
+ docile (~> 1.1)
82
+ json (>= 1.8, < 3)
77
83
  simplecov-html (~> 0.10.0)
78
- simplecov-html (0.10.0)
84
+ simplecov-html (0.10.2)
79
85
  slop (3.6.0)
80
86
  thin (1.7.2)
81
87
  daemons (~> 1.0, >= 1.0.9)
@@ -83,36 +89,31 @@ GEM
83
89
  rack (>= 1, < 3)
84
90
  thor (0.20.0)
85
91
  thread_safe (0.3.6)
86
- tzinfo (1.2.5)
92
+ tzinfo (1.2.7)
87
93
  thread_safe (~> 0.1)
88
94
  unf (0.1.4)
89
95
  unf_ext
90
- unf_ext (0.0.7.5)
91
- webmock (2.1.0)
96
+ unf_ext (0.0.7.7)
97
+ webmock (2.3.2)
92
98
  addressable (>= 2.3.6)
93
99
  crack (>= 0.3.2)
94
100
  hashdiff
95
- websocket (1.2.5)
96
- websocket-client-simple (0.3.0)
97
- event_emitter
98
- websocket
99
- websocket-driver (0.6.5)
101
+ websocket-driver (0.7.3)
100
102
  websocket-extensions (>= 0.1.0)
101
- websocket-extensions (0.1.2)
103
+ websocket-extensions (0.1.5)
102
104
 
103
105
  PLATFORMS
104
106
  ruby
105
107
 
106
108
  DEPENDENCIES
107
- bundler (~> 1.10)
108
- faye-websocket (~> 0.10.7)
109
+ bundler (~> 1.17.3)
109
110
  pry
110
111
  rake (~> 10.0)
111
112
  rspec (~> 3.3)
112
113
  signalfx!
113
114
  simplecov
114
115
  thin (~> 1.7)
115
- webmock (~> 2.1)
116
+ webmock (~> 2.3.1)
116
117
 
117
118
  BUNDLED WITH
118
- 1.16.1
119
+ 1.17.3
data/README.md CHANGED
@@ -21,11 +21,43 @@ Or install it yourself as:
21
21
 
22
22
  $ gem install signalfx
23
23
 
24
+ #### Installing with Ruby 2.2.0 and 2.2.1
25
+
26
+ This library's protobuf dependency requires activesupport >=3.2. 5.x versions of activesupport require Ruby >=2.2.2,
27
+ so users of older Ruby versions will need to install activesupport 4.2.10 before signalfx to avoid attempts of
28
+ installing a more recent gem. Building and installing signalfx from source will fulfill this for you:
29
+
30
+ $ gem build signalfx.gemspec && gem install signalfx-<current_version>.gem
31
+
24
32
  ## Usage
25
33
 
26
- ### API access token
27
34
 
28
- To use this library, you need a SignalFx API access token, which can be obtained from the SignalFx organization you want to report data into.
35
+ ### Configuring your endpoints
36
+
37
+ In order to send your data to the correct realm, you may need to configure your
38
+ endpoints. If no endpoints are set manually, this library uses the ``us0`` realm by default.
39
+ If you are not in this realm, you will need to explicitly set the
40
+ endpoint config options below. To determine if you are in a different realm and need to
41
+ explicitly set the endpoints, check your profile page in the SignalFx
42
+ web application.
43
+
44
+ ```ruby
45
+ require('signalfx')
46
+ # Create client with alternate ingest endpoint
47
+ client = SignalFx.new('ORG_TOKEN', ingest_endpoint: 'https://ingest.{REALM}.signalfx.com',
48
+ stream_endpoint: 'https:/stream.{REALM}.signalfx.com')
49
+
50
+ ```
51
+
52
+ ### Access tokens
53
+
54
+ To use this library, you will also need to specify an access token when requesting
55
+ one of those clients. For the ingest client, you need to specify your
56
+ organization access token (which can be obtained from the
57
+ SignalFx organization you want to report data into). For the SignalFlow client, either an
58
+ organization access token or a user access token may be used. For more
59
+ information on access tokens, see the API's [authentication documentation](https://developers.signalfx.com/basics/authentication.html).
60
+
29
61
 
30
62
  ### Create client
31
63
 
@@ -34,7 +66,7 @@ The default constructor `SignalFx` uses Protobuf to send data to SignalFx. If it
34
66
  ```ruby
35
67
  require('signalfx')
36
68
 
37
- // Create client
69
+ # Create client
38
70
  client = SignalFx.new 'MY_SIGNALFX_TOKEN'
39
71
  ```
40
72
 
@@ -47,7 +79,7 @@ Optional constructor parameters:
47
79
  deployed on Amazon AWS.
48
80
  + **ingest_endpoint** (string): to override the target ingest API
49
81
  endpoint.
50
- + **api_endpoint** (string): to override the target REST API endpoint.
82
+ + **stream_endpoint** (string): to override the target stream endpoint for SignalFlow.
51
83
  + **timeout** (number): timeout, in seconds, for requests to SignalFx.
52
84
  + **batch_size** (number): size of datapoint batches to send to
53
85
  SignalFx.
@@ -92,6 +124,16 @@ datapoints will not accurately represent the time of their measurement
92
124
  (network latency, batching, etc. will all impact when those datapoints
93
125
  actually make it to SignalFx).
94
126
 
127
+ #### Reporting data through a HTTP proxy
128
+
129
+ To send data through a HTTP proxy, set the environment variable `http_proxy`
130
+ with the proxy URL.
131
+
132
+ The SignalFlow client by default will use the proxy set in the `http_proxy`
133
+ envvar by default. To send SignalFlow websocket data through a separate proxy,
134
+ set the `proxy_url` keyword arg on the `client.signalflow` call.
135
+
136
+
95
137
  ### Sending multi-dimensional data
96
138
 
97
139
  Reporting dimensions for the data is also optional, and can be
@@ -161,9 +203,23 @@ sending events.
161
203
 
162
204
  You can run SignalFlow computations as well. This library supports all of the
163
205
  functionality described in our [API docs for
164
- SignalFlow](https://developers.signalfx.com/reference#signalflowconnect). Right
206
+ SignalFlow](https://developers.signalfx.com/signalflow_reference.html). Right
165
207
  now, the only supported transport mechanism is WebSockets.
166
208
 
209
+ #### Configure the SignalFlow client endpoint
210
+
211
+ By default, this library connects to the `us0` stream endpoint.
212
+ If you are not in this realm, you will need to explicitly set the
213
+ endpoint config options below when creating the client.
214
+ To determine if you are in a different realm and need to
215
+ explicitly set the endpoints, check your profile page in the SignalFx web application.
216
+
217
+ ```ruby
218
+ client = SignalFx.new('ORG_TOKEN', ingest_endpoint: 'https://ingest.{REALM}.signalfx.com',
219
+ stream_endpoint: 'https:/stream.{REALM}.signalfx.com')
220
+ ```
221
+
222
+
167
223
  To create a new SignalFlow client instance from an existing SignalFx client:
168
224
 
169
225
  ```ruby
@@ -16,31 +16,35 @@ module SignalFx
16
16
  # and set it as `AWSUniqueId` dimension for each datapoint and event.
17
17
  # Use this option only if your application deployed to Amazon
18
18
  # @param ingest_endpoint - string
19
- # @param api_endpoint - string
19
+ # @param stream_endpoint - string
20
20
  # @param timeout - number
21
21
  # @param batch_size - number
22
22
  # @param user_agents - array
23
23
  def self.new(api_token,
24
24
  enable_aws_unique_id: false,
25
25
  ingest_endpoint: RbConfig::DEFAULT_INGEST_ENDPOINT,
26
+ stream_endpoint: RbConfig::DEFAULT_STREAM_ENDPOINT,
26
27
  timeout: RbConfig::DEFAULT_TIMEOUT,
27
28
  batch_size: RbConfig::DEFAULT_BATCH_SIZE,
28
- user_agents: [])
29
+ user_agents: [],
30
+ logger: Logger.new(STDOUT, progname: "signalfx"))
29
31
  begin
30
32
  require_relative './proto/signal_fx_protocol_buffers.pb'
31
33
  ProtoBufSignalFx.new(api_token,
32
34
  enable_aws_unique_id: enable_aws_unique_id,
33
35
  ingest_endpoint: ingest_endpoint,
36
+ stream_endpoint: stream_endpoint,
34
37
  timeout: timeout,
35
38
  batch_size: batch_size,
36
39
  user_agents: user_agents)
37
40
 
38
41
  rescue Exception => e
39
- puts "Protocol Buffers not installed properly. Switching to JSON.
40
- #{e}"
42
+ logger.warn("Protocol Buffers not installed properly. Switching to JSON.
43
+ #{e}")
41
44
  JsonSignalFx.new(api_token,
42
45
  enable_aws_unique_id: enable_aws_unique_id,
43
46
  ingest_endpoint: ingest_endpoint,
47
+ stream_endpoint: stream_endpoint,
44
48
  timeout: timeout,
45
49
  batch_size: batch_size,
46
50
  user_agents: user_agents)
@@ -25,7 +25,7 @@ class ProtoBufSignalFx < SignalFxClient
25
25
  if datapoint_value.kind_of?(Float)
26
26
  protobuf_datapoint.value = Com::Signalfx::Metrics::Protobuf::Datum.new :doubleValue => datapoint_value
27
27
  else
28
- if datapoint_value.kind_of?(Fixnum)
28
+ if datapoint_value.kind_of?(Integer)
29
29
  protobuf_datapoint.value = Com::Signalfx::Metrics::Protobuf::Datum.new :intValue => datapoint_value
30
30
  else
31
31
  throw TypeError('Invalid Value ' + datapoint_value);
@@ -96,7 +96,7 @@ class ProtoBufSignalFx < SignalFxClient
96
96
  if prop_value.kind_of?(Float)
97
97
  property.value = Com::Signalfx::Metrics::Protobuf::PropertyValue.new :doubleValue => prop_value
98
98
  else
99
- if prop_value.kind_of?(Fixnum)
99
+ if prop_value.kind_of?(Integer)
100
100
  property.value = Com::Signalfx::Metrics::Protobuf::PropertyValue.new :intValue => prop_value
101
101
  else
102
102
  throw TypeError('Invalid Value ' + prop_value);
@@ -31,19 +31,19 @@ class SignalFxClient
31
31
  def initialize(api_token,
32
32
  enable_aws_unique_id: false,
33
33
  ingest_endpoint: RbConfig::DEFAULT_INGEST_ENDPOINT,
34
- api_endpoint: RbConfig::DEFAULT_API_ENDPOINT,
35
34
  stream_endpoint: RbConfig::DEFAULT_STREAM_ENDPOINT,
36
35
  timeout: RbConfig::DEFAULT_TIMEOUT,
37
36
  batch_size: RbConfig::DEFAULT_BATCH_SIZE,
38
- user_agents: [])
37
+ user_agents: [],
38
+ logger: Logger.new(STDOUT, progname: "signalfx"))
39
39
 
40
40
  @api_token = api_token
41
41
  @ingest_endpoint = ingest_endpoint
42
- @api_endpoint = api_endpoint
43
42
  @stream_endpoint = stream_endpoint
44
43
  @timeout = timeout
45
44
  @batch_size = batch_size
46
45
  @user_agents = user_agents
46
+ @logger = logger
47
47
 
48
48
  @aws_unique_id = nil
49
49
 
@@ -55,9 +55,9 @@ class SignalFxClient
55
55
  if request != nil
56
56
  json_resp = JSON.parse(request.body)
57
57
  @aws_unique_id = json_resp['instanceId']+'_'+json_resp['region']+'_'+json_resp['accountId']
58
- puts("AWS Unique ID loaded: #{@aws_unique_id}")
58
+ @logger.info("AWS Unique ID loaded: #{@aws_unique_id}")
59
59
  else
60
- puts('Failed to retrieve AWS unique ID.')
60
+ @logger.warn('Failed to retrieve AWS unique ID.')
61
61
  end
62
62
  }
63
63
  end
@@ -171,8 +171,11 @@ class SignalFxClient
171
171
  #
172
172
  # @return [SignalFlowClient] a newly instantiated client, configured with the
173
173
  # api token and endpoints from this class
174
- def signalflow
175
- SignalFlowClient.new(@api_token, @api_endpoint, @stream_endpoint)
174
+ def signalflow(proxy_url: nil, debug: false)
175
+ if ENV["http_proxy"] and proxy_url == nil
176
+ proxy_url = ENV["http_proxy"]
177
+ end
178
+ SignalFlowClient.new(@api_token, @stream_endpoint, proxy_url: proxy_url, debug: debug)
176
179
  end
177
180
 
178
181
  protected
@@ -208,7 +211,7 @@ class SignalFxClient
208
211
 
209
212
  headers = {HEADER_CONTENT_TYPE => header_content_type,
210
213
  HEADER_API_TOKEN_KEY => @api_token,
211
- HEADER_USER_AGENT_KEY => Version::NAME + '/' + Version::VERSION + http_user_agents}
214
+ HEADER_USER_AGENT_KEY => SignalFx::Version::NAME + '/' + SignalFx::Version::VERSION + http_user_agents}
212
215
 
213
216
  RestClient::Request.execute(
214
217
  method: :post,
@@ -223,14 +226,14 @@ class SignalFxClient
223
226
  block.call(response)
224
227
  end
225
228
  else
226
- puts "Failed to send datapoints. Response code: #{response.code}"
229
+ @logger.error("Failed to send datapoints. Response code: #{response.code}")
227
230
  if block
228
231
  block.call(nil)
229
232
  end
230
233
  end
231
234
  }
232
235
  rescue Exception => e
233
- puts "Failed to send datapoints. Error: #{e}"
236
+ @logger.error("Failed to send datapoints. Error: #{e}")
234
237
  if block
235
238
  block.call(nil)
236
239
  end
@@ -246,12 +249,12 @@ class SignalFxClient
246
249
  when 200
247
250
  return block.call(response)
248
251
  else
249
- puts "Failed to retrieve AWS unique ID. Response code: #{response.code}"
252
+ @logger.warn("Failed to retrieve AWS unique ID. Response code: #{response.code}")
250
253
  return block.call(nil)
251
254
  end
252
255
  }
253
256
  rescue Exception => e
254
- puts "Failed to retrieve AWS unique ID. Error: #{e}"
257
+ @logger.warn("Failed to retrieve AWS unique ID. Error: #{e}")
255
258
  block.call(nil)
256
259
  end
257
260
  end
@@ -19,8 +19,8 @@ require_relative "./websocket"
19
19
  # our API reference for SignalFlow}. Hash keys will be symbols instead of
20
20
  # strings.
21
21
  class SignalFlowClient
22
- def initialize(api_token, api_endpoint, stream_endpoint)
23
- @transport = SignalFlowWebsocketTransport.new(api_token, stream_endpoint)
22
+ def initialize(api_token, stream_endpoint, proxy_url = nil)
23
+ @transport = SignalFlowWebsocketTransport.new(api_token, stream_endpoint, proxy_url)
24
24
  end
25
25
 
26
26
  # Start a computation and attach to its output. If using WebSockets (the
@@ -29,10 +29,10 @@ class SignalFlowClient
29
29
  #
30
30
  # See https://developers.signalfx.com/reference#section-execute-a-computation
31
31
  #
32
- # @option options [Fixnum] :start
33
- # @option options [Fixnum] :stop
34
- # @option options [Fixnum] :resolution
35
- # @option options [Fixnum] :max_delay
32
+ # @option options [Integer] :start
33
+ # @option options [Integer] :stop
34
+ # @option options [Integer] :resolution
35
+ # @option options [Integer] :max_delay
36
36
  # @option options [Boolean] :persistent
37
37
  # @option options [Boolean] :immediate
38
38
  #
@@ -46,9 +46,9 @@ class SignalFlowClient
46
46
  #
47
47
  # See https://developers.signalfx.com/v2/reference#signalflowpreflight
48
48
  #
49
- # @param start [Fixnum]
50
- # @param stop [Fixnum]
51
- # @option options [Fixnum] :max_delay
49
+ # @param start [Integer]
50
+ # @param stop [Integer]
51
+ # @option options [Integer] :max_delay
52
52
  #
53
53
  # @return [Computation] A {Computation} instance with an active channel
54
54
  def preflight(program, start, stop, **options)
@@ -2,12 +2,18 @@
2
2
 
3
3
  require 'json'
4
4
  require 'thread'
5
- require 'websocket-client-simple'
5
+ require 'faye/websocket'
6
6
 
7
7
  require_relative './binary'
8
8
  require_relative './channel'
9
9
  require_relative './computation'
10
10
 
11
+ class WebsocketError < StandardError
12
+ def initialize(ws_err)
13
+ super ws_err.message
14
+ end
15
+ end
16
+
11
17
 
12
18
  # A WebSocket transport for SignalFlow. This should not be used directly by
13
19
  # end-users.
@@ -17,13 +23,17 @@ class SignalFlowWebsocketTransport
17
23
  # A lower bound on the amount of time to wait for a computation to start
18
24
  COMPUTATION_START_TIMEOUT_SECONDS = 30
19
25
 
20
- def initialize(api_token, stream_endpoint)
26
+ def initialize(api_token, stream_endpoint, proxy_url: nil, logger: Logger.new(STDOUT, progname: "signalfx"), debug: false)
21
27
  @api_token = api_token
22
28
  @stream_endpoint = stream_endpoint
29
+ @logger = logger
23
30
  @compress = true
31
+ @proxy_url = proxy_url
32
+ @debug = debug
24
33
 
25
34
  @lock = Mutex.new
26
35
  @close_reason = nil
36
+ @last_error = nil
27
37
  reinit
28
38
  end
29
39
 
@@ -187,6 +197,9 @@ class SignalFlowWebsocketTransport
187
197
  # The socket will be closed by the server if auth isn't successful
188
198
  # within 5 seconds so no point in waiting longer
189
199
  if Time.now - start_time > 5 || @close_reason
200
+ if @last_error
201
+ raise WebsocketError.new(@last_error)
202
+ end
190
203
  raise "Could not authenticate to SignalFlow WebSocket: #{@close_reason}"
191
204
  end
192
205
  sleep 0.1
@@ -199,7 +212,11 @@ class SignalFlowWebsocketTransport
199
212
  private :send_msg
200
213
 
201
214
  def on_close(msg)
202
- @close_reason = "(#{msg.code}, #{msg.data})"
215
+ if @debug
216
+ @logger.info("Websocket on_close: #{msg}")
217
+ end
218
+
219
+ @close_reason = "(#{msg.code}, #{msg.reason})"
203
220
  @chan_callbacks.keys.each do |channel_name|
204
221
  invoke_callback_for_channel({ :event => "CONNECTION_CLOSED" }, channel_name)
205
222
  end
@@ -207,21 +224,31 @@ class SignalFlowWebsocketTransport
207
224
  reinit
208
225
  end
209
226
 
227
+ def on_error(e)
228
+ @logger.error("ERROR #{e.inspect}")
229
+ @last_error = e
230
+ end
231
+
232
+
210
233
  def on_message(m)
211
- begin
212
- return if m.type == :ping
213
- if m.type == :close
214
- on_close(m)
215
- return
216
- end
234
+ if @debug
235
+ @logger.info("Websocket on_message: #{m}")
236
+ end
217
237
 
218
- message_received(m.data, m.type == :text)
238
+ is_text = m.data.kind_of?(String)
239
+
240
+ begin
241
+ message_received(m.data, is_text)
219
242
  rescue Exception => e
220
- puts "Error processing SignalFlow message: #{e.backtrace.first}: #{e.message} (#{e.class})"
243
+ @logger.error("Error processing SignalFlow message: #{e.backtrace.first}: #{e.message} (#{e.class})")
221
244
  end
222
245
  end
223
246
 
224
247
  def on_open
248
+ if @debug
249
+ @logger.info("Websocket on_open")
250
+ end
251
+
225
252
  @ws.send({
226
253
  :type => "authenticate",
227
254
  :token => @api_token,
@@ -232,26 +259,38 @@ class SignalFlowWebsocketTransport
232
259
  # reactor.
233
260
  def startup_client
234
261
  this = self
235
- WebSocket::Client::Simple.connect("#{@stream_endpoint}/v2/signalflow/connect",
236
- # Verification is disabled by default so this is essential
237
- {verify_mode: OpenSSL::SSL::VERIFY_PEER}) do |ws|
238
- @ws = ws
239
- ws.on :error do |e|
240
- puts "ERROR #{e.inspect}"
241
- end
242
262
 
243
- ws.on :close do |e|
244
- this.on_close(e)
245
- end
263
+ options = {
264
+ :tls => {
265
+ :verify_peer => true,
266
+ }
267
+ }
268
+ if @proxy_url
269
+ options[:proxy] = {
270
+ :origin => @proxy_url,
271
+ }
272
+ end
273
+ Thread.new {
274
+ EM.run {
275
+ @ws = Faye::WebSocket::Client.new("#{@stream_endpoint}/v2/signalflow/connect", [], options)
276
+ @ws.on :error do |e|
277
+ this.on_error(e)
278
+ end
246
279
 
247
- ws.on :message do |m|
248
- this.on_message(m)
249
- end
280
+ @ws.on :close do |e|
281
+ this.on_close(e)
282
+ EM.stop_event_loop
283
+ end
250
284
 
251
- ws.on :open do
252
- this.on_open
253
- end
254
- end
285
+ @ws.on :message do |m|
286
+ this.on_message(m)
287
+ end
288
+
289
+ @ws.on :open do
290
+ this.on_open
291
+ end
292
+ }
293
+ }
255
294
  end
256
295
  private :startup_client
257
296
 
@@ -293,7 +332,8 @@ class SignalFlowWebsocketTransport
293
332
  if is_text
294
333
  JSON.parse(raw_msg, {:symbolize_names => true})
295
334
  else
296
- BinaryMessageParser.parse(raw_msg)
335
+ # Convert the byte array to a string
336
+ BinaryMessageParser.parse(raw_msg.pack("c*"))
297
337
  end
298
338
  end
299
339
  private :parse_message
@@ -1,6 +1,8 @@
1
- # Copyright (C) 2015-2016 SignalFx, Inc. All rights reserved.
1
+ # Copyright (C) 2015-2020 SignalFx, Inc. All rights reserved.
2
2
 
3
- module Version
4
- VERSION = '2.0.3'
5
- NAME = 'signalfx-ruby-client'
3
+ module SignalFx
4
+ module Version
5
+ VERSION = '3.1.0'
6
+ NAME = 'signalfx-ruby-client'
7
+ end
6
8
  end
@@ -5,7 +5,7 @@ require_relative 'lib/signalfx/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "signalfx"
8
- spec.version = Version::VERSION
8
+ spec.version = SignalFx::Version::VERSION
9
9
  spec.authors = ["SignalFx, Inc"]
10
10
  spec.email = ["info@signalfx.com"]
11
11
 
@@ -29,14 +29,22 @@ Gem::Specification.new do |spec|
29
29
 
30
30
  spec.required_ruby_version = '>= 2.2.0'
31
31
 
32
- spec.add_development_dependency "bundler", "~> 1.10"
32
+ spec.add_development_dependency "bundler", "~> 1.17.3"
33
33
  spec.add_development_dependency "rake", "~> 10.0"
34
34
  spec.add_development_dependency "rspec", "~> 3.3"
35
- spec.add_development_dependency "webmock", "~> 2.1"
35
+ spec.add_development_dependency "webmock", "~> 2.3.1"
36
36
  spec.add_development_dependency "thin", "~> 1.7"
37
37
  spec.add_development_dependency "pry"
38
- spec.add_development_dependency "faye-websocket", "~> 0.10.7"
38
+
39
+ # protobuf enforces this check but builds with a newer Ruby version so it's not enabled.
40
+ # Incorporating here to allow 2.2.0-1 users to successfully build and install signalfx.
41
+ active_support_max_version = Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.2.2") ? "<5" : "<6"
42
+ spec.add_dependency "activesupport", '>= 3.2', active_support_max_version
43
+
39
44
  spec.add_dependency "protobuf", ">= 3.5.1"
40
45
  spec.add_dependency "rest-client", "~> 2.0"
41
- spec.add_dependency 'websocket-client-simple', "~> 0.3.0"
46
+ spec.add_dependency "faye-websocket", ">= 0.10.7", "< 0.12.0"
47
+ spec.add_dependency "i18n", "= 1.1.0"
48
+ spec.add_dependency "thor", "= 0.20.0"
49
+
42
50
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: signalfx
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - SignalFx, Inc
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-03-27 00:00:00.000000000 Z
11
+ date: 2020-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.10'
19
+ version: 1.17.3
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.10'
26
+ version: 1.17.3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '2.1'
61
+ version: 2.3.1
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '2.1'
68
+ version: 2.3.1
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: thin
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -95,19 +95,25 @@ dependencies:
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: faye-websocket
98
+ name: activesupport
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - "~>"
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
- version: 0.10.7
104
- type: :development
103
+ version: '3.2'
104
+ - - "<"
105
+ - !ruby/object:Gem::Version
106
+ version: '6'
107
+ type: :runtime
105
108
  prerelease: false
106
109
  version_requirements: !ruby/object:Gem::Requirement
107
110
  requirements:
108
- - - "~>"
111
+ - - ">="
109
112
  - !ruby/object:Gem::Version
110
- version: 0.10.7
113
+ version: '3.2'
114
+ - - "<"
115
+ - !ruby/object:Gem::Version
116
+ version: '6'
111
117
  - !ruby/object:Gem::Dependency
112
118
  name: protobuf
113
119
  requirement: !ruby/object:Gem::Requirement
@@ -137,19 +143,53 @@ dependencies:
137
143
  - !ruby/object:Gem::Version
138
144
  version: '2.0'
139
145
  - !ruby/object:Gem::Dependency
140
- name: websocket-client-simple
146
+ name: faye-websocket
141
147
  requirement: !ruby/object:Gem::Requirement
142
148
  requirements:
143
- - - "~>"
149
+ - - ">="
144
150
  - !ruby/object:Gem::Version
145
- version: 0.3.0
151
+ version: 0.10.7
152
+ - - "<"
153
+ - !ruby/object:Gem::Version
154
+ version: 0.12.0
146
155
  type: :runtime
147
156
  prerelease: false
148
157
  version_requirements: !ruby/object:Gem::Requirement
149
158
  requirements:
150
- - - "~>"
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: 0.10.7
162
+ - - "<"
163
+ - !ruby/object:Gem::Version
164
+ version: 0.12.0
165
+ - !ruby/object:Gem::Dependency
166
+ name: i18n
167
+ requirement: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - '='
170
+ - !ruby/object:Gem::Version
171
+ version: 1.1.0
172
+ type: :runtime
173
+ prerelease: false
174
+ version_requirements: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - '='
177
+ - !ruby/object:Gem::Version
178
+ version: 1.1.0
179
+ - !ruby/object:Gem::Dependency
180
+ name: thor
181
+ requirement: !ruby/object:Gem::Requirement
182
+ requirements:
183
+ - - '='
184
+ - !ruby/object:Gem::Version
185
+ version: 0.20.0
186
+ type: :runtime
187
+ prerelease: false
188
+ version_requirements: !ruby/object:Gem::Requirement
189
+ requirements:
190
+ - - '='
151
191
  - !ruby/object:Gem::Version
152
- version: 0.3.0
192
+ version: 0.20.0
153
193
  description: This is a programmatic interface in Ruby for SignalFx's metadata and
154
194
  ingest APIs. It is meant to provide a base for communicating with SignalFx APIs
155
195
  that can be easily leveraged by scripts and applications to interact with SignalFx
@@ -188,7 +228,7 @@ homepage: https://signalfx.com
188
228
  licenses:
189
229
  - Apache Software License v2 © SignalFx
190
230
  metadata: {}
191
- post_install_message:
231
+ post_install_message:
192
232
  rdoc_options: []
193
233
  require_paths:
194
234
  - lib
@@ -203,9 +243,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
203
243
  - !ruby/object:Gem::Version
204
244
  version: '0'
205
245
  requirements: []
206
- rubyforge_project:
207
- rubygems_version: 2.6.14
208
- signing_key:
246
+ rubyforge_project:
247
+ rubygems_version: 2.7.6.2
248
+ signing_key:
209
249
  specification_version: 4
210
250
  summary: Ruby client library for SignalFx
211
251
  test_files: []