signalfx 2.1.0 → 3.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: f4d9b5d2fd10a70d0b431b6e6d4200e3f4634ff5
4
- data.tar.gz: 711835760cb429f574c776435eba20a46b45afa1
2
+ SHA256:
3
+ metadata.gz: 670a3ffcd46baae47aaefbcb622426e9fae027750802206e7bd74b6fecb9928a
4
+ data.tar.gz: 6a757389d9ef2f19b4f58747f0d6ef762a9f809a189b0b1c7692ef950236e093
5
5
  SHA512:
6
- metadata.gz: c9ab6fa6dc20607bb4516534e674206af91bb8ffd7304e2b579a36cbcb1cd85dc23e0b2e25620bec371738b90d4dedb00bc5af22bf7871370167b8470d74f739
7
- data.tar.gz: 9f3d726b842f389cc7e5732b3124d376898cd5639fe657133420c6633bf3ee811c82d139ea4261726f7440842fc98a421819ca3bcd343f6382a21d388212168b
6
+ metadata.gz: 751e1649262c8e0d0d3fa6ccc02e71ec602ff166cc7a78d6b0e1c41a514983dfd8e106cd22dfabb9400f48d484a0b3eebe72d50dd0507b3369ddc3e813772217
7
+ data.tar.gz: b9db8d6fdbed7c32a8f64fa449a36a7830d6f70e1be3606a2bd863046cea6f8f437204b7106f52be8afac3c56b1a7e5a06ae604754637356dd7bb47c4c03eaa8
data/.gitignore CHANGED
@@ -33,9 +33,9 @@ build/
33
33
 
34
34
  # for a library or gem, you might want to ignore these files since the code is
35
35
  # intended to run in multiple environments; otherwise, check them in:
36
- # Gemfile.lock
37
- # .ruby-version
38
- # .ruby-gemset
36
+ Gemfile.lock
37
+ .ruby-version
38
+ .ruby-gemset
39
39
 
40
40
  # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
41
41
  .rvmrc
data/.travis.yml CHANGED
@@ -1,6 +1,11 @@
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
data/README.md CHANGED
@@ -31,9 +31,33 @@ installing a more recent gem. Building and installing signalfx from source will
31
31
 
32
32
  ## Usage
33
33
 
34
- ### API access token
35
34
 
36
- 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
+
37
61
 
38
62
  ### Create client
39
63
 
@@ -105,6 +129,11 @@ actually make it to SignalFx).
105
129
  To send data through a HTTP proxy, set the environment variable `http_proxy`
106
130
  with the proxy URL.
107
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
+
108
137
  ### Sending multi-dimensional data
109
138
 
110
139
  Reporting dimensions for the data is also optional, and can be
@@ -174,9 +203,23 @@ sending events.
174
203
 
175
204
  You can run SignalFlow computations as well. This library supports all of the
