franz 1.6.5 → 1.6.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 15ec73cb6037c16c59a295c5d1e17160edfcff2b
4
- data.tar.gz: 0e68faaa4df6f3d52d4f563c288aeca74b7cb72c
3
+ metadata.gz: b85070420e513988180b780d2a8a38d1b9814d34
4
+ data.tar.gz: 6737e0f12e74f791afcfb829647baa5046af5f4d
5
5
  SHA512:
6
- metadata.gz: 7d4156f5ace594a8d7ed5846efe1d05f1b2eb23c38038bd526516dc9b351e6e4fe3bfcc2e90a79f6f36ef6b67625c51531ecf8dc359eb542a9d8995f21206794
7
- data.tar.gz: 884ff2d8cae0b911310efb98d1203d2b28685c1b15c8f7e756c96deeade3ac41079a8c75bdc2b59c3880e9f529b072fb1c8ec66852a746f0e82b48b95506ef2c
6
+ metadata.gz: ef9f70ca09c8f20e4f56887ec557c1b34a5b8406b1b109a2bea69c10b7e4f896aa9a7f0ad57a7ba7dbd693801741bb60d6905636cff3aaead4583cdebe0a0d79
7
+ data.tar.gz: 38892366770b0622e58591d48c5b0b16ed2d4d58c350d8917602626dd6e089c64370b67c92a810805c436541927200cbf9218d63b5e0d1ae834ce6b98bb6d011
data/Readme.md CHANGED
@@ -118,17 +118,28 @@ It's kinda like a JSON version of the Logstash config language:
118
118
  "output": {
119
119
  "rabbitmq": {
120
120
 
121
- // Must be a consistently-hashed exchange
121
+ // Must be a consistently-hashed exchange!
122
122
  "exchange": {
123
123
  "name": "logs"
124
124
  },
125
125
 
126
- // See Bunny docs for connection configuration
126
+ // See Bunny docs for connection configuration:
127
+ // http://rubybunny.info/articles/connecting.html
128
+ // http://rubybunny.info/articles/tls.html
127
129
  "connection": {
130
+ "port": 5672,
128
131
  "host": "localhost",
129
132
  "vhost": "/logs",
130
133
  "user": "logs",
131
134
  "pass": "logs"
135
+
136
+ // Sample TLS (SSL) attributes:
137
+ // "port": 5671,
138
+ // "tls": true,
139
+ // "tls_cert": "/path/to/client.cert",
140
+ // "tls_key": "/path/to/client.key",
141
+ // "tls_ca_certificates": [ "/path/to/cacert.pem" ],
142
+ // "verify_peer": true
132
143
  }
133
144
  }
134
145
  }
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.6.5
1
+ 1.6.6
data/lib/franz/agg.rb CHANGED
@@ -97,6 +97,14 @@ module Franz
97
97
  return
98
98
  end
99
99
 
100
+ unless @ic.keep? path, message
101
+ log.trace \
102
+ event: 'unkept',
103
+ file: path,
104
+ message: message
105
+ return
106
+ end
107
+
100
108
  t = @ic.type path
101
109
  if t.nil?
102
110
  log.trace \
data/lib/franz/input.rb CHANGED
@@ -178,7 +178,7 @@ module Franz
178
178
  File.open(path, 'w') { |f| f.write Marshal.dump(state) }
179
179
  old_checkpoints.pop # Keep last two checkpoints
180
180
  old_checkpoints.map { |c| FileUtils.rm c }
181
- log.info \
181
+ log.debug \
182
182
  event: 'input checkpoint saved'
183
183
  end
184
184
 
@@ -4,7 +4,12 @@ module Franz
4
4
 
5
5
  def initialize configs
6
6
  @configs = configs
7
+ @configs.map! do |c|
8
+ normalized_config c
9
+ end
7
10
  @types = Hash.new
11
+ @drop = Hash.new
12
+ @keep = Hash.new
8
13
  end
9
14
 
10
15
  def config path
@@ -13,52 +18,85 @@ module Franz
13
18
  end
14
19
 
15
20
  def json? path
16
- begin
17
- return config(path)[:json?]
18
- rescue
19
- return false
20
- end
21
+ config(path)[:json?]
22
+ rescue
23
+ false
24
+ end
25
+
26
+ def keep? path, message
27
+ patterns = keeps_for(path)
28
+ return true if patterns.nil?
29
+ return true if patterns.empty?
30
+ apply_patterns patterns, message
21
31
  end
22
32
 
23
33
  def drop? path, message
