logjam_agent 0.29.4 → 0.32.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 +49 -28
- data/Rakefile +5 -0
- data/lib/logjam_agent.rb +13 -4
- data/lib/logjam_agent/active_support/core_ext/array/extract.rb +21 -0
- data/lib/logjam_agent/active_support/parameter_filter.rb +128 -0
- data/lib/logjam_agent/buffered_logger.rb +17 -42
- data/lib/logjam_agent/middleware.rb +16 -4
- data/lib/logjam_agent/rack/logger.rb +19 -81
- data/lib/logjam_agent/rack/rails_support.rb +26 -0
- data/lib/logjam_agent/rack/sinatra_request.rb +32 -0
- data/lib/logjam_agent/railtie.rb +3 -0
- data/lib/logjam_agent/receiver.rb +22 -0
- data/lib/logjam_agent/sinatra.rb +116 -0
- data/lib/logjam_agent/syslog_like_formatter.rb +15 -7
- data/lib/logjam_agent/util.rb +6 -1
- data/lib/logjam_agent/version.rb +1 -1
- data/lib/logjam_agent/zmq_forwarder.rb +49 -28
- data/test/sinatra_app.rb +32 -0
- data/test/sinatra_classic_app.rb +31 -0
- data/test/sinatra_classic_test.rb +20 -0
- data/test/sinatra_test.rb +54 -0
- data/test/test_helper.rb +8 -3
- data/test/util_test.rb +5 -0
- metadata +69 -16
- data/.gitignore +0 -5
- data/Gemfile +0 -4
- data/logjam_agent.gemspec +0 -34
- data/script/console +0 -28
data/test/sinatra_app.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
$:.unshift File.expand_path('../../lib', __FILE__)
|
2
|
+
|
3
|
+
require 'logjam_agent/sinatra'
|
4
|
+
|
5
|
+
class SinatraTestApp < Sinatra::Base
|
6
|
+
register LogjamAgent::Sinatra
|
7
|
+
|
8
|
+
use LogjamAgent::Sinatra::Middleware
|
9
|
+
|
10
|
+
configure do
|
11
|
+
set :root, File.expand_path('../..', __FILE__)
|
12
|
+
set :environment, :test
|
13
|
+
set :loglevel, :debug
|
14
|
+
setup_logjam_logger
|
15
|
+
|
16
|
+
LogjamAgent.application_name = "myapp"
|
17
|
+
LogjamAgent.add_forwarder(:zmq, :host => "inproc://app")
|
18
|
+
LogjamAgent.parameter_filters << :password
|
19
|
+
LogjamAgent.ensure_ping_at_exit = false
|
20
|
+
end
|
21
|
+
|
22
|
+
before '/index' do
|
23
|
+
action_name "Simple#index"
|
24
|
+
end
|
25
|
+
|
26
|
+
get '/index' do
|
27
|
+
logger.info 'Hello World!'
|
28
|
+
'Hello World!'
|
29
|
+
end
|
30
|
+
|
31
|
+
run! if __FILE__ == $0
|
32
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
$:.unshift File.expand_path('../../lib', __FILE__)
|
2
|
+
|
3
|
+
require 'logjam_agent/sinatra'
|
4
|
+
|
5
|
+
use LogjamAgent::Sinatra::Middleware
|
6
|
+
|
7
|
+
configure do
|
8
|
+
set :root, File.expand_path('../..', __FILE__)
|
9
|
+
set :environment, :test
|
10
|
+
set :loglevel, :debug
|
11
|
+
setup_logjam_logger
|
12
|
+
|
13
|
+
LogjamAgent.application_name = "myapp"
|
14
|
+
LogjamAgent.add_forwarder(
|
15
|
+
:zmq,
|
16
|
+
:host => "localhost",
|
17
|
+
:port => 9604,
|
18
|
+
:linger => 10,
|
19
|
+
:snd_hwm => 10,
|
20
|
+
:rcv_hwm => 10,
|
21
|
+
:rcv_timeo => 10,
|
22
|
+
:snd_timeo => 10
|
23
|
+
)
|
24
|
+
LogjamAgent.parameter_filters << :password
|
25
|
+
end
|
26
|
+
|
27
|
+
get '/index' do
|
28
|
+
action_name "Simple#index"
|
29
|
+
logger.info 'Hello World!'
|
30
|
+
'Hello World!'
|
31
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative "test_helper.rb"
|
2
|
+
require_relative "sinatra_classic_app"
|
3
|
+
require "rack/test"
|
4
|
+
|
5
|
+
module LogjamAgent
|
6
|
+
class SinatraClassicTest < MiniTest::Test
|
7
|
+
|
8
|
+
include ::Rack::Test::Methods
|
9
|
+
|
10
|
+
def app
|
11
|
+
::Sinatra::Application
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_root
|
15
|
+
get '/index?mumu=1&password=5'
|
16
|
+
assert_equal 'Hello World!', last_response.body
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require_relative "test_helper.rb"
|
2
|
+
require_relative "sinatra_app"
|
3
|
+
require "rack/test"
|
4
|
+
|
5
|
+
module LogjamAgent
|
6
|
+
class SinatraTest < MiniTest::Test
|
7
|
+
def setup
|
8
|
+
@@receiver ||= LogjamAgent::Receiver.new
|
9
|
+
LogjamAgent.enable!
|
10
|
+
end
|
11
|
+
|
12
|
+
def teardown
|
13
|
+
LogjamAgent.disable!
|
14
|
+
end
|
15
|
+
|
16
|
+
def logjam_message
|
17
|
+
@@receiver.receive
|
18
|
+
end
|
19
|
+
|
20
|
+
include ::Rack::Test::Methods
|
21
|
+
|
22
|
+
def app
|
23
|
+
SinatraTestApp
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_root
|
27
|
+
get '/index?mumu=1&password=5'
|
28
|
+
assert_equal 'Hello World!', last_response.body
|
29
|
+
assert_equal 200, last_response.status
|
30
|
+
|
31
|
+
stream, topic, payload = logjam_message
|
32
|
+
assert_equal "myapp-test", stream
|
33
|
+
assert_equal "logs.myapp.test", topic
|
34
|
+
assert_equal 200, payload["code"]
|
35
|
+
assert_equal "Simple#index", payload["action"]
|
36
|
+
assert_kind_of Float, payload["total_time"]
|
37
|
+
assert_kind_of String, payload["started_at"]
|
38
|
+
assert_kind_of Integer, payload["started_ms"]
|
39
|
+
assert_kind_of String, payload["ip"]
|
40
|
+
# assert_kind_of Float, payload["view_time"]
|
41
|
+
lines = payload["lines"]
|
42
|
+
assert_match(/Started GET.*password=\[FILTERED\]/, lines[0][2])
|
43
|
+
assert_match(/Hello World/, lines[1][2])
|
44
|
+
assert_match(/Completed 200 OK/, lines[2][2])
|
45
|
+
assert_nil(lines[3])
|
46
|
+
request_info = payload["request_info"]
|
47
|
+
method, url, query_parameters = request_info.values_at(*%w(method url query_parameters))
|
48
|
+
assert_equal method, "GET"
|
49
|
+
assert_equal url, "/index?mumu=1&password=[FILTERED]"
|
50
|
+
assert_equal(query_parameters, { "mumu" => "1", "password" => "[FILTERED]" })
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -1,11 +1,16 @@
|
|
1
1
|
require 'minitest/autorun'
|
2
2
|
require 'minitest/unit'
|
3
3
|
require 'minitest/pride' if ENV['RAINBOW_COLORED_TESTS'] == "1" && $stdout.tty?
|
4
|
-
require 'mocha/
|
5
|
-
|
6
|
-
require_relative "../lib/logjam_agent"
|
4
|
+
require 'mocha/minitest'
|
7
5
|
|
8
6
|
class MiniTest::Test
|
9
7
|
require "active_support/testing/declarative"
|
10
8
|
extend ActiveSupport::Testing::Declarative
|
11
9
|
end
|
10
|
+
|
11
|
+
$:.unshift File.expand_path('../../lib', __FILE__)
|
12
|
+
require "logjam_agent"
|
13
|
+
require "logjam_agent/receiver"
|
14
|
+
|
15
|
+
# for Sinatra
|
16
|
+
ENV['RACK_ENV'] = "test"
|
data/test/util_test.rb
CHANGED
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.32.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefan Kaes
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -122,6 +122,48 @@ dependencies:
|
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: sinatra
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rack-test
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: appraisal
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
125
167
|
- !ruby/object:Gem::Dependency
|
126
168
|
name: activesupport
|
127
169
|
requirement: !ruby/object:Gem::Requirement
|
@@ -142,14 +184,14 @@ dependencies:
|
|
142
184
|
requirements:
|
143
185
|
- - ">="
|
144
186
|
- !ruby/object:Gem::Version
|
145
|
-
version: 0.
|
187
|
+
version: 0.12.2
|
146
188
|
type: :runtime
|
147
189
|
prerelease: false
|
148
190
|
version_requirements: !ruby/object:Gem::Requirement
|
149
191
|
requirements:
|
150
192
|
- - ">="
|
151
193
|
- !ruby/object:Gem::Version
|
152
|
-
version: 0.
|
194
|
+
version: 0.12.2
|
153
195
|
- !ruby/object:Gem::Dependency
|
154
196
|
name: ffi-rzmq-core
|
155
197
|
requirement: !ruby/object:Gem::Requirement
|
@@ -185,32 +227,39 @@ executables: []
|
|
185
227
|
extensions: []
|
186
228
|
extra_rdoc_files: []
|
187
229
|
files:
|
188
|
-
- ".gitignore"
|
189
|
-
- Gemfile
|
190
230
|
- README.md
|
191
231
|
- Rakefile
|
192
232
|
- lib/logjam_agent.rb
|
193
233
|
- lib/logjam_agent/actionpack/lib/action_dispatch/middleware/remote_ip.rb
|
234
|
+
- lib/logjam_agent/active_support/core_ext/array/extract.rb
|
235
|
+
- lib/logjam_agent/active_support/parameter_filter.rb
|
194
236
|
- lib/logjam_agent/buffered_logger.rb
|
195
237
|
- lib/logjam_agent/forwarders.rb
|
196
238
|
- lib/logjam_agent/middleware.rb
|
197
239
|
- lib/logjam_agent/rack/logger.rb
|
240
|
+
- lib/logjam_agent/rack/rails_support.rb
|
241
|
+
- lib/logjam_agent/rack/sinatra_request.rb
|
198
242
|
- lib/logjam_agent/railtie.rb
|
243
|
+
- lib/logjam_agent/receiver.rb
|
199
244
|
- lib/logjam_agent/request.rb
|
245
|
+
- lib/logjam_agent/sinatra.rb
|
200
246
|
- lib/logjam_agent/syslog_like_formatter.rb
|
201
247
|
- lib/logjam_agent/util.rb
|
202
248
|
- lib/logjam_agent/version.rb
|
203
249
|
- lib/logjam_agent/zmq_forwarder.rb
|
204
|
-
- logjam_agent.gemspec
|
205
|
-
- script/console
|
206
250
|
- test/request_test.rb
|
251
|
+
- test/sinatra_app.rb
|
252
|
+
- test/sinatra_classic_app.rb
|
253
|
+
- test/sinatra_classic_test.rb
|
254
|
+
- test/sinatra_test.rb
|
207
255
|
- test/test_helper.rb
|
208
256
|
- test/util_test.rb
|
209
257
|
- test/zmq_forwarder_test.rb
|
210
|
-
homepage:
|
211
|
-
licenses:
|
258
|
+
homepage: https://github.com/skaes/logjam_agent
|
259
|
+
licenses:
|
260
|
+
- MIT
|
212
261
|
metadata: {}
|
213
|
-
post_install_message:
|
262
|
+
post_install_message:
|
214
263
|
rdoc_options: []
|
215
264
|
require_paths:
|
216
265
|
- lib
|
@@ -225,12 +274,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
225
274
|
- !ruby/object:Gem::Version
|
226
275
|
version: '0'
|
227
276
|
requirements: []
|
228
|
-
rubygems_version: 3.
|
229
|
-
signing_key:
|
277
|
+
rubygems_version: 3.1.2
|
278
|
+
signing_key:
|
230
279
|
specification_version: 4
|
231
280
|
summary: Logjam client library to be used with logjam
|
232
281
|
test_files:
|
282
|
+
- test/sinatra_app.rb
|
283
|
+
- test/sinatra_classic_test.rb
|
284
|
+
- test/sinatra_classic_app.rb
|
233
285
|
- test/request_test.rb
|
234
|
-
- test/test_helper.rb
|
235
|
-
- test/util_test.rb
|
236
286
|
- test/zmq_forwarder_test.rb
|
287
|
+
- test/util_test.rb
|
288
|
+
- test/test_helper.rb
|
289
|
+
- test/sinatra_test.rb
|
data/Gemfile
DELETED
data/logjam_agent.gemspec
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
$:.push File.expand_path("../lib", __FILE__)
|
3
|
-
require "logjam_agent/version"
|
4
|
-
|
5
|
-
Gem::Specification.new do |s|
|
6
|
-
s.name = "logjam_agent"
|
7
|
-
s.version = LogjamAgent::VERSION
|
8
|
-
s.authors = ["Stefan Kaes"]
|
9
|
-
s.email = ["stefan.kaes@xing.com"]
|
10
|
-
s.homepage = ""
|
11
|
-
s.summary = %q{Logjam client library to be used with logjam}
|
12
|
-
s.description = %q{Logjam logger and request information forwarding}
|
13
|
-
|
14
|
-
s.rubyforge_project = "logjam_agent"
|
15
|
-
|
16
|
-
s.files = `git ls-files`.split("\n")
|
17
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
-
s.require_paths = ["lib"]
|
20
|
-
|
21
|
-
s.add_development_dependency "rake"
|
22
|
-
s.add_development_dependency "i18n"
|
23
|
-
s.add_development_dependency "snappy"
|
24
|
-
s.add_development_dependency "lz4-ruby"
|
25
|
-
s.add_development_dependency "oj"
|
26
|
-
s.add_development_dependency "byebug"
|
27
|
-
s.add_development_dependency "minitest"
|
28
|
-
s.add_development_dependency "mocha"
|
29
|
-
|
30
|
-
s.add_runtime_dependency "activesupport"
|
31
|
-
s.add_runtime_dependency "time_bandits", [">= 0.6.0"]
|
32
|
-
s.add_runtime_dependency "ffi-rzmq-core", [">= 1.0.5"]
|
33
|
-
s.add_runtime_dependency "ffi-rzmq", [">= 2.0.4"]
|
34
|
-
end
|
data/script/console
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require 'optparse'
|
3
|
-
|
4
|
-
options = { }
|
5
|
-
OptionParser.new do |opt|
|
6
|
-
opt.banner = "Usage: console [options]"
|
7
|
-
opt.on("--debugger", 'Enable ruby-debugging for the console.') { |v| options[:debugger] = v }
|
8
|
-
opt.parse!(ARGV)
|
9
|
-
end
|
10
|
-
|
11
|
-
lib_dir = File.expand_path("../../lib/", __FILE__)
|
12
|
-
libs = " -r irb/completion"
|
13
|
-
libs << " -I #{lib_dir}"
|
14
|
-
libs << " -r #{lib_dir}/logjam_agent.rb"
|
15
|
-
|
16
|
-
if options[:debugger]
|
17
|
-
begin
|
18
|
-
require 'byebug'
|
19
|
-
libs << " -r byebug"
|
20
|
-
puts "=> Debugger enabled"
|
21
|
-
rescue Exception
|
22
|
-
puts "You need to install ruby-debug to run the console in debugging mode. With gems, use 'gem install ruby-debug'"
|
23
|
-
exit
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
28
|
-
exec "#{irb} #{libs} --simple-prompt"
|