riemann-client 1.0.0 → 1.0.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.
data/spec/client.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  # How to run the bacon tests:
4
5
  # 1. Start Riemann using the config from riemann.config
@@ -12,7 +13,7 @@ require 'timecop'
12
13
 
13
14
  Bacon.summary_on_exit
14
15
 
15
- include Riemann
16
+ include Riemann # rubocop:disable Style/MixinUsage
16
17
 
17
18
  INACTIVITY_TIME = 5
18
19
 
@@ -31,56 +32,55 @@ def wait_for(&block)
31
32
  sleep(0.1)
32
33
  end
33
34
 
34
- raise "wait_for condition never realized"
35
+ raise 'wait_for condition never realized'
35
36
  end
36
37
 
37
- def roundtrip_metric(m)
38
+ def roundtrip_metric(metric)
38
39
  @client_with_transport << {
39
- :service => 'metric-test',
40
- :metric => m
40
+ service: 'metric-test',
41
+ metric: metric
41
42
  }
42
43
 
43
- wait_for {@client["service = \"metric-test\" and metric = #{m}"].first }.
44
- metric.should.equal m
44
+ wait_for { @client["service = \"metric-test\" and metric = #{metric}"].first }
45
+ .metric.should.equal metric
45
46
  end
46
47
 
47
48
  def truthy
48
- lambda { |obj| !(obj.nil? || obj == false) }
49
+ ->(obj) { !(obj.nil? || obj == false) }
49
50
  end
50
51
 
51
52
  def falsey
52
- lambda { |obj| obj.nil? || obj == false }
53
+ ->(obj) { obj.nil? || obj == false }
53
54
  end
54
55
 
55
- shared "a riemann client" do
56
-
56
+ shared 'a riemann client' do
57
57
  should 'yield itself to given block' do
58
58
  client = nil
59
- Client.new(:host => "localhost", :port => 5555) do |c|
59
+ Client.new(host: 'localhost', port: 5555) do |c|
60
60
  client = c
61
61
  end
62
- client.should.be.kind_of?(Client)
62
+ client.should.be.is_a?(Client)
63
63
  client.should.not.be.connected
64
64
  end
65
65
 
66
66
  should 'close sockets if given a block that raises' do
67
67
  client = nil
68
68
  begin
69
- Client.new(:host => "localhost", :port => 5555) do |c|
69
+ Client.new(host: 'localhost', port: 5555) do |c|
70
70
  client = c
71
- raise "The Boom"
71
+ raise 'The Boom'
72
72
  end
73
- rescue
73
+ rescue StandardError
74
74
  # swallow the exception
75
75
  end
76
- client.should.be.kind_of?(Client)
76
+ client.should.be.is_a?(Client)
77
77
  client.should.not.be.connected
78
78
  end
79
79
 
80
80
  should 'be connected after sending' do
81
81
  @client_with_transport.connected?.should.be falsey
82
82
  @client.connected?.should.be falsey
83
- @client_with_transport << {:state => 'ok', :service => 'connected check' }
83
+ @client_with_transport << { state: 'ok', service: 'connected check' }
84
84
  @client_with_transport.connected?.should.be truthy
85
85
  # NOTE: only single transport connected at this point, @client.connected? is still false until all transports used
86
86
  end
@@ -101,10 +101,10 @@ shared "a riemann client" do
101
101
 
102
102
  should 'send custom attributes' do
103
103
  event = Event.new(
104
- :service => 'custom',
105
- :state => 'ok',
106
- :cats => 'meow',
107
- :env => 'prod'
104
+ service: 'custom',
105
+ state: 'ok',
106
+ cats: 'meow',
107
+ env: 'prod'
108
108
  )
109
109
  event[:sneak] = 'attack'
110
110
  @client_with_transport << event
@@ -120,9 +120,9 @@ shared "a riemann client" do
120
120
  Timecop.freeze do
121
121
  t = (Time.now - 10).to_i
