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.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +13 -0
- data/.rubocop.yml +18 -0
- data/CHANGELOG.md +10 -2
- data/Gemfile +2 -0
- data/README.markdown +19 -10
- data/Rakefile +4 -1
- data/lib/riemann/attribute.rb +2 -0
- data/lib/riemann/auto_state.rb +9 -3
- data/lib/riemann/client/ssl_socket.rb +22 -21
- data/lib/riemann/client/tcp.rb +38 -38
- data/lib/riemann/client/tcp_socket.rb +66 -51
- data/lib/riemann/client/udp.rb +8 -4
- data/lib/riemann/client.rb +78 -79
- data/lib/riemann/event.rb +45 -51
- data/lib/riemann/message.rb +2 -0
- data/lib/riemann/metric_thread.rb +59 -54
- data/lib/riemann/query.rb +4 -2
- data/lib/riemann/state.rb +8 -8
- data/lib/riemann/version.rb +3 -1
- data/lib/riemann.rb +2 -3
- data/riemann-client.gemspec +9 -5
- data/spec/client.rb +113 -113
- metadata +23 -8
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
|
35
|
+
raise 'wait_for condition never realized'
|
35
36
|
end
|
36
37
|
|
37
|
-
def roundtrip_metric(
|
38
|
+
def roundtrip_metric(metric)
|
38
39
|
@client_with_transport << {
|
39
|
-
:
|
40
|
-
:metric
|
40
|
+
service: 'metric-test',
|
41
|
+
metric: metric
|
41
42
|
}
|
42
43
|
|
43
|
-
wait_for {@client["service = \"metric-test\" and metric = #{
|
44
|
-
metric.should.equal
|
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
|
-
|
49
|
+
->(obj) { !(obj.nil? || obj == false) }
|
49
50
|
end
|
50
51
|
|
51
52
|
def falsey
|
52
|
-
|
53
|
+
->(obj) { obj.nil? || obj == false }
|
53
54
|
end
|
54
55
|
|
55
|
-
shared
|
56
|
-
|
56
|
+
shared 'a riemann client' do
|
57
57
|
should 'yield itself to given block' do
|
58
58
|
client = nil
|
59
|
-
Client.new(:
|
59
|
+
Client.new(host: 'localhost', port: 5555) do |c|
|
60
60
|
client = c
|
61
61
|
end
|
62
|
-
client.should.be.
|
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(:
|
69
|
+
Client.new(host: 'localhost', port: 5555) do |c|
|
70
70
|
client = c
|
71
|
-
raise
|
71
|
+
raise 'The Boom'
|
72
72
|
end
|
73
|
-
rescue
|
73
|
+
rescue StandardError
|
74
74
|
# swallow the exception
|
75
75
|
end
|
76
|
-
client.should.be.
|
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 << {:
|
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
|
-
:
|
105
|
-
:
|
106
|
-
:
|
107
|
-
:
|
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
|
-
:
|
124
|
-
:
|
125
|
-
:
|
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
|
-
:
|
139
|
-
:
|
140
|
-
:
|
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
|
-
:
|
153
|
-
:
|
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
|
163
|
-
@client_with_transport << { :
|
164
|
-
@client_with_transport << { :
|
165
|
-
@client_with_transport << { :
|
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
|
-
|
169
|
-
@client.query('state = "critical" and (service = "1" or service = "2" or service = "3")').events
|
170
|
-
|
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 << {:
|
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 |
|
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 #{
|
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 |
|
198
|
+
(0...concurrency).map do |_i|
|
199
199
|
Thread.new do
|
200
200
|
per_thread.times do
|
201
201
|
@client_with_transport.<<({
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
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
|
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 #{
|
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
|
218
|
+
describe 'Riemann::Client (TLS transport)' do
|
222
219
|
before do
|
223
|
-
@client = Client.new(:
|
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
|
228
|
+
behaves_like 'a riemann client'
|
228
229
|
|
229
230
|
should 'send a state' do
|
230
231
|
res = @client_with_transport << {
|
231
|
-
:
|
232
|
-
:
|
233
|
-
:
|
234
|
-
:
|
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
|
-
|
244
|
-
|
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
|
-
|
252
|
-
|
253
|
-
|
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
|
-
|
260
|
-
|
261
|
-
|
262
|
-
wait_for { @client['service = "survive TCP local close"'].first
|
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
|
-
|
268
|
-
|
269
|
-
|
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
|
275
|
+
describe 'Riemann::Client (TCP transport)' do
|
275
276
|
before do
|
276
|
-
@client = Client.new(:
|
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
|
281
|
+
behaves_like 'a riemann client'
|
281
282
|
|
282
283
|
should 'send a state' do
|
283
284
|
res = @client_with_transport << {
|
284
|
-
:
|
285
|
-
:
|
286
|
-
:
|
287
|
-
:
|
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
|
-
|
297
|
-
|
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
|
-
|
305
|
-
|
306
|
-
|
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
|
-
|
313
|
-
|
314
|
-
|
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
|
-
|
321
|
-
|
322
|
-
|
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
|
328
|
+
describe 'Riemann::Client (UDP transport)' do
|
328
329
|
before do
|
329
|
-
@client = Client.new(:
|
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
|
334
|
+
behaves_like 'a riemann client'
|
334
335
|
|
335
336
|
should 'send a state' do
|
336
337
|
res = @client_with_transport << {
|
337
|
-
:
|
338
|
-
:
|
339
|
-
:
|
340
|
-
:
|
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
|
-
|
350
|
-
|
351
|
-
|
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
|
-
|
358
|
-
|
359
|
-
|
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
|
-
|
366
|
-
|
367
|
-
|
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
|
-
|
374
|
-
|
375
|
-
|
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
|
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.
|
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-
|
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:
|
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.
|
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.
|
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:
|