logstash-output-redis_list 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +11 -0
- data/CONTRIBUTORS +26 -0
- data/Gemfile +2 -0
- data/LICENSE +13 -0
- data/NOTICE.TXT +5 -0
- data/README.md +88 -0
- data/lib/logstash/outputs/redis_list.rb +268 -0
- data/recent-redis-list.gemspec +31 -0
- data/spec/outputs/redis_list_spec.rb +109 -0
- metadata +154 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9c27626fdf0a41c1d82deecc0a6517c7967f473b
|
4
|
+
data.tar.gz: fe02f56fe7cdb15469f76756010780ee888c3b48
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 92770b352f32c611423933c23b5f18947dd2fbfaeffc83cc12c4eb984ca63e10a17025437e9419c39d61044269d39d2240b149ebb0cec68dcd79c498ae188b9a
|
7
|
+
data.tar.gz: 8b6687b1923589e832d62149fe79ed2a02af583e55fba82f4f559cd101da4f58f41ff6263504b3aac740e86f1bdc17433ceaeab402ae444eeec22ac4c2ea8235
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# 2.0.5
|
2
|
+
- Fix LocalJumpError exception see https://github.com/logstash-plugins/logstash-output-redis/pull/27
|
3
|
+
# 2.0.4
|
4
|
+
- Depend on logstash-core-plugin-api instead of logstash-core, removing the need to mass update plugins on major releases of logstash
|
5
|
+
# 2.0.3
|
6
|
+
- New dependency requirements for logstash-core for the 5.0 release
|
7
|
+
## 2.0.0
|
8
|
+
- Plugins were updated to follow the new shutdown semantic, this mainly allows Logstash to instruct input plugins to terminate gracefully,
|
9
|
+
instead of using Thread.raise on the plugins' threads. Ref: https://github.com/elastic/logstash/pull/3895
|
10
|
+
- Dependency on logstash-core update to 2.0
|
11
|
+
|
data/CONTRIBUTORS
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
The following is a list of people who have contributed ideas, code, bug
|
2
|
+
reports, or in general have helped logstash along its way.
|
3
|
+
|
4
|
+
Contributors:
|
5
|
+
* Aaron Mildenstein (untergeek)
|
6
|
+
* Alex Dean (alexdean)
|
7
|
+
* Bob Corsaro (dokipen)
|
8
|
+
* Colin Surprenant (colinsurprenant)
|
9
|
+
* Corry Haines (tabletcorry)
|
10
|
+
* Graham Bleach (bleach)
|
11
|
+
* James Turnbull (jamtur01)
|
12
|
+
* Jason Woods (driskell)
|
13
|
+
* John E. Vincent (lusis)
|
14
|
+
* Jordan Sissel (jordansissel)
|
15
|
+
* Kurt Hurtado (kurtado)
|
16
|
+
* Laust Rud Jacobsen (rud)
|
17
|
+
* Pete Fritchman (fetep)
|
18
|
+
* Pier-Hugues Pellerin (ph)
|
19
|
+
* Richard Pijnenburg (electrical)
|
20
|
+
* Steven Rutkowski (sr-ix)
|
21
|
+
* piavlo
|
22
|
+
|
23
|
+
Note: If you've sent us patches, bug reports, or otherwise contributed to
|
24
|
+
Logstash, and you aren't on the list above and want to be, please let us know
|
25
|
+
and we'll make sure you're here. Contributions from folks like you are what make
|
26
|
+
open source awesome.
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright (c) 2012–2015 Elasticsearch <http://www.elastic.co>
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/NOTICE.TXT
ADDED
data/README.md
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
# Logstash Plugin
|
2
|
+
|
3
|
+
[![Travis Build Status](https://travis-ci.org/logstash-plugins/logstash-output-redis.svg)](https://travis-ci.org/logstash-plugins/logstash-output-redis)
|
4
|
+
|
5
|
+
This is a plugin for [Logstash](https://github.com/elastic/logstash).
|
6
|
+
|
7
|
+
It is fully free and fully open source. The license is Apache 2.0, meaning you are pretty much free to use it however you want in whatever way.
|
8
|
+
|
9
|
+
## Documentation
|
10
|
+
|
11
|
+
Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one [central location](http://www.elastic.co/guide/en/logstash/current/).
|
12
|
+
|
13
|
+
- For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
|
14
|
+
- For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
|
15
|
+
|
16
|
+
## Need Help?
|
17
|
+
|
18
|
+
Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.
|
19
|
+
|
20
|
+
## Developing
|
21
|
+
|
22
|
+
### 1. Plugin Developement and Testing
|
23
|
+
|
24
|
+
#### Code
|
25
|
+
- To get started, you'll need JRuby with the Bundler gem installed.
|
26
|
+
|
27
|
+
- Create a new plugin or clone and existing from the GitHub [logstash-plugins](https://github.com/logstash-plugins) organization. We also provide [example plugins](https://github.com/logstash-plugins?query=example).
|
28
|
+
|
29
|
+
- Install dependencies
|
30
|
+
```sh
|
31
|
+
bundle install
|
32
|
+
```
|
33
|
+
|
34
|
+
#### Test
|
35
|
+
|
36
|
+
- Update your dependencies
|
37
|
+
|
38
|
+
```sh
|
39
|
+
bundle install
|
40
|
+
```
|
41
|
+
|
42
|
+
- Run tests
|
43
|
+
|
44
|
+
```sh
|
45
|
+
bundle exec rspec
|
46
|
+
```
|
47
|
+
|
48
|
+
### 2. Running your unpublished Plugin in Logstash
|
49
|
+
|
50
|
+
#### 2.1 Run in a local Logstash clone
|
51
|
+
|
52
|
+
- Edit Logstash `Gemfile` and add the local plugin path, for example:
|
53
|
+
```ruby
|
54
|
+
gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
|
55
|
+
```
|
56
|
+
- Install plugin
|
57
|
+
```sh
|
58
|
+
bin/plugin install --no-verify
|
59
|
+
```
|
60
|
+
- Run Logstash with your plugin
|
61
|
+
```sh
|
62
|
+
bin/logstash -e 'filter {awesome {}}'
|
63
|
+
```
|
64
|
+
At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
|
65
|
+
|
66
|
+
#### 2.2 Run in an installed Logstash
|
67
|
+
|
68
|
+
You can use the same **2.1** method to run your plugin in an installed Logstash by editing its `Gemfile` and pointing the `:path` to your local plugin development directory or you can build the gem and install it using:
|
69
|
+
|
70
|
+
- Build your plugin gem
|
71
|
+
```sh
|
72
|
+
gem build logstash-filter-awesome.gemspec
|
73
|
+
```
|
74
|
+
- Install the plugin from the Logstash home
|
75
|
+
```sh
|
76
|
+
bin/plugin install /your/local/plugin/logstash-filter-awesome.gem
|
77
|
+
```
|
78
|
+
- Start Logstash and proceed to test the plugin
|
79
|
+
|
80
|
+
## Contributing
|
81
|
+
|
82
|
+
All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
|
83
|
+
|
84
|
+
Programming is not a required skill. Whatever you've seen about open source and maintainers or community members saying "send patches or die" - you will not see that here.
|
85
|
+
|
86
|
+
It is more important to the community that you are able to contribute.
|
87
|
+
|
88
|
+
For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
|
@@ -0,0 +1,268 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "logstash/outputs/base"
|
3
|
+
require "logstash/namespace"
|
4
|
+
require "stud/buffer"
|
5
|
+
|
6
|
+
# This output will send events to a Redis queue using RPUSH.
|
7
|
+
# The RPUSH command is supported in Redis v0.0.7+. Using
|
8
|
+
# PUBLISH to a channel requires at least v1.3.8+.
|
9
|
+
# While you may be able to make these Redis versions work,
|
10
|
+
# the best performance and stability will be found in more
|
11
|
+
# recent stable versions. Versions 2.6.0+ are recommended.
|
12
|
+
#
|
13
|
+
# For more information, see http://redis.io/[the Redis homepage]
|
14
|
+
#
|
15
|
+
class LogStash::Outputs::RedisList < LogStash::Outputs::Base
|
16
|
+
|
17
|
+
include Stud::Buffer
|
18
|
+
|
19
|
+
config_name "redis_list"
|
20
|
+
|
21
|
+
default :codec, "json"
|
22
|
+
|
23
|
+
# Name is used for logging in case there are multiple instances.
|
24
|
+
# TODO: delete
|
25
|
+
config :name, :validate => :string, :default => 'default',
|
26
|
+
:deprecated => true
|
27
|
+
|
28
|
+
# The hostname(s) of your Redis server(s). Ports may be specified on any
|
29
|
+
# hostname, which will override the global port config.
|
30
|
+
#
|
31
|
+
# For example:
|
32
|
+
# [source,ruby]
|
33
|
+
# "127.0.0.1"
|
34
|
+
# ["127.0.0.1", "127.0.0.2"]
|
35
|
+
# ["127.0.0.1:6380", "127.0.0.1"]
|
36
|
+
config :host, :validate => :array, :default => ["127.0.0.1"]
|
37
|
+
|
38
|
+
# Shuffle the host list during Logstash startup.
|
39
|
+
config :shuffle_hosts, :validate => :boolean, :default => true
|
40
|
+
|
41
|
+
# The default port to connect on. Can be overridden on any hostname.
|
42
|
+
config :port, :validate => :number, :default => 6379
|
43
|
+
|
44
|
+
# The Redis database number.
|
45
|
+
config :db, :validate => :number, :default => 0
|
46
|
+
|
47
|
+
# Redis initial connection timeout in seconds.
|
48
|
+
config :timeout, :validate => :number, :default => 5
|
49
|
+
|
50
|
+
# Password to authenticate with. There is no authentication by default.
|
51
|
+
config :password, :validate => :password
|
52
|
+
|
53
|
+
# The name of the Redis queue (we'll use RPUSH on this). Dynamic names are
|
54
|
+
# valid here, for example `logstash-%{type}`
|
55
|
+
# TODO: delete
|
56
|
+
config :queue, :validate => :string, :deprecated => true
|
57
|
+
|
58
|
+
# The name of a Redis list or channel. Dynamic names are
|
59
|
+
# valid here, for example `logstash-%{type}`.
|
60
|
+
# TODO set required true
|
61
|
+
config :key, :validate => :string, :required => false
|
62
|
+
|
63
|
+
config :value, :validate => :string, :required => false
|
64
|
+
|
65
|
+
config :length, :validate => :number, :default => 5
|
66
|
+
|
67
|
+
config :expire, :validate => :number, :default => 604800
|
68
|
+
|
69
|
+
# Either list or channel. If `redis_type` is list, then we will set
|
70
|
+
# RPUSH to key. If `redis_type` is channel, then we will PUBLISH to `key`.
|
71
|
+
# TODO set required true
|
72
|
+
config :data_type, :validate => [ "list", "channel" ], :required => false
|
73
|
+
|
74
|
+
# Set to true if you want Redis to batch up values and send 1 RPUSH command
|
75
|
+
# instead of one command per value to push on the list. Note that this only
|
76
|
+
# works with `data_type="list"` mode right now.
|
77
|
+
#
|
78
|
+
# If true, we send an RPUSH every "batch_events" events or
|
79
|
+
# "batch_timeout" seconds (whichever comes first).
|
80
|
+
# Only supported for `data_type` is "list".
|
81
|
+
config :batch, :validate => :boolean, :default => false
|
82
|
+
|
83
|
+
# If batch is set to true, the number of events we queue up for an RPUSH.
|
84
|
+
config :batch_events, :validate => :number, :default => 50
|
85
|
+
|
86
|
+
# If batch is set to true, the maximum amount of time between RPUSH commands
|
87
|
+
# when there are pending events to flush.
|
88
|
+
config :batch_timeout, :validate => :number, :default => 5
|
89
|
+
|
90
|
+
# Interval for reconnecting to failed Redis connections
|
91
|
+
config :reconnect_interval, :validate => :number, :default => 1
|
92
|
+
|
93
|
+
# In case Redis `data_type` is `list` and has more than `@congestion_threshold` items,
|
94
|
+
# block until someone consumes them and reduces congestion, otherwise if there are
|
95
|
+
# no consumers Redis will run out of memory, unless it was configured with OOM protection.
|
96
|
+
# But even with OOM protection, a single Redis list can block all other users of Redis,
|
97
|
+
# until Redis CPU consumption reaches the max allowed RAM size.
|
98
|
+
# A default value of 0 means that this limit is disabled.
|
99
|
+
# Only supported for `list` Redis `data_type`.
|
100
|
+
config :congestion_threshold, :validate => :number, :default => 0
|
101
|
+
|
102
|
+
# How often to check for congestion. Default is one second.
|
103
|
+
# Zero means to check on every event.
|
104
|
+
config :congestion_interval, :validate => :number, :default => 1
|
105
|
+
|
106
|
+
def register
|
107
|
+
require 'redis'
|
108
|
+
|
109
|
+
# TODO remove after setting key and data_type to true
|
110
|
+
if @queue
|
111
|
+
if @key or @data_type
|
112
|
+
raise RuntimeError.new(
|
113
|
+
"Cannot specify queue parameter and key or data_type"
|
114
|
+
)
|
115
|
+
end
|
116
|
+
@key = @queue
|
117
|
+
@data_type = 'list'
|
118
|
+
end
|
119
|
+
|
120
|
+
if not @key or not @data_type
|
121
|
+
raise RuntimeError.new(
|
122
|
+
"Must define queue, or key and data_type parameters"
|
123
|
+
)
|
124
|
+
end
|
125
|
+
# end TODO
|
126
|
+
|
127
|
+
|
128
|
+
if @batch
|
129
|
+
if @data_type != "list"
|
130
|
+
raise RuntimeError.new(
|
131
|
+
"batch is not supported with data_type #{@data_type}"
|
132
|
+
)
|
133
|
+
end
|
134
|
+
buffer_initialize(
|
135
|
+
:max_items => @batch_events,
|
136
|
+
:max_interval => @batch_timeout,
|
137
|
+
:logger => @logger
|
138
|
+
)
|
139
|
+
end
|
140
|
+
|
141
|
+
@redis = nil
|
142
|
+
if @shuffle_hosts
|
143
|
+
@host.shuffle!
|
144
|
+
end
|
145
|
+
@host_idx = 0
|
146
|
+
|
147
|
+
@congestion_check_times = Hash.new { |h,k| h[k] = Time.now.to_i - @congestion_interval }
|
148
|
+
|
149
|
+
@codec.on_event(&method(:send_to_redis))
|
150
|
+
end # def register
|
151
|
+
|
152
|
+
def receive(event)
|
153
|
+
# TODO(sissel): We really should not drop an event, but historically
|
154
|
+
# we have dropped events that fail to be converted to json.
|
155
|
+
# TODO(sissel): Find a way to continue passing events through even
|
156
|
+
# if they fail to convert properly.
|
157
|
+
begin
|
158
|
+
@codec.encode(event)
|
159
|
+
rescue LocalJumpError
|
160
|
+
# This LocalJumpError rescue clause is required to test for regressions
|
161
|
+
# for https://github.com/logstash-plugins/logstash-output-redis/issues/26
|
162
|
+
# see specs. Without it the LocalJumpError is rescued by the StandardError
|
163
|
+
raise
|
164
|
+
rescue StandardError => e
|
165
|
+
@logger.warn("Error encoding event", :exception => e,
|
166
|
+
:event => event)
|
167
|
+
end
|
168
|
+
end # def receive
|
169
|
+
|
170
|
+
def congestion_check(key)
|
171
|
+
return if @congestion_threshold == 0
|
172
|
+
if (Time.now.to_i - @congestion_check_times[key]) >= @congestion_interval # Check congestion only if enough time has passed since last check.
|
173
|
+
while @redis.llen(key) > @congestion_threshold # Don't push event to Redis key which has reached @congestion_threshold.
|
174
|
+
@logger.warn? and @logger.warn("Redis key size has hit a congestion threshold #{@congestion_threshold} suspending output for #{@congestion_interval} seconds")
|
175
|
+
sleep @congestion_interval
|
176
|
+
end
|
177
|
+
@congestion_check_times[key] = Time.now.to_i
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
# called from Stud::Buffer#buffer_flush when there are events to flush
|
182
|
+
def flush(events, key, close=false)
|
183
|
+
@redis ||= connect
|
184
|
+
# we should not block due to congestion on close
|
185
|
+
# to support this Stud::Buffer#buffer_flush should pass here the :final boolean value.
|
186
|
+
congestion_check(key) unless close
|
187
|
+
@redis.rpush(key, events)
|
188
|
+
end
|
189
|
+
# called from Stud::Buffer#buffer_flush when an error occurs
|
190
|
+
def on_flush_error(e)
|
191
|
+
@logger.warn("Failed to send backlog of events to Redis",
|
192
|
+
:identity => identity,
|
193
|
+
:exception => e,
|
194
|
+
:backtrace => e.backtrace
|
195
|
+
)
|
196
|
+
@redis = connect
|
197
|
+
end
|
198
|
+
|
199
|
+
def close
|
200
|
+
if @batch
|
201
|
+
buffer_flush(:final => true)
|
202
|
+
end
|
203
|
+
if @data_type == 'channel' and @redis
|
204
|
+
@redis.quit
|
205
|
+
@redis = nil
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
private
|
210
|
+
def connect
|
211
|
+
@current_host, @current_port = @host[@host_idx].split(':')
|
212
|
+
@host_idx = @host_idx + 1 >= @host.length ? 0 : @host_idx + 1
|
213
|
+
|
214
|
+
if not @current_port
|
215
|
+
@current_port = @port
|
216
|
+
end
|
217
|
+
|
218
|
+
params = {
|
219
|
+
:host => @current_host,
|
220
|
+
:port => @current_port,
|
221
|
+
:timeout => @timeout,
|
222
|
+
:db => @db
|
223
|
+
}
|
224
|
+
@logger.debug(params)
|
225
|
+
|
226
|
+
if @password
|
227
|
+
params[:password] = @password.value
|
228
|
+
end
|
229
|
+
|
230
|
+
Redis.new(params)
|
231
|
+
end # def connect
|
232
|
+
|
233
|
+
# A string used to identify a Redis instance in log messages
|
234
|
+
def identity
|
235
|
+
@name || "redis://#{@password}@#{@current_host}:#{@current_port}/#{@db} #{@data_type}:#{@key}"
|
236
|
+
end
|
237
|
+
|
238
|
+
def send_to_redis(event, payload)
|
239
|
+
# How can I do this sort of thing with codecs?
|
240
|
+
key = event.sprintf(@key)
|
241
|
+
value = event.sprintf(@value)
|
242
|
+
|
243
|
+
if @batch && @data_type == 'list' # Don't use batched method for pubsub.
|
244
|
+
# Stud::Buffer
|
245
|
+
buffer_receive(payload, key)
|
246
|
+
return
|
247
|
+
end
|
248
|
+
|
249
|
+
begin
|
250
|
+
@redis ||= connect
|
251
|
+
if @data_type == 'list'
|
252
|
+
congestion_check(key)
|
253
|
+
@redis.lpush(key, value)
|
254
|
+
@redis.ltrim(key, 0, @length)
|
255
|
+
@redis.expire(key, @expire)
|
256
|
+
else
|
257
|
+
@redis.publish(key, payload)
|
258
|
+
end
|
259
|
+
rescue => e
|
260
|
+
@logger.warn("Failed to send event to Redis", :event => event,
|
261
|
+
:identity => identity, :exception => e,
|
262
|
+
:backtrace => e.backtrace)
|
263
|
+
sleep @reconnect_interval
|
264
|
+
@redis = nil
|
265
|
+
retry
|
266
|
+
end
|
267
|
+
end
|
268
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
|
3
|
+
s.name = 'logstash-output-redis_list'
|
4
|
+
s.version = '0.0.1'
|
5
|
+
s.licenses = ['Apache License (2.0)']
|
6
|
+
s.summary = "This output will send events to a Redis queue using LPUSH and LTRIM"
|
7
|
+
s.description = "This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program"
|
8
|
+
s.authors = ["Elastic", "akdh"]
|
9
|
+
s.require_paths = ["lib"]
|
10
|
+
|
11
|
+
# Files
|
12
|
+
s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
|
13
|
+
|
14
|
+
# Tests
|
15
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
16
|
+
|
17
|
+
# Special flag to let us know this is actually a logstash plugin
|
18
|
+
s.metadata = { "logstash_plugin" => "true", "logstash_group" => "output" }
|
19
|
+
|
20
|
+
# Gem dependencies
|
21
|
+
s.add_runtime_dependency "logstash-core-plugin-api", "~> 1.0"
|
22
|
+
|
23
|
+
s.add_runtime_dependency 'redis'
|
24
|
+
s.add_runtime_dependency 'stud'
|
25
|
+
|
26
|
+
s.add_development_dependency 'logstash-devutils'
|
27
|
+
s.add_development_dependency 'logstash-input-generator'
|
28
|
+
s.add_development_dependency 'logstash-codec-json'
|
29
|
+
s.add_development_dependency 'flores'
|
30
|
+
end
|
31
|
+
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require "logstash/devutils/rspec/spec_helper"
|
2
|
+
require "logstash/outputs/redis_list"
|
3
|
+
require "logstash/json"
|
4
|
+
require "redis"
|
5
|
+
require "flores/random"
|
6
|
+
|
7
|
+
describe LogStash::Outputs::RedisList do
|
8
|
+
|
9
|
+
context "integration tests", :redis => true do
|
10
|
+
shared_examples_for "writing to redis list" do |extra_config|
|
11
|
+
let(:key) { 10.times.collect { rand(10).to_s }.join("") }
|
12
|
+
let(:event_count) { Flores::Random.integer(0..10000) }
|
13
|
+
let(:message) { Flores::Random.text(0..100) }
|
14
|
+
let(:default_config) {
|
15
|
+
{
|
16
|
+
"key" => key,
|
17
|
+
"data_type" => "list",
|
18
|
+
"host" => "localhost"
|
19
|
+
}
|
20
|
+
}
|
21
|
+
let(:redis_config) {
|
22
|
+
default_config.merge(extra_config || {})
|
23
|
+
}
|
24
|
+
let(:redis_output) { described_class.new(redis_config) }
|
25
|
+
|
26
|
+
before do
|
27
|
+
redis_output.register
|
28
|
+
event_count.times do |i|
|
29
|
+
event = LogStash::Event.new("sequence" => i, "message" => message)
|
30
|
+
redis_output.receive(event)
|
31
|
+
end
|
32
|
+
redis_output.close
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should successfully send all events to redis" do
|
36
|
+
redis = Redis.new(:host => "127.0.0.1")
|
37
|
+
|
38
|
+
# The list should contain the number of elements our agent pushed up.
|
39
|
+
insist { redis.llen(key) } == event_count
|
40
|
+
|
41
|
+
# Now check all events for order and correctness.
|
42
|
+
event_count.times do |value|
|
43
|
+
id, element = redis.blpop(key, 0)
|
44
|
+
event = LogStash::Event.new(LogStash::Json.load(element))
|
45
|
+
insist { event["sequence"] } == value
|
46
|
+
insist { event["message"] } == message
|
47
|
+
end
|
48
|
+
|
49
|
+
# The list should now be empty
|
50
|
+
insist { redis.llen(key) } == 0
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "when batch_mode is false" do
|
55
|
+
include_examples "writing to redis list"
|
56
|
+
end
|
57
|
+
|
58
|
+
context "when batch_mode is true" do
|
59
|
+
batch_events = Flores::Random.integer(1..1000)
|
60
|
+
batch_settings = {
|
61
|
+
"batch" => true,
|
62
|
+
"batch_events" => batch_events
|
63
|
+
}
|
64
|
+
|
65
|
+
include_examples "writing to redis list", batch_settings do
|
66
|
+
|
67
|
+
# A canary to make sure we're actually enabling batch mode
|
68
|
+
# in this shared example.
|
69
|
+
it "should have batch mode enabled" do
|
70
|
+
expect(redis_config).to include("batch")
|
71
|
+
expect(redis_config["batch"]).to be_truthy
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context "Redis#receive in batch mode" do
|
78
|
+
# this is a regression test harness to verify fix for https://github.com/logstash-plugins/logstash-output-redis/issues/26
|
79
|
+
# TODO: refactor specs above and probably rely on a Redis mock to correctly test the code expected behaviour, the actual
|
80
|
+
# tests agains Redis should be moved into integration tests.
|
81
|
+
let(:key) { "thekey" }
|
82
|
+
let(:payload) { "somepayload"}
|
83
|
+
let(:event) { LogStash::Event.new({"message" => "test"}) }
|
84
|
+
let(:config) {
|
85
|
+
{
|
86
|
+
"key" => key,
|
87
|
+
"data_type" => "list",
|
88
|
+
"batch" => true,
|
89
|
+
"batch_events" => 50,
|
90
|
+
"length" => 25
|
91
|
+
}
|
92
|
+
}
|
93
|
+
let(:redis) { described_class.new(config) }
|
94
|
+
|
95
|
+
it "should call buffer_receive" do
|
96
|
+
redis.register
|
97
|
+
expect(redis).to receive(:buffer_receive).exactly(10000).times.and_call_original
|
98
|
+
expect(redis).to receive(:flush).exactly(200).times
|
99
|
+
|
100
|
+
# I was able to reproduce the LocalJumpError: unexpected next exception at around 50
|
101
|
+
# consicutive invocations. setting to 10000 should reproduce it for any environment
|
102
|
+
# I have no clue at this point why this problem does not happen at every invocation
|
103
|
+
1.upto(10000) do
|
104
|
+
expect{redis.receive(event)}.to_not raise_error
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
metadata
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logstash-output-redis_list
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Elastic
|
8
|
+
- akdh
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2016-08-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
name: logstash-core-plugin-api
|
21
|
+
prerelease: false
|
22
|
+
type: :runtime
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
name: redis
|
35
|
+
prerelease: false
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
name: stud
|
49
|
+
prerelease: false
|
50
|
+
type: :runtime
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
name: logstash-devutils
|
63
|
+
prerelease: false
|
64
|
+
type: :development
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
name: logstash-input-generator
|
77
|
+
prerelease: false
|
78
|
+
type: :development
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
name: logstash-codec-json
|
91
|
+
prerelease: false
|
92
|
+
type: :development
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
name: flores
|
105
|
+
prerelease: false
|
106
|
+
type: :development
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
description: This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program
|
113
|
+
email:
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- CHANGELOG.md
|
119
|
+
- CONTRIBUTORS
|
120
|
+
- Gemfile
|
121
|
+
- LICENSE
|
122
|
+
- NOTICE.TXT
|
123
|
+
- README.md
|
124
|
+
- lib/logstash/outputs/redis_list.rb
|
125
|
+
- recent-redis-list.gemspec
|
126
|
+
- spec/outputs/redis_list_spec.rb
|
127
|
+
homepage:
|
128
|
+
licenses:
|
129
|
+
- Apache License (2.0)
|
130
|
+
metadata:
|
131
|
+
logstash_plugin: 'true'
|
132
|
+
logstash_group: output
|
133
|
+
post_install_message:
|
134
|
+
rdoc_options: []
|
135
|
+
require_paths:
|
136
|
+
- lib
|
137
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - '>='
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
requirements: []
|
148
|
+
rubyforge_project:
|
149
|
+
rubygems_version: 2.4.5
|
150
|
+
signing_key:
|
151
|
+
specification_version: 4
|
152
|
+
summary: This output will send events to a Redis queue using LPUSH and LTRIM
|
153
|
+
test_files:
|
154
|
+
- spec/outputs/redis_list_spec.rb
|