122
122
  @client_with_transport << {
123
- :state => 'ok',
124
- :service => 'test',
125
- :time => t
123
+ state: 'ok',
124
+ service: 'test',
125
+ time: t
126
126
  }
127
127
  wait_for { @client.query('service = "test"').events.first.time == t }
128
128
  e = @client.query('service = "test"').events.first
@@ -135,9 +135,9 @@ shared "a riemann client" do
135
135
  Timecop.freeze do
136
136
  t = ((Time.now - 10).to_f * 1_000_000).to_i
137
137
  @client_with_transport << {
138
- :state => 'ok',
139
- :service => 'test',
140
- :time_micros => t
138
+ state: 'ok',
139
+ service: 'test',
140
+ time_micros: t
141
141
  }
142
142
  wait_for { @client.query('service = "test"').events.first.time_micros == t }
143
143
  e = @client.query('service = "test"').events.first
@@ -149,8 +149,8 @@ shared "a riemann client" do
149
149
  should 'send a state without time nor time_micros' do
150
150
  time_before = (Time.now.to_f * 1_000_000).to_i
151
151
  @client_with_transport << {
152
- :state => 'ok',
153
- :service => 'timeless test'
152
+ state: 'ok',
153
+ service: 'timeless test'
154
154
  }
155
155
  wait_for { @client.query('service = "timeless test"').events.first.time_micros >= time_before }
156
156
  e = @client.query('service = "timeless test"').events.first
@@ -159,33 +159,33 @@ shared "a riemann client" do
159
159
  [time_before, e.time_micros, time_after].sort.should.equal([time_before, e.time_micros, time_after])
160
160
  end
161
161
 
162
- should "query states" do
163
- @client_with_transport << { :state => 'critical', :service => '1' }
164
- @client_with_transport << { :state => 'warning', :service => '2' }
165
- @client_with_transport << { :state => 'critical', :service => '3' }
162
+ should 'query states' do
163
+ @client_with_transport << { state: 'critical', service: '1' }
164
+ @client_with_transport << { state: 'warning', service: '2' }
165
+ @client_with_transport << { state: 'critical', service: '3' }
166
166
  wait_for { @client.query('service = "3"').events.first }
167
- @client.query.events.
168
- map(&:service).to_set.should.superset ['1', '2', '3'].to_set
169
- @client.query('state = "critical" and (service = "1" or service = "2" or service = "3")').events.
170
- map(&:service).to_set.should.equal ['1', '3'].to_set
167
+ @client.query.events
168
+ .map(&:service).to_set.should.superset %w[1 2 3].to_set
169
+ @client.query('state = "critical" and (service = "1" or service = "2" or service = "3")').events
170
+ .map(&:service).to_set.should.equal %w[1 3].to_set
171
171
  end
172
172
 
173
173
  it '[]' do
174
- # @client['state = "critical"'].should == []
175
- @client_with_transport << {:state => 'critical'}
174
+ # @client['state = "critical"'].should == []
175
+ @client_with_transport << { state: 'critical' }
176
176
  wait_for { @client['state = "critical"'].first }.state.should.equal 'critical'
177
177
  end
178
178
 
179
179
  should 'query quickly' do
180
180
  t1 = Time.now
181
181
  total = 1000
182
- total.times do |i|
182
+ total.times do |_i|
183
183
  @client.query('state = "critical"')
184
184
  end
185
185
  t2 = Time.now
186
186
 
187
187
  rate = total / (t2 - t1)
188
- puts "\n #{"%.2f" % rate} queries/sec (#{"%.2f" % (1000/rate)}ms per query)"
188
+ puts "\n #{format('%.2f', rate)} queries/sec (#{format('%.2f', (1000 / rate))}ms per query)"
189
189
  rate.should > 100
190
190
  end
191
191
 
@@ -195,43 +195,44 @@ shared "a riemann client" do
195
195
  total = concurrency * per_thread
196
196
 
197
197
  t1 = Time.now