24
- begin
25
- drop = config(path)[:drop]
26
- rescue
27
- return true # No config found, drop it!
28
- end
29
- if drop
30
- drop = drop.is_a?(Array) ? drop : [ drop ]
31
- drop.each do |pattern|
32
- return true if message =~ pattern
33
- end
34
- end
35
- return false
34
+ patterns = drops_for(path)
35
+ return true if patterns.nil?
36
+ return false if patterns.empty?
37
+ apply_patterns patterns, message
36
38
  end
37
39
 
38
40
  def type path
39
- begin
40
- @types.fetch path
41
- rescue KeyError
42
- configs.each do |config|
43
- type = config[:type] if config[:includes].any? { |glob|
44
- included = File.fnmatch? glob, path
45
- excludes = !config[:excludes].nil?
46
- excluded = excludes && config[:excludes].any? { |exlude|
47
- File.fnmatch? exlude, File::basename(path)
48
- }
49
- included && !excluded
41
+ @types.fetch path
42
+ rescue KeyError
43
+ configs.each do |config|
44
+ type = config[:type] if config[:includes].any? { |glob|
45
+ included = File.fnmatch? glob, path
46
+ excludes = !config[:excludes].nil?
47
+ excluded = excludes && config[:excludes].any? { |exlude|
48
+ File.fnmatch? exlude, File::basename(path)
50
49
  }
51
- unless type.nil?
52
- @types[path] = type
53
- return type
54
- end
50
+ included && !excluded
51
+ }
52
+ unless type.nil?
53
+ @types[path] = type
54
+ return type
55
55
  end
56
- log.warn \
57
- event: 'type unknown',
58
- file: path
59
- @types[path] = nil
60
- return nil
61
56
  end
57
+ log.warn \
58
+ event: 'type unknown',
59
+ file: path
60
+ @types[path] = nil
61
+ end
62
+
63
+
64
+ private
65
+ def normalized_config config
66
+ config[:keep] = realize_regexps config[:keep]
67
+ config[:drop] = realize_regexps config[:drop]
68
+ config
62
69
  end
70
+
71
+ def realize_regexps ps
72
+ return [] if ps.nil?
73
+ ps = ps.is_a?(Array) ? ps : [ ps ]
74
+ ps.map do |pattern|
75
+ Regexp.new pattern
76
+ end
77
+ end
78
+
79
+ def apply_patterns patterns, message
80
+ return true if patterns.nil?
81
+ patterns.each do |pattern|
82
+ return true if message =~ pattern
83
+ end
84
+ return false
85
+ end
86
+
87
+ def drops_for path
88
+ patterns_for path, :drop, @drop
89
+ end
90
+
91
+ def keeps_for path
92
+ patterns_for path, :keep, @keep
93
+ end
94
+
95
+ def patterns_for path, kind, memo
96
+ memo.fetch path
97
+ rescue KeyError
98
+ memo[path] = config(path)[kind]
99
+ end
100
+
63
101
  end
64
102
  end
@@ -74,6 +74,37 @@ class TestFranzAgg < MiniTest::Test
74
74
  assert seqs[path] == 2 # should be two lines
75
75
  end
76
76
 
77
+ def test_handles_singular_keep
78
+ sample = "keep this\nbut not this\n"
79
+ tmp = tempfile %w[ test1 .log ]
80
+ tmp.write sample
81
+ tmp.flush
82
+ tmp.close
83
+ start_agg keep: /^keep/
84
+ sleep 3
85
+ seqs = stop_agg
86
+ path = realpath tmp.path
87
+ assert seqs.include?(path)
88
+ assert_equal sample.lines.first.strip, @agg_events.shift[:message]
89
+ assert seqs[path] == 1 # should be one line
90
+ end
91
+
92
+ def test_handles_plural_keep
93
+ sample = "keep this\nbut not this\noh this too\nreally\n"
94
+ tmp = tempfile %w[ test1 .log ]
95
+ tmp.write sample
96
+ tmp.flush
97
+ tmp.close
98
+ start_agg keep: [ /^keep/, /^oh/ ]
99
+ sleep 5
100
+ seqs = stop_agg
101
+ path = realpath tmp.path
102
+ assert seqs.include?(path)
103
+ assert_equal sample.lines[0].strip, @agg_events.shift[:message]
104
+ assert_equal sample.lines[2].strip, @agg_events.shift[:message]
105
+ assert seqs[path] == 2 # should be two lines
106
+ end
107
+
77
108
  private
78
109
  def tempfile prefix=nil
79
110
  Tempfile.new prefix, @tmpdir
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: franz
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.5
4
+ version: 1.6.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Clemmer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-26 00:00:00.000000000 Z
11
+ date: 2015-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: slog