logjam_agent 0.28.0 → 0.29.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -5
- data/lib/logjam_agent/version.rb +1 -1
- data/lib/logjam_agent.rb +30 -2
- data/logjam_agent.gemspec +1 -0
- data/test/zmq_forwarder_test.rb +23 -1
- metadata +17 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24a410b2cc2884bdb2ad87c3219db9cc1c78b0b050e7a8161288a1f13146cdcf
|
4
|
+
data.tar.gz: c9dab061fe5360f6ff7db1784c1d0ff2c972b2b2a9486e0e689bc0068d6e9871
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 351db0a9ab580febe99e11c2616e099817445ff698a2a26da7b5233497532a4abb49545949794dca173e54127e043f819c8040d9470abf295ee7fcd155360fba
|
7
|
+
data.tar.gz: 0e1c1387cb78caa5a84e2dcb6945558600ea5a3d613d66104ddaed9d1336d403f859e8295afcbe1eb8975370f408651b0a0a425f1c421b428dbad04c09cb4eb9
|
data/README.md
CHANGED
@@ -93,11 +93,13 @@ module LogjamAgent
|
|
93
93
|
self.max_bytes_all_lines = 1024 * 1024
|
94
94
|
|
95
95
|
# Configure compression method. Defaults to NO_COMPRESSION. Available
|
96
|
-
# compression methods are ZLIB_COMPRESSION
|
97
|
-
# Snappy
|
98
|
-
# higher compression rates.
|
96
|
+
# compression methods are ZLIB_COMPRESSION, SNAPPY_COMPRESSION, LZ4_COMPRESSION.
|
97
|
+
# Snappy and LZ4 are faster and less CPU intensive than ZLIB, ZLIB achieves
|
98
|
+
# higher compression rates. LZ4 is faster to decompress than Snappy
|
99
|
+
# and recommended.
|
99
100
|
# self.compression_method = ZLIB_COMPRESSION
|
100
101
|
# self.compression_method = SNAPPY_COMPRESSION
|
102
|
+
# self.compression_method = LZ4_COMPRESSION
|
101
103
|
|
102
104
|
# Activate the split between hard and soft-exceptions. Soft exceptions are
|
103
105
|
# all exceptions below a log level of Logger::ERROR. Logjam itself can then
|
@@ -110,7 +112,7 @@ end
|
|
110
112
|
|
111
113
|
The agent generates unique request ids for all request handled. It
|
112
114
|
will use [uuid4r](https://github.com/skaes/uuid4r) if this is
|
113
|
-
|
115
|
+
available in the application. Otherwise it will fall back to use the
|
114
116
|
standard `SecureRandom` class shipped with Ruby.
|
115
117
|
|
116
118
|
### Generating JSON
|
@@ -135,7 +137,7 @@ LogjamAgent.error_handler = lambda {|exception| ... }
|
|
135
137
|
|
136
138
|
The MIT License
|
137
139
|
|
138
|
-
Copyright (c) 2013 -
|
140
|
+
Copyright (c) 2013 - 2019 Stefan Kaes
|
139
141
|
|
140
142
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
141
143
|
of this software and associated documentation files (the "Software"), to deal
|
data/lib/logjam_agent/version.rb
CHANGED
data/lib/logjam_agent.rb
CHANGED
@@ -117,6 +117,7 @@ module LogjamAgent
|
|
117
117
|
NO_COMPRESSION = 0
|
118
118
|
ZLIB_COMPRESSION = 1
|
119
119
|
SNAPPY_COMPRESSION = 2
|
120
|
+
LZ4_COMPRESSION= 3
|
120
121
|
|
121
122
|
mattr_reader :compression_method
|
122
123
|
def self.compression_method=(compression_method)
|
@@ -128,6 +129,13 @@ module LogjamAgent
|
|
128
129
|
rescue LoadError
|
129
130
|
# do nothing
|
130
131
|
end
|
132
|
+
when LZ4_COMPRESSION
|
133
|
+
begin
|
134
|
+
require "ruby-lz4"
|
135
|
+
@@compression_method = LZ4_COMPRESSION
|
136
|
+
rescue LoadError
|
137
|
+
# do nothing
|
138
|
+
end
|
131
139
|
when NO_COMPRESSION, ZLIB_COMPRESSION
|
132
140
|
@@compression_method = compression_method
|
133
141
|
else
|
@@ -245,15 +253,35 @@ module LogjamAgent
|
|
245
253
|
def self.encode_payload(data)
|
246
254
|
json = json_encode_payload(data)
|
247
255
|
case compression_method
|
248
|
-
when ZLIB_COMPRESSION
|
249
|
-
ActiveSupport::Gzip.compress(json)
|
250
256
|
when SNAPPY_COMPRESSION
|
251
257
|
Snappy.deflate(json)
|
258
|
+
when LZ4_COMPRESSION
|
259
|
+
n = data.byte_size
|
260
|
+
max_compressed_size = n + n/256 + 16
|
261
|
+
buf = String.new([n].pack("N"), capacity: max_compressed_size + 4)
|
262
|
+
LZ4::Raw.compress(json, input_size: n, dest: buf, max_ouput_size: max_compressed_size).first
|
263
|
+
when ZLIB_COMPRESSION
|
264
|
+
ActiveSupport::Gzip.compress(json)
|
252
265
|
else
|
253
266
|
json
|
254
267
|
end
|
255
268
|
end
|
256
269
|
|
270
|
+
def self.decode_payload(data)
|
271
|
+
case compression_method
|
272
|
+
when SNAPPY_COMPRESSION
|
273
|
+
Snappy.inflate(data)
|
274
|
+
when LZ4_COMPRESSION
|
275
|
+
uncompressed_size = data[0..3].unpack("N")
|
276
|
+
buf = String.new("", capacity: uncompressed_size)
|
277
|
+
LZ4::Raw.decompress(data[4..-1], uncompressed_size, dest: buf).first
|
278
|
+
when ZLIB_COMPRESSION
|
279
|
+
ActiveSupport::Gzip.decompress(data)
|
280
|
+
else
|
281
|
+
data
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
257
285
|
def self.event(label, extra_fields = {})
|
258
286
|
fields = {
|
259
287
|
:label => label,
|
data/logjam_agent.gemspec
CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.add_development_dependency "rake"
|
22
22
|
s.add_development_dependency "i18n"
|
23
23
|
s.add_development_dependency "snappy"
|
24
|
+
s.add_development_dependency "lz4-ruby"
|
24
25
|
s.add_development_dependency "oj"
|
25
26
|
s.add_development_dependency "byebug"
|
26
27
|
s.add_development_dependency "minitest"
|
data/test/zmq_forwarder_test.rb
CHANGED
@@ -30,7 +30,29 @@ module LogjamAgent
|
|
30
30
|
normal_msg = LogjamAgent.encode_payload(data)
|
31
31
|
LogjamAgent.compression_method = SNAPPY_COMPRESSION
|
32
32
|
compressed_msg = LogjamAgent.encode_payload(data)
|
33
|
-
assert_equal normal_msg,
|
33
|
+
assert_equal normal_msg, LogjamAgent.decode_payload(compressed_msg)
|
34
|
+
f = ZMQForwarder.new
|
35
|
+
f.expects(:publish).with("a-b", "x", compressed_msg)
|
36
|
+
f.forward(data, :routing_key => "x", :app_env => "a-b")
|
37
|
+
end
|
38
|
+
|
39
|
+
test "compressed message using lz4 can be uncompressed" do
|
40
|
+
data = {a: 1, b: "str"}
|
41
|
+
normal_msg = LogjamAgent.encode_payload(data)
|
42
|
+
LogjamAgent.compression_method = LZ4_COMPRESSION
|
43
|
+
compressed_msg = LogjamAgent.encode_payload(data)
|
44
|
+
assert_equal normal_msg, LogjamAgent.decode_payload(compressed_msg)
|
45
|
+
f = ZMQForwarder.new
|
46
|
+
f.expects(:publish).with("a-b", "x", compressed_msg)
|
47
|
+
f.forward(data, :routing_key => "x", :app_env => "a-b")
|
48
|
+
end
|
49
|
+
|
50
|
+
test "compressed message using zlib can be uncompressed" do
|
51
|
+
data = {a: 1, b: "str"}
|
52
|
+
normal_msg = LogjamAgent.encode_payload(data)
|
53
|
+
LogjamAgent.compression_method = ZLIB_COMPRESSION
|
54
|
+
compressed_msg = LogjamAgent.encode_payload(data)
|
55
|
+
assert_equal normal_msg, LogjamAgent.decode_payload(compressed_msg)
|
34
56
|
f = ZMQForwarder.new
|
35
57
|
f.expects(:publish).with("a-b", "x", compressed_msg)
|
36
58
|
f.forward(data, :routing_key => "x", :app_env => "a-b")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logjam_agent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.29.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefan Kaes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: lz4-ruby
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: oj
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -211,8 +225,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
211
225
|
- !ruby/object:Gem::Version
|
212
226
|
version: '0'
|
213
227
|
requirements: []
|
214
|
-
|
215
|
-
rubygems_version: 2.7.8
|
228
|
+
rubygems_version: 3.0.3
|
216
229
|
signing_key:
|
217
230
|
specification_version: 4
|
218
231
|
summary: Logjam client library to be used with logjam
|