198
- (0...concurrency).map do |i|
198
+ (0...concurrency).map do |_i|
199
199
  Thread.new do
200
200
  per_thread.times do
201
201
  @client_with_transport.<<({
202
- :state => 'ok',
203
- :service => 'test',
204
- :description => 'desc',
205
- :metric_f => 1.0
206
- })
202
+ state: 'ok',
203
+ service: 'test',
204
+ description: 'desc',
205
+ metric_f: 1.0
206
+ })
207
207
  end
208
208
  end
209
- end.each do |t|
210
- t.join
211
- end
209
+ end.each(&:join)
212
210
  t2 = Time.now
213
211
 
214
212
  rate = total / (t2 - t1)
215
- puts "\n #{"%.2f" % rate} inserts/sec (#{"%.2f" % (1000/rate)}ms per insert)"
213
+ puts "\n #{format('%.2f', rate)} inserts/sec (#{format('%.2f', (1000 / rate))}ms per insert)"
216
214
  rate.should > @expected_rate
217
215
  end
218
-
219
216
  end
220
217
 
221
- describe "Riemann::Client (TLS transport)" do
218
+ describe 'Riemann::Client (TLS transport)' do
222
219
  before do
223
- @client = Client.new(:host => "localhost", :port => 5554, :ssl => true, :key_file => '/etc/riemann/riemann_server.pkcs8', :cert_file => '/etc/riemann/riemann_server.crt', :ca_file => '/etc/riemann/riemann_server.crt', :ssl_verify => true)
220
+ @client = Client.new(host: 'localhost', port: 5554, ssl: true,
221
+ key_file: '/etc/riemann/riemann_server.pkcs8',
222
+ cert_file: '/etc/riemann/riemann_server.crt',
223
+ ca_file: '/etc/riemann/riemann_server.crt',
224
+ ssl_verify: true)
224
225
  @client_with_transport = @client.tcp
225
226
  @expected_rate = 100
226
227
  end
227
- behaves_like "a riemann client"
228
+ behaves_like 'a riemann client'
228
229
 
229
230
  should 'send a state' do
230
231
  res = @client_with_transport << {
231
- :state => 'ok',
232
- :service => 'test',
233
- :description => 'desc',
234
- :metric_f => 1.0
232
+ state: 'ok',
233
+ service: 'test',
234
+ description: 'desc',
235
+ metric_f: 1.0
235
236
  }
236
237
 
237
238
  res.ok.should.be truthy
@@ -240,51 +241,51 @@ describe "Riemann::Client (TLS transport)" do
240
241
 
241
242
  should 'survive inactivity' do
242
243
  @client_with_transport.<<({
243
- :state => 'warning',
244
- :service => 'survive TCP inactivity',
245
- })
244
+ state: 'warning',
245
+ service: 'survive TCP inactivity'
246
+ })
246
247
  wait_for { @client['service = "survive TCP inactivity"'].first.state == 'warning' }
247
248
 
248
249
  sleep INACTIVITY_TIME
249
250
 
250
251
  @client_with_transport.<<({
251
- :state => 'ok',
252
- :service => 'survive TCP inactivity',
253
- }).ok.should.be truthy
252
+ state: 'ok',
253
+ service: 'survive TCP inactivity'
254
+ }).ok.should.be truthy
254
255
  wait_for { @client['service = "survive TCP inactivity"'].first.state == 'ok' }
255
256
  end
256
257
 
257
258
  should 'survive local close' do
258
259
  @client_with_transport.<<({
259
- :state => 'warning',
260
- :service => 'survive TCP local close',
261
- }).ok.should.be truthy
262
- wait_for { @client['service = "survive TCP local close"'].first .state == 'warning' }
260
+ state: 'warning',
261
+ service: 'survive TCP local close'
262
+ }).ok.should.be truthy
263
+ wait_for { @client['service = "survive TCP local close"'].first.state == 'warning' }
263
264
 
264
265
  @client.close
265
266
 
