lenjador 1.2.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +38 -0
- data/.travis.yml +0 -1
- data/Gemfile +1 -6
- data/Rakefile +6 -4
- data/benchmark/whitelisting.rb +7 -7
- data/lenjador.gemspec +19 -20
- data/lib/lenjador.rb +5 -3
- data/lib/lenjador/adapters.rb +11 -11
- data/lib/lenjador/adapters/stdout_adapter.rb +3 -1
- data/lib/lenjador/adapters/stdout_json_adapter.rb +10 -8
- data/lib/lenjador/null_logger.rb +7 -10
- data/lib/lenjador/preprocessors.rb +2 -0
- data/lib/lenjador/preprocessors/blacklist.rb +8 -7
- data/lib/lenjador/preprocessors/json_pointer_trie.rb +4 -2
- data/lib/lenjador/preprocessors/strategies/mask.rb +3 -1
- data/lib/lenjador/preprocessors/strategies/prune.rb +2 -0
- data/lib/lenjador/preprocessors/whitelist.rb +5 -5
- data/lib/lenjador/utils.rb +34 -7
- data/profiler/logs.rb +19 -0
- data/spec/{adapters → lenjador/adapters}/stdout_adapter_spec.rb +1 -1
- data/spec/{adapters → lenjador/adapters}/stdout_json_adapter_spec.rb +1 -1
- data/spec/{preprocessors → lenjador/preprocessors}/blacklist_spec.rb +18 -14
- data/spec/{preprocessors/json_pointer_trie.rb → lenjador/preprocessors/json_pointer_trie_spec.rb} +4 -4
- data/spec/lenjador/preprocessors/whitelist_spec.rb +335 -0
- data/spec/lenjador/utils_spec.rb +128 -0
- data/spec/lenjador_spec.rb +2 -8
- data/spec/spec_helper.rb +1 -1
- metadata +60 -16
- data/spec/preprocessors/whitelist_spec.rb +0 -335
- data/spec/utils_spec.rb +0 -84
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 10e0eaa5dd3548c6bfc7ff8c980e7e500ee4d297
|
4
|
+
data.tar.gz: c2dd081c02374b3144f3a7c77494c3f19b7ef464
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3766944053913a9345b4a8415f9de802c93de119affebd85fe43fe8696047ee656e586d84c6e0bf45cacdbcb376fafd443bea60c92728265f53c5bfa457daaa
|
7
|
+
data.tar.gz: e87536d2ccc0abf5176f474f782458877832b47335c30ae0d6f714bae688b10e934627446dc9d1a879a488c5e023585db1ba928575502ce2c962e9d19832c8cb
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
inherit_gem:
|
2
|
+
rubocop-salemove: config/default.yml
|
3
|
+
|
4
|
+
Style/FrozenStringLiteralComment:
|
5
|
+
Enabled: yes
|
6
|
+
EnforcedStyle: always
|
7
|
+
Include:
|
8
|
+
- 'lib/**/*'
|
9
|
+
|
10
|
+
Metrics/MethodLength:
|
11
|
+
Enabled: no
|
12
|
+
|
13
|
+
Style/GuardClause:
|
14
|
+
Enabled: no
|
15
|
+
|
16
|
+
RSpec/VerifiedDoubles:
|
17
|
+
Enabled: no
|
18
|
+
|
19
|
+
Metrics/BlockLength:
|
20
|
+
Enabled: no
|
21
|
+
|
22
|
+
RSpec/MessageSpies:
|
23
|
+
Enabled: no
|
24
|
+
|
25
|
+
RSpec/ExpectOutput:
|
26
|
+
Enabled: no
|
27
|
+
|
28
|
+
RSpec/ExampleLength:
|
29
|
+
Enabled: no
|
30
|
+
|
31
|
+
RSpec/MultipleExpectations:
|
32
|
+
Enabled: no
|
33
|
+
|
34
|
+
Style/SafeNavigation:
|
35
|
+
Enabled: no
|
36
|
+
|
37
|
+
Performance/RegexpMatch:
|
38
|
+
Enabled: no
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rubocop/rake_task'
|
3
|
+
require 'rspec/core/rake_task'
|
2
4
|
|
3
|
-
require "rspec/core/rake_task"
|
4
5
|
RSpec::Core::RakeTask.new(:spec)
|
5
6
|
|
6
|
-
|
7
|
-
|
7
|
+
RuboCop::RakeTask.new(:rubocop)
|
8
|
+
|
9
|
+
task default: %i[rubocop spec]
|
data/benchmark/whitelisting.rb
CHANGED
@@ -21,20 +21,20 @@ pointers = %w[
|
|
21
21
|
end
|
22
22
|
|
23
23
|
x.report("Flat hash whitelisting (action=#{action})") do
|
24
|
-
preprocessor.process(flat_hash: {
|
24
|
+
preprocessor.process(flat_hash: {scalar: 'value', array: [1, 2], hash: {}})
|
25
25
|
end
|
26
26
|
|
27
27
|
x.report("Nested hash whitelisting (action=#{action})") do
|
28
28
|
preprocessor.process(
|
29
29
|
nested_hash: {
|
30
30
|
next_level_hash: {
|
31
|
-
deep_hash: {
|
31
|
+
deep_hash: {scalar: 'value', array: [1, 2]}
|
32
32
|
},
|
33
33
|
next_level_hash2: {
|
34
|
-
deep_hash: {
|
34
|
+
deep_hash: {scalar: 'value', array: [1, 2]}
|
35
35
|
},
|
36
36
|
next_level_hash3: {
|
37
|
-
deep_hash: {
|
37
|
+
deep_hash: {scalar: 'value', array: [1, 2]}
|
38
38
|
}
|
39
39
|
}
|
40
40
|
)
|
@@ -43,9 +43,9 @@ pointers = %w[
|
|
43
43
|
x.report("Flat array whitelisting (action=#{action})") do
|
44
44
|
preprocessor.process(
|
45
45
|
nested_array: [
|
46
|
-
{
|
47
|
-
{
|
48
|
-
{
|
46
|
+
{deep_array: [1, 2, 3]},
|
47
|
+
{deep_array: [1, 2, 3]},
|
48
|
+
{deep_array: [1, 2, 3]}
|
49
49
|
]
|
50
50
|
)
|
51
51
|
end
|
data/lenjador.gemspec
CHANGED
@@ -1,25 +1,21 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
|
5
6
|
Gem::Specification.new do |gem|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
gem.
|
13
|
-
gem.authors = ["Salemove"]
|
14
|
-
gem.email = ["support@salemove.com"]
|
15
|
-
gem.description = %q{It's lenjadoric}
|
16
|
-
gem.summary = %q{What description said}
|
17
|
-
gem.license = "MIT"
|
7
|
+
gem.name = RUBY_PLATFORM =~ /java/ ? 'lenjador-jruby' : 'lenjador'
|
8
|
+
gem.version = '1.3.0'
|
9
|
+
gem.authors = ['Salemove']
|
10
|
+
gem.email = ['support@salemove.com']
|
11
|
+
gem.description = "It's lenjadoric"
|
12
|
+
gem.summary = 'What description said'
|
13
|
+
gem.license = 'MIT'
|
18
14
|
|
19
|
-
gem.files = `git ls-files`.split(
|
15
|
+
gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
20
16
|
gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
21
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
22
|
-
gem.require_paths = [
|
18
|
+
gem.require_paths = ['lib']
|
23
19
|
|
24
20
|
gem.add_dependency 'lru_redux'
|
25
21
|
|
@@ -27,10 +23,13 @@ Gem::Specification.new do |gem|
|
|
27
23
|
gem.add_dependency 'jrjackson'
|
28
24
|
else
|
29
25
|
gem.add_dependency 'oj'
|
26
|
+
gem.add_development_dependency 'ruby-prof'
|
30
27
|
end
|
31
28
|
|
32
|
-
gem.add_development_dependency
|
33
|
-
gem.add_development_dependency
|
34
|
-
gem.add_development_dependency
|
35
|
-
gem.add_development_dependency
|
29
|
+
gem.add_development_dependency 'benchmark-ips'
|
30
|
+
gem.add_development_dependency 'bundler', '~> 1.3'
|
31
|
+
gem.add_development_dependency 'pry'
|
32
|
+
gem.add_development_dependency 'rake'
|
33
|
+
gem.add_development_dependency 'rspec'
|
34
|
+
gem.add_development_dependency 'rubocop-salemove'
|
36
35
|
end
|
data/lib/lenjador.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'logger'
|
2
4
|
require_relative 'lenjador/adapters'
|
3
5
|
require_relative 'lenjador/utils'
|
4
6
|
require_relative 'lenjador/null_logger'
|
5
7
|
require_relative 'lenjador/preprocessors'
|
6
8
|
|
7
|
-
LOG_LEVEL_QUERY_METHODS = [
|
9
|
+
LOG_LEVEL_QUERY_METHODS = %i[debug? info? warn? error? fatal?].freeze
|
8
10
|
|
9
11
|
class Lenjador
|
10
12
|
def self.build(service_name, loggers_config, preprocessors_config = {})
|
@@ -45,7 +47,7 @@ class Lenjador
|
|
45
47
|
|
46
48
|
LOG_LEVEL_QUERY_METHODS.each do |method|
|
47
49
|
define_method(method) do
|
48
|
-
@adapters.any? {|adapter| adapter.public_send(method) }
|
50
|
+
@adapters.any? { |adapter| adapter.public_send(method) }
|
49
51
|
end
|
50
52
|
end
|
51
53
|
|
@@ -69,6 +71,6 @@ class Lenjador
|
|
69
71
|
def parse_log_data(message = nil, metadata = {}, &block)
|
70
72
|
return message if message.is_a?(Hash)
|
71
73
|
|
72
|
-
(metadata || {}).merge(message: block ?
|
74
|
+
(metadata || {}).merge(message: block ? yield : message)
|
73
75
|
end
|
74
76
|
end
|
data/lib/lenjador/adapters.rb
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Lenjador
|
2
4
|
module Adapters
|
3
|
-
LOG_LEVELS = %
|
5
|
+
LOG_LEVELS = %i[debug info warn error fatal unknown].freeze
|
4
6
|
|
5
7
|
def self.get(type, service_name, arguments)
|
8
|
+
raise "Unsupported logger: #{type}" if type != 'stdout'
|
9
|
+
|
6
10
|
adapter =
|
7
|
-
if
|
8
|
-
|
9
|
-
|
10
|
-
StdoutJsonAdapter
|
11
|
-
else
|
12
|
-
require_relative 'adapters/stdout_adapter'
|
13
|
-
StdoutAdapter
|
14
|
-
end
|
11
|
+
if arguments.fetch(:json, false)
|
12
|
+
require_relative 'adapters/stdout_json_adapter'
|
13
|
+
StdoutJsonAdapter
|
15
14
|
else
|
16
|
-
|
15
|
+
require_relative 'adapters/stdout_adapter'
|
16
|
+
StdoutAdapter
|
17
17
|
end
|
18
|
-
level = LOG_LEVELS.index(arguments.fetch(:level,
|
18
|
+
level = LOG_LEVELS.index(arguments.fetch(:level, :debug).to_sym)
|
19
19
|
adapter.new(level, service_name, arguments)
|
20
20
|
end
|
21
21
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'forwardable'
|
2
4
|
|
3
5
|
class Lenjador
|
@@ -16,7 +18,7 @@ class Lenjador
|
|
16
18
|
|
17
19
|
def log(level, metadata = {})
|
18
20
|
message = metadata[:message]
|
19
|
-
data = metadata.
|
21
|
+
data = metadata.reject { |key, _value| key == :message }
|
20
22
|
log_data = [
|
21
23
|
message,
|
22
24
|
data.empty? ? nil : Utils.generate_json(data)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Lenjador
|
2
4
|
module Adapters
|
3
5
|
class StdoutJsonAdapter
|
@@ -5,14 +7,14 @@ class Lenjador
|
|
5
7
|
@level = level
|
6
8
|
@service_name = service_name
|
7
9
|
@application_name = Utils.application_name(service_name)
|
8
|
-
@mutex = Mutex.new if RUBY_ENGINE ==
|
10
|
+
@mutex = Mutex.new if RUBY_ENGINE == 'jruby'
|
9
11
|
end
|
10
12
|
|
11
13
|
def log(level, metadata = {})
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
return unless meets_threshold?(level)
|
15
|
+
|
16
|
+
message = Utils.build_event(metadata, level, @application_name)
|
17
|
+
print_line(Utils.generate_json(message))
|
16
18
|
end
|
17
19
|
|
18
20
|
def debug?
|
@@ -38,15 +40,15 @@ class Lenjador
|
|
38
40
|
private
|
39
41
|
|
40
42
|
def meets_threshold?(level)
|
41
|
-
LOG_LEVELS.index(level
|
43
|
+
LOG_LEVELS.index(level) >= @level
|
42
44
|
end
|
43
45
|
|
44
46
|
# puts is atomic in MRI starting from 2.5.0
|
45
|
-
if RUBY_ENGINE ==
|
47
|
+
if RUBY_ENGINE == 'ruby' && RUBY_VERSION >= '2.5.0'
|
46
48
|
def print_line(str)
|
47
49
|
$stdout.puts(str)
|
48
50
|
end
|
49
|
-
elsif RUBY_ENGINE ==
|
51
|
+
elsif RUBY_ENGINE == 'jruby'
|
50
52
|
def print_line(str)
|
51
53
|
@mutex.synchronize { $stdout.write(str + "\n") }
|
52
54
|
end
|
data/lib/lenjador/null_logger.rb
CHANGED
@@ -1,18 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Lenjador
|
2
4
|
class NullLogger
|
3
|
-
def debug(*)
|
4
|
-
end
|
5
|
+
def debug(*); end
|
5
6
|
|
6
|
-
def info(*)
|
7
|
-
end
|
7
|
+
def info(*); end
|
8
8
|
|
9
|
-
def warn(*)
|
10
|
-
end
|
9
|
+
def warn(*); end
|
11
10
|
|
12
|
-
def error(*)
|
13
|
-
end
|
11
|
+
def error(*); end
|
14
12
|
|
15
|
-
def fatal(*)
|
16
|
-
end
|
13
|
+
def fatal(*); end
|
17
14
|
end
|
18
15
|
end
|
@@ -1,12 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Lenjador
|
2
4
|
module Preprocessors
|
3
5
|
class Blacklist
|
4
|
-
|
5
6
|
DEFAULT_ACTION = 'prune'
|
6
7
|
MASK_SYMBOL = '*'
|
7
8
|
MASKED_VALUE = MASK_SYMBOL * 5
|
8
9
|
|
9
|
-
class UnsupportedActionException <
|
10
|
+
class UnsupportedActionException < RuntimeError
|
10
11
|
end
|
11
12
|
|
12
13
|
def initialize(config = {})
|
@@ -22,7 +23,7 @@ class Lenjador
|
|
22
23
|
if data.is_a? Hash
|
23
24
|
data.inject({}) do |mem, (key, val)|
|
24
25
|
if (field = @fields_to_process[key.to_s])
|
25
|
-
|
26
|
+
send(action_method(field[:action]), mem, key, val)
|
26
27
|
else
|
27
28
|
mem.merge(key => process(val))
|
28
29
|
end
|
@@ -43,19 +44,19 @@ class Lenjador
|
|
43
44
|
end
|
44
45
|
|
45
46
|
def validate_action_supported(action)
|
46
|
-
unless
|
47
|
-
raise UnsupportedActionException
|
47
|
+
unless respond_to?(action_method(action).to_sym, true)
|
48
|
+
raise UnsupportedActionException, "Action: #{action} is not supported"
|
48
49
|
end
|
49
50
|
end
|
50
51
|
|
51
|
-
def mask_field(data, key,
|
52
|
+
def mask_field(data, key, _val)
|
52
53
|
data.merge(key => MASKED_VALUE)
|
53
54
|
end
|
54
55
|
|
55
56
|
def prune_field(data, *)
|
56
57
|
data
|
57
58
|
end
|
58
|
-
|
59
|
+
alias exclude_field prune_field
|
59
60
|
end
|
60
61
|
end
|
61
62
|
end
|
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'lru_redux'
|
2
4
|
|
3
5
|
class Lenjador
|
4
6
|
module Preprocessors
|
5
7
|
class JSONPointerTrie
|
6
|
-
SEPARATOR = '/'
|
7
|
-
WILDCARD = '~'
|
8
|
+
SEPARATOR = '/'
|
9
|
+
WILDCARD = '~'
|
8
10
|
DEFAULT_CACHE_SIZE = 100
|
9
11
|
|
10
12
|
def initialize(cache_size: DEFAULT_CACHE_SIZE, **)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'lenjador/preprocessors/json_pointer_trie'
|
2
4
|
require 'lenjador/preprocessors/strategies/mask'
|
3
5
|
require 'lenjador/preprocessors/strategies/prune'
|
@@ -6,12 +8,12 @@ class Lenjador
|
|
6
8
|
module Preprocessors
|
7
9
|
class Whitelist
|
8
10
|
DEFAULT_WHITELIST = %w[/id /message /correlation_id /queue].freeze
|
9
|
-
MASK_SYMBOL = '*'
|
11
|
+
MASK_SYMBOL = '*'
|
10
12
|
MASKED_VALUE = MASK_SYMBOL * 5
|
11
13
|
|
12
14
|
PRUNE_ACTION_NAMES = %w[prune exclude].freeze
|
13
15
|
|
14
|
-
class InvalidPointerFormatException <
|
16
|
+
class InvalidPointerFormatException < RuntimeError
|
15
17
|
end
|
16
18
|
|
17
19
|
def initialize(config = {})
|
@@ -31,9 +33,7 @@ class Lenjador
|
|
31
33
|
private
|
32
34
|
|
33
35
|
def validate_pointer(pointer)
|
34
|
-
if pointer.slice(-1) == '/'
|
35
|
-
raise InvalidPointerFormatException, 'Pointer should not contain trailing slash'
|
36
|
-
end
|
36
|
+
raise InvalidPointerFormatException, 'Pointer should not contain trailing slash' if pointer.slice(-1) == '/'
|
37
37
|
end
|
38
38
|
|
39
39
|
def decode(pointer)
|