logstash-input-redis 3.2.2 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3166f0d0790fde3501ba2bbe462c826548d3f4f3796354cb528ec7dec9b250db
4
- data.tar.gz: 64a5bd0542681731513c830c611b051bf445d729c5b9259a31801f70fb07d825
3
+ metadata.gz: 8e3e4321bea3cf53703a9cb4a730e72757c84293359a0b8bf627489900124994
4
+ data.tar.gz: 404ca9d392bb01710e8f5617a4b583761667b7f8a933ec49a9fed5c4adc9a0ba
5
5
  SHA512:
6
- metadata.gz: c6d0529bd28db81ea0a134a504dd79b1ad499cbefae933a20946abafa7e80c95ff478941c6739d855325629ff0d2ab028e7fd30227a8994a23d1b1e6153f5388
7
- data.tar.gz: da5342d81946331dec0fef00fdc132c62255f837467dbd2b582e503ff701e8f9813a05b167c580b53fc56bd8f4f361e19283f601cdc02269b79189f20feaeaeb
6
+ metadata.gz: a5a2b7347085f5e45f4318b8deb23e87df06b7a6726ffd6c4d51740a9574c226b043ca8afec8a8c8a0d3918959d60d91797efd6da3add028891f1280846b7b67
7
+ data.tar.gz: 2cd45bba305f53142589737821c8e99402dd020fa1c845bd7c4399406e6569dd82e38683c562a33c4aa203e39572a201d02085864aea7b1afc8a71f53d46b9d4
@@ -1,3 +1,9 @@
1
+ ## 3.4.0
2
+ - Added support for renamed redis commands [#29](https://github.com/logstash-plugins/logstash-input-redis/issues/29)
3
+
4
+ ## 3.3.0
5
+ - Add channel to the event #46
6
+
1
7
  ## 3.2.2
2
8
  - Docs: Set the default_codec doc attribute.
3
9
 
@@ -53,6 +53,7 @@ This plugin supports the following configuration options plus the <<plugins-{typ
53
53
  | <<plugins-{type}s-{plugin}-ssl>> |<<boolean,boolean>>|No
54
54
  | <<plugins-{type}s-{plugin}-threads>> |<<number,number>>|No
55
55
  | <<plugins-{type}s-{plugin}-timeout>> |<<number,number>>|No
56
+ | <<plugins-{type}s-{plugin}-command_map>> |<<hash,hash>>|No
56
57
  |=======================================================================
57
58
 
58
59
  Also see <<plugins-{type}s-{plugin}-common-options>> for a list of options supported by all
@@ -154,7 +155,15 @@ Enable SSL support.
154
155
 
155
156
  Initial connection timeout in seconds.
156
157
 
158
+ [id="plugins-{type}s-{plugin}-command_map"]
159
+ ===== `command_map`
157
160
 
161
+ * Value type is <<hash,hash>>
162
+ * There is no default value for this setting.
163
+ * key is the default command name, value is the renamed command.
164
+
165
+ Configure renamed redis commands in the form of "oldname" => "newname".
166
+ Redis allows for the renaming or disabling of commands in its protocol, see: https://redis.io/topics/security
158
167
 
159
168
  [id="plugins-{type}s-{plugin}-common-options"]
160
169
  include::{include_path}/{type}.asciidoc[]
@@ -56,9 +56,12 @@ module LogStash module Inputs class Redis < LogStash::Inputs::Threadable
56
56
  # The number of events to return from Redis using EVAL.
57
57
  config :batch_count, :validate => :number, :default => 125
58
58
 
59
+ # Redefined Redis commands to be passed to the Redis client.
60
+ config :command_map, :validate => :hash, :default => {}
61
+
59
62
  public
60
63
  # public API
61
- # use to store a proc that can provide a redis instance or mock
64
+ # use to store a proc that can provide a Redis instance or mock
62
65
  def add_external_redis_builder(builder) #callable
63
66
  @redis_builder = builder
64
67
  self
@@ -151,6 +154,15 @@ module LogStash module Inputs class Redis < LogStash::Inputs::Threadable
151
154
  # private
152
155
  def connect
153
156
  redis = new_redis_instance
157
+
158
+ # register any renamed Redis commands
159
+ if @command_map.any?
160
+ client_command_map = redis.client.command_map
161
+ @command_map.each do |name, renamed|
162
+ client_command_map[name.to_sym] = renamed.to_sym
163
+ end
164
+ end
165
+
154
166
  load_batch_script(redis) if batched? && is_list_type?
155
167
  redis
156
168
  end # def connect
@@ -158,20 +170,21 @@ module LogStash module Inputs class Redis < LogStash::Inputs::Threadable
158
170
  # private
159
171
  def load_batch_script(redis)
160
172
  #A Redis Lua EVAL script to fetch a count of keys
161
- redis_script = <<EOF
162
- local batchsize = tonumber(ARGV[1])
163
- local result = redis.call('lrange', KEYS[1], 0, batchsize)
164
- redis.call('ltrim', KEYS[1], batchsize + 1, -1)
165
- return result
173
+ redis_script = <<EOF
174
+ local batchsize = tonumber(ARGV[1])
175
+ local result = redis.call(\'#{@command_map.fetch('lrange', 'lrange')}\', KEYS[1], 0, batchsize)
176
+ redis.call(\'#{@command_map.fetch('ltrim', 'ltrim')}\', KEYS[1], batchsize + 1, -1)
177
+ return result
166
178
  EOF
167
179
  @redis_script_sha = redis.script(:load, redis_script)
168
180
  end
169
181
 
170
182
  # private
171
- def queue_event(msg, output_queue)
183
+ def queue_event(msg, output_queue, channel=nil)
172
184
  begin
173
185
  @codec.decode(msg) do |event|
174
186
  decorate(event)
187
+ event.set("[@metadata][redis_channel]", channel) if !channel.nil?
175
188
  output_queue << event
176
189
  end
177
190
  rescue => e # parse or event creation error
@@ -297,7 +310,7 @@ EOF
297
310
  end
298
311
 
299
312
  on.message do |channel, message|
300
- queue_event(message, output_queue)
313
+ queue_event(message, output_queue, channel)
301
314
  end
302
315
 
303
316
  on.unsubscribe do |channel, count|
@@ -320,7 +333,7 @@ EOF
320
333
  end
321
334
 
322
335
  on.pmessage do |pattern, channel, message|
323
- queue_event(message, output_queue)
336
+ queue_event(message, output_queue, channel)
324
337
  end
325
338
 
326
339
  on.punsubscribe do |channel, count|
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-input-redis'
4
- s.version = '3.2.2'
4
+ s.version = '3.4.0'
5
5
  s.licenses = ['Apache License (2.0)']
6
6
  s.summary = "Reads events from a Redis instance"
7
7
  s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
@@ -76,6 +76,7 @@ describe LogStash::Inputs::Redis do
76
76
  let(:cfg) { {'key' => 'foo', 'data_type' => data_type, 'batch_count' => batch_count} }
77
77
  let(:quit_calls) { [:quit] }
78
78
  let(:accumulator) { [] }
79
+ let(:command_map) { {} }
79
80
 
80
81
  subject do
81
82
  LogStash::Plugin.lookup("input", "redis")
@@ -88,6 +89,71 @@ describe LogStash::Inputs::Redis do
88
89
  end
89
90
  end
90
91
 
92
+ context 'renamed redis commands' do
93
+ let(:cfg) {
94
+ {'key' => 'foo',
95
+ 'data_type' => data_type,
96
+ 'command_map' =>
97
+ {
98
+ 'blpop' => 'testblpop',
99
+ 'evalsha' => 'testevalsha',
100
+ 'lrange' => 'testlrange',
101
+ 'ltrim' => 'testltrim',
102
+ 'script' => 'testscript',
103
+ 'subscribe' => 'testsubscribe',
104
+ 'psubscribe' => 'testpsubscribe',
105
+ },
106
+ 'batch_count' => 2
107
+ }
108
+ }
109
+
110
+ before do
111
+ subject.register
112
+ allow(redis).to receive(:connected?)
113
+ allow(redis).to receive(:client).and_return(connection)
114
+ allow(connection).to receive(:command_map).and_return(command_map)
115
+ end
116
+
117
+ it 'sets the renamed commands in the command map' do
118
+ allow(redis).to receive(:script)
119
+ allow(redis).to receive(:evalsha).and_return([])
120
+
121
+ tt = Thread.new do
122
+ sleep 0.01
123
+ subject.do_stop
124
+ end
125
+
126
+ subject.run(accumulator)
127
+ tt.join
128
+
129
+ expect(command_map[:blpop]).to eq cfg['command_map']['blpop'].to_sym
130
+ expect(command_map[:evalsha]).to eq cfg['command_map']['evalsha'].to_sym
131
+ expect(command_map[:lrange]).to eq cfg['command_map']['lrange'].to_sym
132
+ expect(command_map[:ltrim]).to eq cfg['command_map']['ltrim'].to_sym
133
+ expect(command_map[:script]).to eq cfg['command_map']['script'].to_sym
134
+ expect(command_map[:subscribe]).to eq cfg['command_map']['subscribe'].to_sym
135
+ expect(command_map[:psubscribe]).to eq cfg['command_map']['psubscribe'].to_sym
136
+ end
137
+
138
+ it 'loads the batch script with the renamed command' do
139
+ capture = nil
140
+ allow(redis).to receive(:script) { |load, lua_script| capture = lua_script }
141
+ allow(redis).to receive(:evalsha).and_return([])
142
+
143
+ tt = Thread.new do
144
+ sleep 0.01
145
+ subject.do_stop
146
+ end
147
+
148
+ subject.run(accumulator)
149
+ tt.join
150
+
151
+ expect(capture).to include "redis.call('#{cfg['command_map']['lrange']}', KEYS[1], 0, batchsize)"
152
+ expect(capture).to include "redis.call('#{cfg['command_map']['ltrim']}', KEYS[1], batchsize + 1, -1)"
153
+ end
154
+ end
155
+
156
+
91
157
  context 'runtime for list data_type' do
92
158
  before do
93
159
  subject.register
@@ -272,6 +338,18 @@ describe LogStash::Inputs::Redis do
272
338
 
273
339
  expect(accumulator.size).to eq(2)
274
340
  end
341
+ it 'events had redis_channel' do
342
+ #simulate the input thread
343
+ rt = run_it_thread(instance)
344
+ #simulate the other system thread
345
+ publish_thread(instance.new_redis_instance, 'c').join
346
+ #simulate the pipeline thread
347
+ close_thread(instance, rt).join
348
+ e1 = accumulator.pop
349
+ e2 = accumulator.pop
350
+ expect(e1.get('[@metadata][redis_channel]')).to eq('foo')
351
+ expect(e2.get('[@metadata][redis_channel]')).to eq('foo')
352
+ end
275
353
  end
276
354
  end
277
355
 
@@ -299,6 +377,18 @@ describe LogStash::Inputs::Redis do
299
377
 
300
378
  expect(accumulator.size).to eq(2)
301
379
  end
380
+ it 'events had redis_channel' do
381
+ #simulate the input thread
382
+ rt = run_it_thread(instance)
383
+ #simulate the other system thread
384
+ publish_thread(instance.new_redis_instance, 'pc').join
385
+ #simulate the pipeline thread
386
+ close_thread(instance, rt).join
387
+ e1 = accumulator.pop
388
+ e2 = accumulator.pop
389
+ expect(e1.get('[@metadata][redis_channel]')).to eq('foo')
390
+ expect(e2.get('[@metadata][redis_channel]')).to eq('foo')
391
+ end
302
392
  end
303
393
  end
304
394
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-input-redis
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.2
4
+ version: 3.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-06 00:00:00.000000000 Z
11
+ date: 2018-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -112,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
112
  version: '0'
113
113
  requirements: []
114
114
  rubyforge_project:
115
- rubygems_version: 2.6.11
115
+ rubygems_version: 2.6.13
116
116
  signing_key:
117
117
  specification_version: 4
118
118
  summary: Reads events from a Redis instance