266
267
  @client_with_transport.<<({
267
- :state => 'ok',
268
- :service => 'survive TCP local close',
269
- }).ok.should.be truthy
268
+ state: 'ok',
269
+ service: 'survive TCP local close'
270
+ }).ok.should.be truthy
270
271
  wait_for { @client['service = "survive TCP local close"'].first.state == 'ok' }
271
272
  end
272
273
  end
273
274
 
274
- describe "Riemann::Client (TCP transport)" do
275
+ describe 'Riemann::Client (TCP transport)' do
275
276
  before do
276
- @client = Client.new(:host => "localhost", :port => 5555)
277
+ @client = Client.new(host: 'localhost', port: 5555)
277
278
  @client_with_transport = @client.tcp
278
279
  @expected_rate = 100
279
280
  end
280
- behaves_like "a riemann client"
281
+ behaves_like 'a riemann client'
281
282
 
282
283
  should 'send a state' do
283
284
  res = @client_with_transport << {
284
- :state => 'ok',
285
- :service => 'test',
286
- :description => 'desc',
287
- :metric_f => 1.0
285
+ state: 'ok',
286
+ service: 'test',
287
+ description: 'desc',
288
+ metric_f: 1.0
288
289
  }
289
290
 
290
291
  res.ok.should.be truthy
@@ -293,51 +294,51 @@ describe "Riemann::Client (TCP transport)" do
293
294
 
294
295
  should 'survive inactivity' do
295
296
  @client_with_transport.<<({
296
- :state => 'warning',
297
- :service => 'survive TCP inactivity',
298
- })
297
+ state: 'warning',
298
+ service: 'survive TCP inactivity'
299
+ })
299
300
  wait_for { @client['service = "survive TCP inactivity"'].first.state == 'warning' }
300
301
 
301
302
  sleep INACTIVITY_TIME
302
303
 
303
304
  @client_with_transport.<<({
304
- :state => 'ok',
305
- :service => 'survive TCP inactivity',
306
- }).ok.should.be truthy
305
+ state: 'ok',
306
+ service: 'survive TCP inactivity'
307
+ }).ok.should.be truthy
307
308
  wait_for { @client['service = "survive TCP inactivity"'].first.state == 'ok' }
308
309
  end
309
310
 
310
311
  should 'survive local close' do
311
312
  @client_with_transport.<<({
312
- :state => 'warning',
313
- :service => 'survive TCP local close',
314
- }).ok.should.be truthy
313
+ state: 'warning',
314
+ service: 'survive TCP local close'
315
+ }).ok.should.be truthy
315
316
  wait_for { @client['service = "survive TCP local close"'].first.state == 'warning' }
316
317
 
317
318
  @client.close
318
319
 
319
320
  @client_with_transport.<<({
320
- :state => 'ok',
321
- :service => 'survive TCP local close',
322
- }).ok.should.be truthy
321
+ state: 'ok',
322
+ service: 'survive TCP local close'
323
+ }).ok.should.be truthy
323
324
  wait_for { @client['service = "survive TCP local close"'].first.state == 'ok' }
324
325
  end
325
326
  end
326
327
 
327
- describe "Riemann::Client (UDP transport)" do
328
+ describe 'Riemann::Client (UDP transport)' do
328
329
  before do
329
- @client = Client.new(:host => "localhost", :port => 5555)
330
+ @client = Client.new(host: 'localhost', port: 5555)
330
331
  @client_with_transport = @client.udp
331
332
  @expected_rate = 1000
332
333
  end
333
- behaves_like "a riemann client"
334
+ behaves_like 'a riemann client'
334
335
 
335
336
  should 'send a state' do
336
337
  res = @client_with_transport << {
337
- :state => 'ok',
338
- :service => 'test',
339
- :description => 'desc',
340
- :metric_f => 1.0
338
+ state: 'ok',
339
+ service: 'test',
340
+ description: 'desc',
341
+ metric_f: 1.0
341
342
  }