176
205
  functionality described in our [API docs for
177
- SignalFlow](https://developers.signalfx.com/reference#signalflowconnect). Right
206
+ SignalFlow](https://developers.signalfx.com/signalflow_reference.html). Right
178
207
  now, the only supported transport mechanism is WebSockets.
179
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
+
180
223
  To create a new SignalFlow client instance from an existing SignalFx client:
181
224
 
182
225
  ```ruby
@@ -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, @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
@@ -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, 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
@@ -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,14 +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, logger: Logger.new(STDOUT, progname: "signalfx"))
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
23
29
  @logger = logger
24
30
  @compress = true
31
+ @proxy_url = proxy_url
32
+ @debug = debug
25
33
 
26
34
  @lock = Mutex.new
27
35
  @close_reason = nil
36
+ @last_error = nil
28
37
  reinit
29
38
  end
30
39
 
@@ -188,6 +197,9 @@ class SignalFlowWebsocketTransport
188
197
  # The socket will be closed by the server if auth isn't successful
189
198
  # within 5 seconds so no point in waiting longer
190
199
  if Time.now - start_time > 5 || @close_reason
200
+ if @last_error
201
+ raise WebsocketError.new(@last_error)
202
+ end
191
203
  raise "Could not authenticate to SignalFlow WebSocket: #{@close_reason}"
192
204
  end
193
205
  sleep 0.1
@@ -200,7 +212,11 @@ class SignalFlowWebsocketTransport
200
212
  private :send_msg
201
213
 
202
214
  def on_close(msg)
203
- @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})"
204
220
  @chan_callbacks.keys.each do |channel_name|
205
221
  invoke_callback_for_channel({ :event => "CONNECTION_CLOSED" }, channel_name)
206
222
  end
@@ -208,21 +224,31 @@ class SignalFlowWebsocketTransport
208
224
  reinit
209
225
  end
210
226
 
227
+ def on_error(e)
228
+ @logger.error("ERROR #{e.inspect}")
229
+ @last_error = e
230
+ end
231
+
232
+
211
233
  def on_message(m)
212
- begin
213
- return if m.type == :ping
214
- if m.type == :close
215
- on_close(m)
216
- return
217
- end
234
+ if @debug
235
+ @logger.info("Websocket on_message: #{m}")
236
+ end
218
237
 
219
- 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)
220
242
  rescue Exception => e
221
243
  @logger.error("Error processing SignalFlow message: #{e.backtrace.first}: #{e.message} (#{e.class})")
222
244
  end
223
245
  end
224
246
 
225
247
  def on_open
248
+ if @debug
249
+ @logger.info("Websocket on_open")
250
+ end
251
+
226
252
  @ws.send({
227
253
  :type => "authenticate",
228
254
  :token => @api_token,
@@ -233,26 +259,38 @@ class SignalFlowWebsocketTransport
233
259
  # reactor.
234
260
  def startup_client
235
261
  this = self
236
- WebSocket::Client::Simple.connect("#{@stream_endpoint}/v2/signalflow/connect",
237
- # Verification is disabled by default so this is essential
238
- {verify_mode: OpenSSL::SSL::VERIFY_PEER}) do |ws|
239
- @ws = ws
240
- ws.on :error do |e|
241
- @logger.error("ERROR #{e.inspect}")
242
- end
243
262
 
244
- ws.on :close do |e|
245
- this.on_close(e)
246
- 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
247
279
 
248
- ws.on :message do |m|
249
- this.on_message(m)
250
- end
280
+ @ws.on :close do |e|
281
+ this.on_close(e)
282
+ EM.stop_event_loop
283
+ end
251
284
 
252
- ws.on :open do
253
- this.on_open
254
- end
255
- 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
+ }
256
294
  end
257
295
  private :startup_client
258
296
 
@@ -294,7 +332,8 @@ class SignalFlowWebsocketTransport
294
332
  if is_text
295
333
  JSON.parse(raw_msg, {:symbolize_names => true})
296
334
  else
297
- BinaryMessageParser.parse(raw_msg)
335
+ # Convert the byte array to a string
336
+ BinaryMessageParser.parse(raw_msg.pack("c*"))
298
337
  end
299
338
  end
300
339
  private :parse_message
@@ -1,8 +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
3
  module SignalFx
4
4
  module Version
5
- VERSION = '2.1.0'
5
+ VERSION = '3.1.1'
6
6
  NAME = 'signalfx-ruby-client'
7
7
  end
8
8
  end
data/signalfx.gemspec CHANGED
@@ -29,13 +29,12 @@ 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
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"
39
38
 
40
39
  # protobuf enforces this check but builds with a newer Ruby version so it's not enabled.
41
40
  # Incorporating here to allow 2.2.0-1 users to successfully build and install signalfx.
@@ -44,5 +43,7 @@ Gem::Specification.new do |spec|
44
43
 
45
44
  spec.add_dependency "protobuf", ">= 3.5.1"
46
45
  spec.add_dependency "rest-client", "~> 2.0"
47
- 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 "thor", "= 0.20.0"
48
+
48
49
  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.1.0
4
+ version: 3.1.1
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: 2019-02-22 00:00:00.000000000 Z
11
+ date: 2021-01-20 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
@@ -94,20 +94,6 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: faye-websocket
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: 0.10.7
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: 0.10.7
111
97
  - !ruby/object:Gem::Dependency
112
98
  name: activesupport
113
99
  requirement: !ruby/object:Gem::Requirement
@@ -151,19 +137,39 @@ dependencies:
151
137
  - !ruby/object:Gem::Version
152
138
  version: '2.0'
153
139
  - !ruby/object:Gem::Dependency
154
- name: websocket-client-simple
140
+ name: faye-websocket
155
141
  requirement: !ruby/object:Gem::Requirement
156
142
  requirements:
157
- - - "~>"
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: 0.10.7
146
+ - - "<"
158
147
  - !ruby/object:Gem::Version
159
- version: 0.3.0
148
+ version: 0.12.0
160
149
  type: :runtime
161
150
  prerelease: false
162
151
  version_requirements: !ruby/object:Gem::Requirement
163
152
  requirements:
164
- - - "~>"
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: 0.10.7
156
+ - - "<"
157
+ - !ruby/object:Gem::Version
158
+ version: 0.12.0
159
+ - !ruby/object:Gem::Dependency
160
+ name: thor
161
+ requirement: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - '='
164
+ - !ruby/object:Gem::Version
165
+ version: 0.20.0
166
+ type: :runtime
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - '='
165
171
  - !ruby/object:Gem::Version
166
- version: 0.3.0
172
+ version: 0.20.0
167
173
  description: This is a programmatic interface in Ruby for SignalFx's metadata and
168
174
  ingest APIs. It is meant to provide a base for communicating with SignalFx APIs
169
175
  that can be easily leveraged by scripts and applications to interact with SignalFx
@@ -177,7 +183,6 @@ files:
177
183
  - ".gitignore"
178
184
  - ".travis.yml"
179
185
  - Gemfile
180
- - Gemfile.lock
181
186
  - README.md
182
187
  - Rakefile
183
188
  - bin/console
@@ -202,7 +207,7 @@ homepage: https://signalfx.com
202
207
  licenses:
203
208
  - Apache Software License v2 © SignalFx
204
209
  metadata: {}
205
- post_install_message:
210
+ post_install_message:
206
211
  rdoc_options: []
207
212
  require_paths:
208
213
  - lib
@@ -217,9 +222,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
217
222
  - !ruby/object:Gem::Version
218
223
  version: '0'
219
224
  requirements: []
220
- rubyforge_project:
221
- rubygems_version: 2.5.2.3
222
- signing_key:
225
+ rubygems_version: 3.1.4
226
+ signing_key:
223
227
  specification_version: 4
224
228
  summary: Ruby client library for SignalFx
225
229
  test_files: []
data/Gemfile.lock DELETED
@@ -1,121 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- signalfx (2.1.0)
5
- activesupport (>= 3.2)
6
- protobuf (>= 3.5.1)
7
- rest-client (~> 2.0)
8
- websocket-client-simple (~> 0.3.0)
9
-
10
- GEM
11
- remote: https://rubygems.org/
12
- specs:
13
- activesupport (5.2.1)
14
- concurrent-ruby (~> 1.0, >= 1.0.2)
15
- i18n (>= 0.7, < 2)
16
- minitest (~> 5.1)
17
- tzinfo (~> 1.1)
18
- addressable (2.5.2)
19
- public_suffix (>= 2.0.2, < 4.0)
20
- coderay (1.1.1)
21
- concurrent-ruby (1.0.5)
22
- crack (0.4.3)
23
- safe_yaml (~> 1.0.0)
24
- daemons (1.2.4)
25
- diff-lcs (1.2.5)
26
- docile (1.3.1)
27
- domain_name (0.5.20180417)
28
- unf (>= 0.0.5, < 1.0.0)
29
- event_emitter (0.2.6)
30
- eventmachine (1.2.5)
31
- faye-websocket (0.10.7)
32
- eventmachine (>= 0.12.0)
33
- websocket-driver (>= 0.5.1)
34
- hashdiff (0.3.7)
35
- http-cookie (1.0.3)
36
- domain_name (~> 0.5)
37
- i18n (1.1.0)
38
- concurrent-ruby (~> 1.0)
39
- json (2.1.0)
40
- method_source (0.8.2)
41
- middleware (0.1.0)
42
- mime-types (3.2.2)
43
- mime-types-data (~> 3.2015)
44
- mime-types-data (3.2018.0812)
45
- minitest (5.11.3)
46
- netrc (0.11.0)
47
- protobuf (3.8.4)
48
- activesupport (>= 3.2)
49
- middleware
50
- thor
51
- thread_safe
52
- pry (0.10.4)
53
- coderay (~> 1.1.0)
54
- method_source (~> 0.8.1)
55
- slop (~> 3.4)
56
- public_suffix (3.0.2)
57
- rack (2.0.3)
58
- rake (10.4.2)
59
- rest-client (2.0.2)
60
- http-cookie (>= 1.0.2, < 2.0)
61
- mime-types (>= 1.16, < 4.0)
62
- netrc (~> 0.8)
63
- rspec (3.3.0)
64
- rspec-core (~> 3.3.0)
65
- rspec-expectations (~> 3.3.0)
66
- rspec-mocks (~> 3.3.0)
67
- rspec-core (3.3.2)
68
- rspec-support (~> 3.3.0)
69
- rspec-expectations (3.3.1)
70
- diff-lcs (>= 1.2.0, < 2.0)
71
- rspec-support (~> 3.3.0)
72
- rspec-mocks (3.3.2)
73
- diff-lcs (>= 1.2.0, < 2.0)
74
- rspec-support (~> 3.3.0)
75
- rspec-support (3.3.0)
76
- safe_yaml (1.0.4)
77
- simplecov (0.16.1)
78
- docile (~> 1.1)
79
- json (>= 1.8, < 3)
80
- simplecov-html (~> 0.10.0)
81
- simplecov-html (0.10.2)
82
- slop (3.6.0)
83
- thin (1.7.2)
84
- daemons (~> 1.0, >= 1.0.9)
85
- eventmachine (~> 1.0, >= 1.0.4)
86
- rack (>= 1, < 3)
87
- thor (0.20.0)
88
- thread_safe (0.3.6)
89
- tzinfo (1.2.5)
90
- thread_safe (~> 0.1)
91
- unf (0.1.4)
92
- unf_ext
93
- unf_ext (0.0.7.5)
94
- webmock (2.3.2)
95
- addressable (>= 2.3.6)
96
- crack (>= 0.3.2)
97
- hashdiff
98
- websocket (1.2.8)
99
- websocket-client-simple (0.3.0)
100
- event_emitter
101
- websocket
102
- websocket-driver (0.6.5)
103
- websocket-extensions (>= 0.1.0)
104
- websocket-extensions (0.1.2)
105
-
106
- PLATFORMS
107
- ruby
108
-
109
- DEPENDENCIES
110
- bundler (~> 1.10)
111
- faye-websocket (~> 0.10.7)
112
- pry
113
- rake (~> 10.0)
114
- rspec (~> 3.3)
115
- signalfx!
116
- simplecov
117
- thin (~> 1.7)
118
- webmock (~> 2.3.1)
119
-
120
- BUNDLED WITH
121
- 1.16.3