Skip to content

Commit 466e3d3

Browse files
authored
Merge pull request #273 from riemann/fix-riemann-haproxy
Fix `riemann-haproxy` with Ruby 3.0+
2 parents 87fb130 + 7326d2e commit 466e3d3

File tree

5 files changed

+32
-4
lines changed

5 files changed

+32
-4
lines changed

lib/riemann/tools.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def report(event)
6363
event[:tags] = [*event.fetch(:tags, [])] + options[:tag].map(&:dup)
6464
end
6565

66-
event[:ttl] ||= (options[:ttl] || (options[:interval] * 2))
66+
event[:ttl] ||= options[:ttl] || (options[:interval] * 2)
6767

6868
event[:host] = options[:event_host].dup if options[:event_host]
6969

lib/riemann/tools/bench.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def initialize
1515
@hosts = %w[a b c d e f g h i j]
1616
@services = %w[test1 test2 test3 foo bar baz xyzzy attack cat treat]
1717
@states = {}
18-
@client = Riemann::Client.new(host: (ARGV.first || 'localhost'))
18+
@client = Riemann::Client.new(host: ARGV.first || 'localhost')
1919
end
2020

2121
def evolve(state)

lib/riemann/tools/haproxy.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ def tick
4444
end
4545

4646
def csv
47+
CSV.parse(body.split('# ')[1], headers: true)
48+
end
49+
50+
def body
4751
http = ::Net::HTTP.new(@uri.host, @uri.port)
4852
http.use_ssl = true if @uri.scheme == 'https'
4953
res = http.start do |h|
@@ -53,8 +57,8 @@ def csv
5357
get.basic_auth userinfo[0], userinfo[1]
5458
end
5559
h.request get
60+
res.body
5661
end
57-
CSV.parse(res.body.split('# ')[1], { headers: true })
5862
end
5963
end
6064
end

lib/riemann/tools/net.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def tick
108108

109109
if @old_state
110110
# Report services from `@old_state` that don't exist in `state` as expired
111-
@old_state.reject { |k| state.key?(k) }.each do |service, _metric|
111+
@old_state.reject { |k| state.key?(k) }.each_key do |service|
112112
report(service: service.dup, state: 'expired')
113113
end
114114

spec/riemann/tools/haproxy_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# frozen_string_literal: true
2+
3+
require 'riemann/tools/haproxy'
4+
5+
RSpec.describe Riemann::Tools::Haproxy do
6+
context('#tick') do
7+
before do
8+
ARGV.replace(['--stats-url', 'http://localhost'])
9+
10+
allow(subject).to receive(:body).and_return(<<~DATA)
11+
# pxname,svname,qcur,qmax,scur,smax,slim,stot,bin,bout,dreq,dresp,ereq,econ,eresp,wretr,wredis,status,weight,act,bck,chkfail,chkdown,lastchg,downtime,qlimit,pid,iid,sid,throttle,lbtot,tracked,type,rate,rate_lim,rate_max,check_status,check_code,check_duration,hrsp_1xx,hrsp_2xx,hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,hanafail,req_rate,req_rate_max,req_tot,cli_abrt,srv_abrt,comp_in,comp_out,comp_byp,comp_rsp,lastsess,last_chk,last_agt,qtime,ctime,rtime,ttime,agent_status,agent_code,agent_duration,check_desc,agent_desc,check_rise,check_fall,check_health,agent_rise,agent_fall,agent_health,addr,cookie,mode,algo,conn_rate,conn_rate_max,conn_tot,intercepted,dcon,dses,wrew,connect,reuse,cache_lookups,cache_hits,srv_icur,src_ilim,qtime_max,ctime_max,rtime_max,ttime_max,eint,idle_conn_cur,safe_conn_cur,used_conn_cur,need_conn_est,
12+
ft-http,FRONTEND,,,0,24,8000,911,225427,282808,0,0,142,,,,,OPEN,,,,,,,,,1,2,0,,,,0,0,0,18,,,,0,0,86,142,1076,0,,0,46,1304,,,0,0,0,0,,,,,,,,,,,,,,,,,,,,,http,,0,18,911,0,0,0,0,,,0,0,,,,,,,0,,,,,
13+
ft-https,FRONTEND,,,4,23,8000,442138,1437985213,6885481212,0,0,49,,,,,OPEN,,,,,,,,,1,3,0,,,,0,2,0,41,,,,,,,,,,,0,0,0,,,0,0,0,0,,,,,,,,,,,,,,,,,,,,,tcp,,2,41,442138,,0,0,0,,,,,,,,,,,0,,,,,
14+
stats,FRONTEND,,,1,1,8000,15939,3235327,99009201,0,0,0,,,,,OPEN,,,,,,,,,1,4,0,,,,0,1,0,1,,,,0,15938,0,0,0,0,,1,1,15939,,,0,0,0,0,,,,,,,,,,,,,,,,,,,,,http,,1,1,15939,15939,0,0,0,,,0,0,,,,,,,0,,,,,
15+
DATA
16+
end
17+
18+
it 'reports ok state' do
19+
allow(subject).to receive(:report)
20+
subject.tick
21+
expect(subject).to have_received(:report).exactly(294).times
22+
end
23+
end
24+
end

0 commit comments

Comments
 (0)