342
343
 
343
344
  res.should.be.nil
@@ -346,39 +347,38 @@ describe "Riemann::Client (UDP transport)" do
346
347
 
347
348
  should 'survive inactivity' do
348
349
  @client_with_transport.<<({
349
- :state => 'warning',
350
- :service => 'survive UDP inactivity',
351
- }).should.be.nil
350
+ state: 'warning',
351
+ service: 'survive UDP inactivity'
352
+ }).should.be.nil
352
353
  wait_for { @client['service = "survive UDP inactivity"'].first.state == 'warning' }
353
354
 
354
355
  sleep INACTIVITY_TIME
355
356
 
356
357
  @client_with_transport.<<({
357
- :state => 'ok',
358
- :service => 'survive UDP inactivity',
359
- }).should.be.nil
358
+ state: 'ok',
359
+ service: 'survive UDP inactivity'
360
+ }).should.be.nil
360
361
  wait_for { @client['service = "survive UDP inactivity"'].first.state == 'ok' }
361
362
  end
362
363
 
363
364
  should 'survive local close' do
364
365
  @client_with_transport.<<({
365
- :state => 'warning',
366
- :service => 'survive UDP local close',
367
- }).should.be.nil
366
+ state: 'warning',
367
+ service: 'survive UDP local close'
368
+ }).should.be.nil
368
369
  wait_for { @client['service = "survive UDP local close"'].first.state == 'warning' }
369
370
 
370
371
  @client.close
371
372
 
372
373
  @client_with_transport.<<({
373
- :state => 'ok',
374
- :service => 'survive UDP local close',
375
- }).should.be.nil
374
+ state: 'ok',
375
+ service: 'survive UDP local close'
376
+ }).should.be.nil
376
377
  wait_for { @client['service = "survive UDP local close"'].first.state == 'ok' }
377
378
  end
378
379
 
379
- should "raise Riemann::Client::Unsupported exception on query" do
380
+ should 'raise Riemann::Client::Unsupported exception on query' do
380
381
  should.raise(Riemann::Client::Unsupported) { @client_with_transport['service = "test"'] }
381
382
  should.raise(Riemann::Client::Unsupported) { @client_with_transport.query('service = "test"') }
382
383
  end
383
-
384
384
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riemann-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyle Kingsbury
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-16 00:00:00.000000000 Z
11
+ date: 2022-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bacon
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -25,7 +39,7 @@ dependencies:
25
39
  - !ruby/object:Gem::Version
26
40
  version: '1.3'
27
41
  - !ruby/object:Gem::Dependency
28
- name: bacon
42
+ name: rubocop
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - ">="
@@ -88,6 +102,7 @@ extra_rdoc_files: []
88
102
  files:
89
103
  - ".github/workflows/ci.yml"
90
104
  - ".gitignore"
105
+ - ".rubocop.yml"
91
106
  - CHANGELOG.md
92
107
  - Gemfile
93
108
  - LICENSE
@@ -114,7 +129,7 @@ homepage: https://github.com/aphyr/riemann-ruby-client
114
129
  licenses:
115
130
  - MIT
116
131
  metadata: {}
117
- post_install_message:
132
+ post_install_message:
118
133
  rdoc_options: []
119
134
  require_paths:
120
135
  - lib
@@ -122,15 +137,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
122
137
  requirements:
123
138
  - - ">="
124
139
  - !ruby/object:Gem::Version
125
- version: 2.7.0
140
+ version: 2.6.0
126
141
  required_rubygems_version: !ruby/object:Gem::Requirement
127
142
  requirements:
128
143
  - - ">="
129
144
  - !ruby/object:Gem::Version
130
145
  version: '0'
131
146
  requirements: []
132
- rubygems_version: 3.2.5
133
- signing_key:
147
+ rubygems_version: 3.3.15
148
+ signing_key:
134
149
  specification_version: 4
135
150
  summary: Client for the distributed event system Riemann.
136
151
  test_files: