logstash-input-redis 3.4.1 → 3.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -0
- data/LICENSE +199 -10
- data/README.md +1 -4
- data/docs/index.asciidoc +12 -11
- data/lib/logstash/inputs/redis.rb +67 -65
- data/logstash-input-redis.gemspec +2 -2
- data/spec/inputs/redis_spec.rb +196 -155
- metadata +12 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0be6dfe6d1465214b44d17ae4a45482ba364735abb7032fa26e37660845aaba8
|
4
|
+
data.tar.gz: d68f634cac89442c536f8f57713354af640f61dc0cc72561ba0972503c9b2d10
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c662434d97dc7d4811f062ef9dfd3c0d6fe1eec8083f27b7f0a0638e35e5ad7ef10a5b322439ed5df5bf45acaa9fff645bf9592cd5a481b9c8a9d753cd022c6
|
7
|
+
data.tar.gz: f96f01c43dfaaa0843645fb737af52408709c27b962231b10781353951c849aa8b83bad85dc4a92fc2b76c5731bca1d01bb5e1998aa2e79799744078b64b8c42
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
## 3.7.0
|
2
|
+
- Fix: better (Redis) exception handling [#89](https://github.com/logstash-plugins/logstash-input-redis/pull/89)
|
3
|
+
- Test: start running integration specs on CI
|
4
|
+
|
5
|
+
## 3.6.1
|
6
|
+
- Fix: resolve crash when commands_map is set [#86](https://github.com/logstash-plugins/logstash-input-redis/pull/86)
|
7
|
+
|
8
|
+
## 3.6.0
|
9
|
+
- Remove ruby pipeline dependency. Starting from Logstash 8, Ruby execution engine is not available. All pipelines should use Java pipeline [#84](https://github.com/logstash-plugins/logstash-input-redis/pull/84)
|
10
|
+
|
11
|
+
## 3.5.1
|
12
|
+
- [DOC] Reordered config option to alpha order [#79](https://github.com/logstash-plugins/logstash-input-redis/issues/79)
|
13
|
+
|
14
|
+
## 3.5.0
|
15
|
+
- Updated redis client dependency to ~> 4
|
16
|
+
|
1
17
|
## 3.4.1
|
2
18
|
- Changed `redis_type` to `data_type` in .rb file [#70](https://github.com/logstash-plugins/logstash-input-redis/issues/70) and asciidoc file [#71](https://github.com/logstash-plugins/logstash-input-redis/issues/71)
|
3
19
|
|
data/LICENSE
CHANGED
@@ -1,13 +1,202 @@
|
|
1
|
-
Copyright (c) 2012-2018 Elasticsearch <http://www.elastic.co>
|
2
1
|
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
http://www.apache.org/licenses/
|
6
5
|
|
7
|
-
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
1. Definitions.
|
9
|
+
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
15
|
+
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
17
|
+
other entities that control, are controlled by, or are under common
|
18
|
+
control with that entity. For the purposes of this definition,
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
20
|
+
direction or management of such entity, whether by contract or
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
26
|
+
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
28
|
+
including but not limited to software source code, documentation
|
29
|
+
source, and configuration files.
|
30
|
+
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
32
|
+
transformation or translation of a Source form, including but
|
33
|
+
not limited to compiled object code, generated documentation,
|
34
|
+
and conversions to other media types.
|
35
|
+
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
37
|
+
Object form, made available under the License, as indicated by a
|
38
|
+
copyright notice that is included in or attached to the work
|
39
|
+
(an example is provided in the Appendix below).
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and Derivative Works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
73
|
+
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79
|
+
where such license applies only to those patent claims licensable
|
80
|
+
by such Contributor that are necessarily infringed by their
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
83
|
+
institute patent litigation against any entity (including a
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
86
|
+
or contributory patent infringement, then any patent licenses
|
87
|
+
granted to You under this License for that Work shall terminate
|
88
|
+
as of the date such litigation is filed.
|
89
|
+
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
92
|
+
modifications, and in Source or Object form, provided that You
|
93
|
+
meet the following conditions:
|
94
|
+
|
95
|
+
(a) You must give any other recipients of the Work or
|
96
|
+
Derivative Works a copy of this License; and
|
97
|
+
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
99
|
+
stating that You changed the files; and
|
100
|
+
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
103
|
+
attribution notices from the Source form of the Work,
|
104
|
+
excluding those notices that do not pertain to any part of
|
105
|
+
the Derivative Works; and
|
106
|
+
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
109
|
+
include a readable copy of the attribution notices contained
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
112
|
+
of the following places: within a NOTICE text file distributed
|
113
|
+
as part of the Derivative Works; within the Source form or
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
115
|
+
within a display generated by the Derivative Works, if and
|
116
|
+
wherever such third-party notices normally appear. The contents
|
117
|
+
of the NOTICE file are for informational purposes only and
|
118
|
+
do not modify the License. You may add Your own attribution
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
121
|
+
that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
125
|
+
may provide additional or different license terms and conditions
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
129
|
+
the conditions stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
134
|
+
this License, without any additional terms or conditions.
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136
|
+
the terms of any separate license agreement you may have executed
|
137
|
+
with Licensor regarding such Contributions.
|
138
|
+
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
141
|
+
except as required for reasonable and customary use in describing the
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
143
|
+
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
153
|
+
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
159
|
+
incidental, or consequential damages of any character arising as a
|
160
|
+
result of this License or out of the use or inability to use the
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
163
|
+
other commercial damages or losses), even if such Contributor
|
164
|
+
has been advised of the possibility of such damages.
|
165
|
+
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169
|
+
or other liability obligations and/or rights consistent with this
|
170
|
+
License. However, in accepting such obligations, You may act only
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
175
|
+
of your accepting any such warranty or additional liability.
|
176
|
+
|
177
|
+
END OF TERMS AND CONDITIONS
|
178
|
+
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
180
|
+
|
181
|
+
To apply the Apache License to your work, attach the following
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
183
|
+
replaced with your own identifying information. (Don't include
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
185
|
+
comment syntax for the file format. We also recommend that a
|
186
|
+
file or class name and description of purpose be included on the
|
187
|
+
same "printed page" as the copyright notice for easier
|
188
|
+
identification within third-party archives.
|
189
|
+
|
190
|
+
Copyright 2020 Elastic and contributors
|
191
|
+
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
193
|
+
you may not use this file except in compliance with the License.
|
194
|
+
You may obtain a copy of the License at
|
195
|
+
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
197
|
+
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
201
|
+
See the License for the specific language governing permissions and
|
202
|
+
limitations under the License.
|
data/README.md
CHANGED
@@ -1,10 +1,7 @@
|
|
1
1
|
# Logstash Plugin
|
2
2
|
|
3
3
|
Travis Build
|
4
|
-
[![Travis Build Status](https://travis-ci.
|
5
|
-
|
6
|
-
Jenkins Build
|
7
|
-
[![Travis Build Status](https://travis-ci.org/logstash-plugins/logstash-input-redis.svg)](https://travis-ci.org/logstash-plugins/logstash-input-redis)
|
4
|
+
[![Travis Build Status](https://travis-ci.com/logstash-plugins/logstash-input-redis.svg)](https://travis-ci.com/logstash-plugins/logstash-input-redis)
|
8
5
|
|
9
6
|
This is a plugin for [Logstash](https://github.com/elastic/logstash).
|
10
7
|
|
data/docs/index.asciidoc
CHANGED
@@ -43,6 +43,7 @@ This plugin supports the following configuration options plus the <<plugins-{typ
|
|
43
43
|
|=======================================================================
|
44
44
|
|Setting |Input type|Required
|
45
45
|
| <<plugins-{type}s-{plugin}-batch_count>> |<<number,number>>|No
|
46
|
+
| <<plugins-{type}s-{plugin}-command_map>> |<<hash,hash>>|No
|
46
47
|
| <<plugins-{type}s-{plugin}-data_type>> |<<string,string>>, one of `["list", "channel", "pattern_channel"]`|Yes
|
47
48
|
| <<plugins-{type}s-{plugin}-db>> |<<number,number>>|No
|
48
49
|
| <<plugins-{type}s-{plugin}-host>> |<<string,string>>|No
|
@@ -53,7 +54,6 @@ This plugin supports the following configuration options plus the <<plugins-{typ
|
|
53
54
|
| <<plugins-{type}s-{plugin}-ssl>> |<<boolean,boolean>>|No
|
54
55
|
| <<plugins-{type}s-{plugin}-threads>> |<<number,number>>|No
|
55
56
|
| <<plugins-{type}s-{plugin}-timeout>> |<<number,number>>|No
|
56
|
-
| <<plugins-{type}s-{plugin}-command_map>> |<<hash,hash>>|No
|
57
57
|
|=======================================================================
|
58
58
|
|
59
59
|
Also see <<plugins-{type}s-{plugin}-common-options>> for a list of options supported by all
|
@@ -69,6 +69,17 @@ input plugins.
|
|
69
69
|
|
70
70
|
The number of events to return from Redis using EVAL.
|
71
71
|
|
72
|
+
[id="plugins-{type}s-{plugin}-command_map"]
|
73
|
+
===== `command_map`
|
74
|
+
|
75
|
+
* Value type is <<hash,hash>>
|
76
|
+
* There is no default value for this setting.
|
77
|
+
* key is the default command name, value is the renamed command.
|
78
|
+
|
79
|
+
Configure renamed redis commands in the form of "oldname" => "newname".
|
80
|
+
Redis allows for the renaming or disabling of commands in its protocol, see: https://redis.io/topics/security
|
81
|
+
|
82
|
+
|
72
83
|
[id="plugins-{type}s-{plugin}-data_type"]
|
73
84
|
===== `data_type`
|
74
85
|
|
@@ -155,16 +166,6 @@ Enable SSL support.
|
|
155
166
|
|
156
167
|
Initial connection timeout in seconds.
|
157
168
|
|
158
|
-
[id="plugins-{type}s-{plugin}-command_map"]
|
159
|
-
===== `command_map`
|
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
|
167
|
-
|
168
169
|
[id="plugins-{type}s-{plugin}-common-options"]
|
169
170
|
include::{include_path}/{type}.asciidoc[]
|
170
171
|
|
@@ -3,6 +3,7 @@ require "logstash/namespace"
|
|
3
3
|
require "logstash/inputs/base"
|
4
4
|
require "logstash/inputs/threadable"
|
5
5
|
require 'redis'
|
6
|
+
require "stud/interval"
|
6
7
|
|
7
8
|
# This input will read events from a Redis instance; it supports both Redis channels and lists.
|
8
9
|
# The list command (BLPOP) used by Logstash is supported in Redis v1.3.1+, and
|
@@ -60,28 +61,10 @@ module LogStash module Inputs class Redis < LogStash::Inputs::Threadable
|
|
60
61
|
config :command_map, :validate => :hash, :default => {}
|
61
62
|
|
62
63
|
public
|
63
|
-
# public API
|
64
|
-
# use to store a proc that can provide a Redis instance or mock
|
65
|
-
def add_external_redis_builder(builder) #callable
|
66
|
-
@redis_builder = builder
|
67
|
-
self
|
68
|
-
end
|
69
|
-
|
70
|
-
# use to apply an instance directly and bypass the builder
|
71
|
-
def use_redis(instance)
|
72
|
-
@redis = instance
|
73
|
-
self
|
74
|
-
end
|
75
|
-
|
76
|
-
def new_redis_instance
|
77
|
-
@redis_builder.call
|
78
|
-
end
|
79
64
|
|
80
65
|
def register
|
81
66
|
@redis_url = @path.nil? ? "redis://#{@password}@#{@host}:#{@port}/#{@db}" : "#{@password}@#{@path}/#{@db}"
|
82
67
|
|
83
|
-
@redis_builder ||= method(:internal_redis_builder)
|
84
|
-
|
85
68
|
# just switch on data_type once
|
86
69
|
if @data_type == 'list' || @data_type == 'dummy'
|
87
70
|
@run_method = method(:list_runner)
|
@@ -124,30 +107,25 @@ module LogStash module Inputs class Redis < LogStash::Inputs::Threadable
|
|
124
107
|
|
125
108
|
# private
|
126
109
|
def redis_params
|
110
|
+
params = {
|
111
|
+
:timeout => @timeout,
|
112
|
+
:db => @db,
|
113
|
+
:password => @password.nil? ? nil : @password.value,
|
114
|
+
:ssl => @ssl
|
115
|
+
}
|
116
|
+
|
127
117
|
if @path.nil?
|
128
|
-
|
129
|
-
|
130
|
-
:port => @port
|
131
|
-
}
|
118
|
+
params[:host] = @host
|
119
|
+
params[:port] = @port
|
132
120
|
else
|
133
121
|
@logger.warn("Parameter 'path' is set, ignoring parameters: 'host' and 'port'")
|
134
|
-
|
135
|
-
:path => @path
|
136
|
-
}
|
122
|
+
params[:path] = @path
|
137
123
|
end
|
138
124
|
|
139
|
-
|
140
|
-
:timeout => @timeout,
|
141
|
-
:db => @db,
|
142
|
-
:password => @password.nil? ? nil : @password.value,
|
143
|
-
:ssl => @ssl
|
144
|
-
}
|
145
|
-
|
146
|
-
return connectionParams.merge(baseParams)
|
125
|
+
params
|
147
126
|
end
|
148
127
|
|
149
|
-
|
150
|
-
def internal_redis_builder
|
128
|
+
def new_redis_instance
|
151
129
|
::Redis.new(redis_params)
|
152
130
|
end
|
153
131
|
|
@@ -156,14 +134,12 @@ module LogStash module Inputs class Redis < LogStash::Inputs::Threadable
|
|
156
134
|
redis = new_redis_instance
|
157
135
|
|
158
136
|
# register any renamed Redis commands
|
159
|
-
|
160
|
-
|
161
|
-
@command_map.each do |name, renamed|
|
162
|
-
client_command_map[name.to_sym] = renamed.to_sym
|
163
|
-
end
|
137
|
+
@command_map.each do |name, renamed|
|
138
|
+
redis._client.command_map[name.to_sym] = renamed.to_sym
|
164
139
|
end
|
165
140
|
|
166
141
|
load_batch_script(redis) if batched? && is_list_type?
|
142
|
+
|
167
143
|
redis
|
168
144
|
end # def connect
|
169
145
|
|
@@ -194,9 +170,12 @@ EOF
|
|
194
170
|
|
195
171
|
# private
|
196
172
|
def list_stop
|
197
|
-
|
173
|
+
redis = @redis # might change during method invocation
|
174
|
+
return if redis.nil? || !redis.connected?
|
198
175
|
|
199
|
-
|
176
|
+
redis.quit rescue nil # does client.disconnect internally
|
177
|
+
# check if input retried while executing
|
178
|
+
list_stop unless redis.equal? @redis
|
200
179
|
@redis = nil
|
201
180
|
end
|
202
181
|
|
@@ -206,13 +185,9 @@ EOF
|
|
206
185
|
begin
|
207
186
|
@redis ||= connect
|
208
187
|
@list_method.call(@redis, output_queue)
|
209
|
-
rescue
|
210
|
-
|
211
|
-
|
212
|
-
@redis = nil
|
213
|
-
# this sleep does not need to be stoppable as its
|
214
|
-
# in a while !stop? loop
|
215
|
-
sleep 1
|
188
|
+
rescue => e
|
189
|
+
log_error(e)
|
190
|
+
retry if reset_for_error_retry(e)
|
216
191
|
end
|
217
192
|
end
|
218
193
|
end
|
@@ -266,18 +241,19 @@ EOF
|
|
266
241
|
|
267
242
|
# private
|
268
243
|
def subscribe_stop
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
if
|
244
|
+
redis = @redis # might change during method invocation
|
245
|
+
return if redis.nil? || !redis.connected?
|
246
|
+
|
247
|
+
if redis.subscribed?
|
273
248
|
if @data_type == 'pattern_channel'
|
274
|
-
|
249
|
+
redis.punsubscribe
|
275
250
|
else
|
276
|
-
|
251
|
+
redis.unsubscribe
|
277
252
|
end
|
278
|
-
else
|
279
|
-
@redis.client.disconnect
|
280
253
|
end
|
254
|
+
redis.close rescue nil # does client.disconnect
|
255
|
+
# check if input retried while executing
|
256
|
+
subscribe_stop unless redis.equal? @redis
|
281
257
|
@redis = nil
|
282
258
|
end
|
283
259
|
|
@@ -286,15 +262,43 @@ EOF
|
|
286
262
|
begin
|
287
263
|
@redis ||= connect
|
288
264
|
yield
|
289
|
-
rescue
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
265
|
+
rescue => e
|
266
|
+
log_error(e)
|
267
|
+
retry if reset_for_error_retry(e)
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
def log_error(e)
|
272
|
+
info = { message: e.message, exception: e.class }
|
273
|
+
info[:backtrace] = e.backtrace if @logger.debug?
|
274
|
+
|
275
|
+
case e
|
276
|
+
when ::Redis::TimeoutError
|
277
|
+
# expected for channels in case no data is available
|
278
|
+
@logger.debug("Redis timeout, retrying", info)
|
279
|
+
when ::Redis::BaseConnectionError, ::Redis::ProtocolError
|
280
|
+
@logger.warn("Redis connection error", info)
|
281
|
+
when ::Redis::BaseError
|
282
|
+
@logger.error("Redis error", info)
|
283
|
+
when ::LogStash::ShutdownSignal
|
284
|
+
@logger.debug("Received shutdown signal")
|
285
|
+
else
|
286
|
+
info[:backtrace] ||= e.backtrace
|
287
|
+
@logger.error("Unexpected error", info)
|
295
288
|
end
|
296
289
|
end
|
297
290
|
|
291
|
+
# @return [true] if operation is fine to retry
|
292
|
+
def reset_for_error_retry(e)
|
293
|
+
return if e.is_a?(::LogStash::ShutdownSignal)
|
294
|
+
|
295
|
+
# Reset the redis variable to trigger reconnect
|
296
|
+
@redis = nil
|
297
|
+
|
298
|
+
Stud.stoppable_sleep(1) { stop? }
|
299
|
+
!stop? # retry if not stop-ing
|
300
|
+
end
|
301
|
+
|
298
302
|
# private
|
299
303
|
def channel_runner(output_queue)
|
300
304
|
redis_runner do
|
@@ -342,6 +346,4 @@ EOF
|
|
342
346
|
end
|
343
347
|
end
|
344
348
|
|
345
|
-
# end
|
346
|
-
|
347
349
|
end end end # Redis Inputs LogStash
|
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
|
3
3
|
s.name = 'logstash-input-redis'
|
4
|
-
s.version = '3.
|
4
|
+
s.version = '3.7.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"
|
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.add_runtime_dependency "logstash-core-plugin-api", ">= 1.60", "<= 2.99"
|
24
24
|
|
25
25
|
s.add_runtime_dependency 'logstash-codec-json'
|
26
|
-
s.add_runtime_dependency 'redis', '
|
26
|
+
s.add_runtime_dependency 'redis', '>= 4.0.1', '< 5'
|
27
27
|
|
28
28
|
s.add_development_dependency 'logstash-devutils'
|
29
29
|
end
|
data/spec/inputs/redis_spec.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
require "logstash/devutils/rspec/spec_helper"
|
2
|
-
require "
|
3
|
-
require "stud/try"
|
2
|
+
require "logstash/devutils/rspec/shared_examples"
|
4
3
|
require 'logstash/inputs/redis'
|
5
4
|
require 'securerandom'
|
6
5
|
|
7
6
|
def populate(key, event_count)
|
8
7
|
require "logstash/event"
|
8
|
+
require "redis"
|
9
|
+
require "stud/try"
|
9
10
|
redis = Redis.new(:host => "localhost")
|
10
11
|
event_count.times do |value|
|
11
12
|
event = LogStash::Event.new("sequence" => value)
|
@@ -16,11 +17,15 @@ def populate(key, event_count)
|
|
16
17
|
end
|
17
18
|
|
18
19
|
def process(conf, event_count)
|
19
|
-
events = input(conf) do |
|
20
|
-
|
20
|
+
events = input(conf) do |_, queue|
|
21
|
+
sleep 0.1 until queue.size >= event_count
|
22
|
+
queue.size.times.map { queue.pop }
|
21
23
|
end
|
22
|
-
|
23
|
-
|
24
|
+
# due multiple workers we get events out-of-order in the output
|
25
|
+
events.sort! { |a, b| a.get('sequence') <=> b.get('sequence') }
|
26
|
+
expect(events[0].get('sequence')).to eq(0)
|
27
|
+
expect(events[100].get('sequence')).to eq(100)
|
28
|
+
expect(events[1000].get('sequence')).to eq(1000)
|
24
29
|
end
|
25
30
|
|
26
31
|
# integration tests ---------------------
|
@@ -30,7 +35,6 @@ describe "inputs/redis", :redis => true do
|
|
30
35
|
it "should read events from a list" do
|
31
36
|
key = SecureRandom.hex
|
32
37
|
event_count = 1000 + rand(50)
|
33
|
-
# event_count = 100
|
34
38
|
conf = <<-CONFIG
|
35
39
|
input {
|
36
40
|
redis {
|
@@ -64,153 +68,200 @@ describe "inputs/redis", :redis => true do
|
|
64
68
|
end
|
65
69
|
end
|
66
70
|
|
67
|
-
# unit tests ---------------------
|
68
|
-
|
69
71
|
describe LogStash::Inputs::Redis do
|
70
|
-
let(:
|
71
|
-
|
72
|
-
let(:connection) { double('redis_connection') }
|
73
|
-
let(:connected) { [true] }
|
72
|
+
let(:queue) { Queue.new }
|
73
|
+
|
74
74
|
let(:data_type) { 'list' }
|
75
75
|
let(:batch_count) { 1 }
|
76
|
-
let(:
|
76
|
+
let(:config) { {'key' => 'foo', 'data_type' => data_type, 'batch_count' => batch_count} }
|
77
77
|
let(:quit_calls) { [:quit] }
|
78
|
-
let(:accumulator) { [] }
|
79
|
-
let(:command_map) { {} }
|
80
78
|
|
81
79
|
subject do
|
82
|
-
LogStash::
|
83
|
-
.new(cfg).add_external_redis_builder(builder)
|
80
|
+
LogStash::Inputs::Redis.new(config)
|
84
81
|
end
|
85
82
|
|
86
83
|
context 'construction' do
|
87
84
|
it 'registers the input' do
|
88
|
-
expect {subject.register}.not_to raise_error
|
85
|
+
expect { subject.register }.not_to raise_error
|
89
86
|
end
|
90
87
|
end
|
91
88
|
|
92
89
|
context 'renamed redis commands' do
|
93
|
-
let(:
|
94
|
-
{
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
90
|
+
let(:config) do
|
91
|
+
{
|
92
|
+
'key' => 'foo',
|
93
|
+
'data_type' => data_type,
|
94
|
+
'command_map' => {
|
95
|
+
'blpop' => 'testblpop',
|
96
|
+
'evalsha' => 'testevalsha',
|
97
|
+
'lrange' => 'testlrange',
|
98
|
+
'ltrim' => 'testltrim',
|
99
|
+
'script' => 'testscript',
|
100
|
+
'subscribe' => 'testsubscribe',
|
101
|
+
'psubscribe' => 'testpsubscribe',
|
102
|
+
},
|
103
|
+
'batch_count' => 2
|
107
104
|
}
|
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
105
|
end
|
116
106
|
|
117
107
|
it 'sets the renamed commands in the command map' do
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
tt = Thread.new do
|
122
|
-
sleep 0.01
|
123
|
-
subject.do_stop
|
108
|
+
allow_any_instance_of( Redis::Client ).to receive(:call) do |_, command|
|
109
|
+
expect(command[0]).to eql :script
|
110
|
+
expect(command[1]).to eql 'load'
|
124
111
|
end
|
125
112
|
|
126
|
-
subject.
|
127
|
-
|
113
|
+
subject.register
|
114
|
+
redis = subject.send :connect
|
115
|
+
|
116
|
+
command_map = redis._client.command_map
|
128
117
|
|
129
|
-
expect(command_map[:blpop]).to eq
|
130
|
-
expect(command_map[:evalsha]).to eq
|
131
|
-
expect(command_map[:lrange]).to eq
|
132
|
-
expect(command_map[:ltrim]).to eq
|
133
|
-
expect(command_map[:script]).to eq
|
134
|
-
expect(command_map[:subscribe]).to eq
|
135
|
-
expect(command_map[:psubscribe]).to eq
|
118
|
+
expect(command_map[:blpop]).to eq config['command_map']['blpop'].to_sym
|
119
|
+
expect(command_map[:evalsha]).to eq config['command_map']['evalsha'].to_sym
|
120
|
+
expect(command_map[:lrange]).to eq config['command_map']['lrange'].to_sym
|
121
|
+
expect(command_map[:ltrim]).to eq config['command_map']['ltrim'].to_sym
|
122
|
+
expect(command_map[:script]).to eq config['command_map']['script'].to_sym
|
123
|
+
expect(command_map[:subscribe]).to eq config['command_map']['subscribe'].to_sym
|
124
|
+
expect(command_map[:psubscribe]).to eq config['command_map']['psubscribe'].to_sym
|
136
125
|
end
|
137
126
|
|
138
127
|
it 'loads the batch script with the renamed command' do
|
139
|
-
|
140
|
-
|
141
|
-
|
128
|
+
expect_any_instance_of( Redis::Client ).to receive(:call) do |_, command|
|
129
|
+
expect(command[0]).to eql :script
|
130
|
+
expect(command[1]).to eql 'load'
|
142
131
|
|
143
|
-
|
144
|
-
|
145
|
-
|
132
|
+
script = command[2]
|
133
|
+
expect(script).to include "redis.call('#{config['command_map']['lrange']}', KEYS[1], 0, batchsize)"
|
134
|
+
expect(script).to include "redis.call('#{config['command_map']['ltrim']}', KEYS[1], batchsize + 1, -1)"
|
146
135
|
end
|
147
136
|
|
148
|
-
subject.
|
149
|
-
|
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)"
|
137
|
+
subject.register
|
138
|
+
subject.send :connect
|
153
139
|
end
|
154
140
|
end
|
155
141
|
|
156
|
-
|
157
142
|
context 'runtime for list data_type' do
|
143
|
+
|
158
144
|
before do
|
159
145
|
subject.register
|
146
|
+
allow_any_instance_of( Redis::Client ).to receive(:connected?).and_return true
|
147
|
+
allow_any_instance_of( Redis::Client ).to receive(:disconnect)
|
148
|
+
allow_any_instance_of( Redis ).to receive(:quit)
|
149
|
+
end
|
150
|
+
|
151
|
+
after do
|
152
|
+
subject.stop
|
160
153
|
end
|
161
154
|
|
162
155
|
context 'close when redis is unset' do
|
163
|
-
let(:quit_calls) { [:quit, :unsubscribe, :punsubscribe, :connection, :disconnect!] }
|
164
156
|
|
165
157
|
it 'does not attempt to quit' do
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
expect {subject.do_stop}.not_to raise_error
|
158
|
+
expect_any_instance_of( Redis::Client ).to_not receive(:call)
|
159
|
+
expect_any_instance_of( Redis::Client ).to_not receive(:disconnect)
|
160
|
+
|
161
|
+
expect { subject.do_stop }.not_to raise_error
|
171
162
|
end
|
172
163
|
end
|
173
164
|
|
174
165
|
it 'calling the run method, adds events to the queue' do
|
175
|
-
|
166
|
+
allow_any_instance_of( Redis::Client ).to receive(:call_with_timeout) do |_, command, timeout, &block|
|
167
|
+
expect(command[0]).to eql :blpop
|
168
|
+
expect(command[1]).to eql ['foo', 0]
|
169
|
+
end.and_return ['foo', "{\"foo1\":\"bar\""], nil
|
170
|
+
|
171
|
+
tt = Thread.new do
|
172
|
+
sleep 0.25
|
173
|
+
subject.do_stop
|
174
|
+
end
|
175
|
+
|
176
|
+
subject.run(queue)
|
177
|
+
|
178
|
+
tt.join
|
179
|
+
|
180
|
+
expect( queue.size ).to be > 0
|
181
|
+
end
|
182
|
+
|
183
|
+
it 'keeps running when a connection error occurs' do
|
184
|
+
raised = false
|
185
|
+
allow_any_instance_of( Redis::Client ).to receive(:call_with_timeout) do |_, command, timeout, &block|
|
186
|
+
expect(command[0]).to eql :blpop
|
187
|
+
unless raised
|
188
|
+
raised = true
|
189
|
+
raise Redis::CannotConnectError.new('test')
|
190
|
+
end
|
191
|
+
['foo', "{\"after\":\"raise\"}"]
|
192
|
+
end
|
176
193
|
|
177
|
-
|
178
|
-
|
194
|
+
expect(subject.logger).to receive(:warn).with('Redis connection error',
|
195
|
+
hash_including(:message=>"test", :exception=>Redis::CannotConnectError)
|
196
|
+
).and_call_original
|
179
197
|
|
180
198
|
tt = Thread.new do
|
181
|
-
sleep 0
|
199
|
+
sleep 2.0 # allow for retry (sleep) after handle_error
|
182
200
|
subject.do_stop
|
183
201
|
end
|
184
202
|
|
185
|
-
subject.run(
|
203
|
+
subject.run(queue)
|
186
204
|
|
187
205
|
tt.join
|
188
206
|
|
189
|
-
expect(
|
207
|
+
try(3) { expect( queue.size ).to be > 0 }
|
190
208
|
end
|
191
209
|
|
192
|
-
context
|
193
|
-
|
194
|
-
let(:
|
210
|
+
context 'error handling' do
|
211
|
+
|
212
|
+
let(:config) do
|
213
|
+
super().merge 'batch_count' => 2
|
214
|
+
end
|
215
|
+
|
216
|
+
it 'keeps running when a (non-Redis) io error occurs' do
|
217
|
+
raised = false
|
218
|
+
allow(subject).to receive(:connect).and_return redis = double('redis')
|
219
|
+
allow(redis).to receive(:blpop).and_return nil
|
220
|
+
expect(redis).to receive(:evalsha) do
|
221
|
+
unless raised
|
222
|
+
raised = true
|
223
|
+
raise IOError.new('closed stream')
|
224
|
+
end
|
225
|
+
[]
|
226
|
+
end.at_least(1)
|
227
|
+
redis
|
228
|
+
allow(subject).to receive(:stop)
|
229
|
+
|
230
|
+
expect(subject.logger).to receive(:error).with('Unexpected error',
|
231
|
+
hash_including(:message=>'closed stream', :exception=>IOError)
|
232
|
+
).and_call_original
|
195
233
|
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
234
|
+
tt = Thread.new do
|
235
|
+
sleep 2.0 # allow for retry (sleep) after handle_error
|
236
|
+
subject.do_stop
|
237
|
+
end
|
238
|
+
|
239
|
+
subject.run(queue)
|
240
|
+
|
241
|
+
tt.join
|
200
242
|
end
|
201
243
|
|
244
|
+
end
|
245
|
+
|
246
|
+
context "when the batch size is greater than 1" do
|
247
|
+
let(:batch_count) { 10 }
|
248
|
+
|
202
249
|
it 'calling the run method, adds events to the queue' do
|
203
|
-
|
250
|
+
allow_any_instance_of( Redis ).to receive(:script)
|
251
|
+
allow_any_instance_of( Redis::Client ).to receive(:call) do |_, command|
|
252
|
+
expect(command[0]).to eql :evalsha
|
253
|
+
end.and_return ['{"a": 1}', '{"b":'], []
|
204
254
|
|
205
255
|
tt = Thread.new do
|
206
|
-
sleep 0.
|
256
|
+
sleep 0.25
|
207
257
|
subject.do_stop
|
208
258
|
end
|
209
259
|
|
210
|
-
subject.run(
|
260
|
+
subject.run(queue)
|
211
261
|
|
212
262
|
tt.join
|
213
|
-
|
263
|
+
|
264
|
+
expect( queue.size ).to be > 0
|
214
265
|
end
|
215
266
|
end
|
216
267
|
|
@@ -219,20 +270,18 @@ describe LogStash::Inputs::Redis do
|
|
219
270
|
let(:rates) { [] }
|
220
271
|
|
221
272
|
it 'will throttle the loop' do
|
222
|
-
|
273
|
+
allow_any_instance_of( Redis ).to receive(:script)
|
274
|
+
allow_any_instance_of( Redis::Client ).to receive(:call) do |_, command|
|
275
|
+
expect(command[0]).to eql :evalsha
|
223
276
|
rates.unshift Time.now.to_f
|
224
|
-
|
225
|
-
end
|
226
|
-
allow(redis).to receive(:connected?).and_return(connected.last)
|
227
|
-
allow(redis).to receive(:script)
|
228
|
-
allow(redis).to receive(:quit)
|
277
|
+
end.and_return []
|
229
278
|
|
230
279
|
tt = Thread.new do
|
231
|
-
sleep
|
280
|
+
sleep 0.25
|
232
281
|
subject.do_stop
|
233
282
|
end
|
234
283
|
|
235
|
-
subject.run(
|
284
|
+
subject.run(queue)
|
236
285
|
|
237
286
|
tt.join
|
238
287
|
|
@@ -241,7 +290,7 @@ describe LogStash::Inputs::Redis do
|
|
241
290
|
inters << x - y
|
242
291
|
end
|
243
292
|
|
244
|
-
expect(
|
293
|
+
expect( queue.size ).to eq(0)
|
245
294
|
inters.each do |delta|
|
246
295
|
expect(delta).to be_within(0.01).of(LogStash::Inputs::Redis::BATCH_EMPTY_SLEEP)
|
247
296
|
end
|
@@ -249,24 +298,25 @@ describe LogStash::Inputs::Redis do
|
|
249
298
|
end
|
250
299
|
|
251
300
|
it 'multiple close calls, calls to redis once' do
|
252
|
-
|
253
|
-
|
254
|
-
expect(redis).to receive(:connected?).and_return(connected.last)
|
301
|
+
allow_any_instance_of( Redis::Client ).to receive(:connected?).and_return true, false
|
302
|
+
# allow_any_instance_of( Redis::Client ).to receive(:disconnect)
|
255
303
|
quit_calls.each do |call|
|
256
|
-
|
304
|
+
allow_any_instance_of( Redis ).to receive(call).at_most(:once)
|
257
305
|
end
|
258
306
|
|
259
307
|
subject.do_stop
|
260
|
-
|
261
|
-
expect {subject.do_stop}.not_to raise_error
|
308
|
+
expect { subject.do_stop }.not_to raise_error
|
262
309
|
subject.do_stop
|
263
310
|
end
|
264
311
|
end
|
265
312
|
|
266
313
|
context 'for the subscribe data_types' do
|
314
|
+
|
315
|
+
before { subject.register }
|
316
|
+
|
267
317
|
def run_it_thread(inst)
|
268
318
|
Thread.new(inst) do |subj|
|
269
|
-
subj.run(
|
319
|
+
subj.run(queue)
|
270
320
|
end
|
271
321
|
end
|
272
322
|
|
@@ -282,35 +332,21 @@ describe LogStash::Inputs::Redis do
|
|
282
332
|
def close_thread(inst, rt)
|
283
333
|
Thread.new(inst, rt) do |subj, runner|
|
284
334
|
# block for the messages
|
285
|
-
e1 =
|
286
|
-
e2 =
|
335
|
+
e1 = queue.pop
|
336
|
+
e2 = queue.pop
|
287
337
|
# put em back for the tests
|
288
|
-
|
289
|
-
|
338
|
+
queue.push(e1)
|
339
|
+
queue.push(e2)
|
290
340
|
runner.raise(LogStash::ShutdownSignal)
|
291
341
|
subj.close
|
292
342
|
end
|
293
343
|
end
|
294
344
|
|
295
|
-
let(:accumulator) { Queue.new }
|
296
|
-
|
297
|
-
let(:instance) do
|
298
|
-
inst = described_class.new(cfg)
|
299
|
-
inst.register
|
300
|
-
inst
|
301
|
-
end
|
302
|
-
|
303
345
|
before(:example, type: :mocked) do
|
304
346
|
subject.register
|
305
|
-
|
306
|
-
allow(connection).to receive(:is_a?).and_return(true)
|
307
|
-
allow(redis).to receive(:client).and_return(connection)
|
308
|
-
expect(redis).to receive(:connected?).and_return(connected.last)
|
309
|
-
allow(connection).to receive(:unsubscribe)
|
310
|
-
allow(connection).to receive(:punsubscribe)
|
311
|
-
|
347
|
+
allow_any_instance_of( Redis::Client ).to receive(:connected?).and_return true, false
|
312
348
|
quit_calls.each do |call|
|
313
|
-
|
349
|
+
allow_any_instance_of( Redis ).to receive(call).at_most(:once)
|
314
350
|
end
|
315
351
|
end
|
316
352
|
|
@@ -318,11 +354,12 @@ describe LogStash::Inputs::Redis do
|
|
318
354
|
let(:data_type) { 'channel' }
|
319
355
|
let(:quit_calls) { [:unsubscribe, :connection] }
|
320
356
|
|
357
|
+
before { subject.register }
|
358
|
+
|
321
359
|
context 'mocked redis' do
|
322
360
|
it 'multiple stop calls, calls to redis once', type: :mocked do
|
323
361
|
subject.do_stop
|
324
|
-
|
325
|
-
expect {subject.do_stop}.not_to raise_error
|
362
|
+
expect { subject.do_stop }.not_to raise_error
|
326
363
|
subject.do_stop
|
327
364
|
end
|
328
365
|
end
|
@@ -330,23 +367,23 @@ describe LogStash::Inputs::Redis do
|
|
330
367
|
context 'real redis', :redis => true do
|
331
368
|
it 'calling the run method, adds events to the queue' do
|
332
369
|
#simulate the input thread
|
333
|
-
rt = run_it_thread(
|
370
|
+
rt = run_it_thread(subject)
|
334
371
|
#simulate the other system thread
|
335
|
-
publish_thread(
|
372
|
+
publish_thread(subject.send(:new_redis_instance), 'c').join
|
336
373
|
#simulate the pipeline thread
|
337
|
-
close_thread(
|
374
|
+
close_thread(subject, rt).join
|
338
375
|
|
339
|
-
expect(
|
376
|
+
expect(queue.size).to eq(2)
|
340
377
|
end
|
341
378
|
it 'events had redis_channel' do
|
342
379
|
#simulate the input thread
|
343
|
-
rt = run_it_thread(
|
380
|
+
rt = run_it_thread(subject)
|
344
381
|
#simulate the other system thread
|
345
|
-
publish_thread(
|
382
|
+
publish_thread(subject.send(:new_redis_instance), 'c').join
|
346
383
|
#simulate the pipeline thread
|
347
|
-
close_thread(
|
348
|
-
e1 =
|
349
|
-
e2 =
|
384
|
+
close_thread(subject, rt).join
|
385
|
+
e1 = queue.pop
|
386
|
+
e2 = queue.pop
|
350
387
|
expect(e1.get('[@metadata][redis_channel]')).to eq('foo')
|
351
388
|
expect(e2.get('[@metadata][redis_channel]')).to eq('foo')
|
352
389
|
end
|
@@ -360,8 +397,7 @@ describe LogStash::Inputs::Redis do
|
|
360
397
|
context 'mocked redis' do
|
361
398
|
it 'multiple stop calls, calls to redis once', type: :mocked do
|
362
399
|
subject.do_stop
|
363
|
-
|
364
|
-
expect {subject.do_stop}.not_to raise_error
|
400
|
+
expect { subject.do_stop }.not_to raise_error
|
365
401
|
subject.do_stop
|
366
402
|
end
|
367
403
|
end
|
@@ -369,23 +405,24 @@ describe LogStash::Inputs::Redis do
|
|
369
405
|
context 'real redis', :redis => true do
|
370
406
|
it 'calling the run method, adds events to the queue' do
|
371
407
|
#simulate the input thread
|
372
|
-
rt = run_it_thread(
|
408
|
+
rt = run_it_thread(subject)
|
373
409
|
#simulate the other system thread
|
374
|
-
publish_thread(
|
410
|
+
publish_thread(subject.send(:new_redis_instance), 'pc').join
|
375
411
|
#simulate the pipeline thread
|
376
|
-
close_thread(
|
412
|
+
close_thread(subject, rt).join
|
377
413
|
|
378
|
-
expect(
|
414
|
+
expect(queue.size).to eq(2)
|
379
415
|
end
|
416
|
+
|
380
417
|
it 'events had redis_channel' do
|
381
418
|
#simulate the input thread
|
382
|
-
rt = run_it_thread(
|
419
|
+
rt = run_it_thread(subject)
|
383
420
|
#simulate the other system thread
|
384
|
-
publish_thread(
|
421
|
+
publish_thread(subject.send(:new_redis_instance), 'pc').join
|
385
422
|
#simulate the pipeline thread
|
386
|
-
close_thread(
|
387
|
-
e1 =
|
388
|
-
e2 =
|
423
|
+
close_thread(subject, rt).join
|
424
|
+
e1 = queue.pop
|
425
|
+
e2 = queue.pop
|
389
426
|
expect(e1.get('[@metadata][redis_channel]')).to eq('foo')
|
390
427
|
expect(e2.get('[@metadata][redis_channel]')).to eq('foo')
|
391
428
|
end
|
@@ -393,15 +430,19 @@ describe LogStash::Inputs::Redis do
|
|
393
430
|
end
|
394
431
|
end
|
395
432
|
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
433
|
+
context "when using data type" do
|
434
|
+
|
435
|
+
["list", "channel", "pattern_channel"].each do |data_type|
|
436
|
+
context data_type do
|
437
|
+
# TODO pending
|
438
|
+
# redis-rb ends up in a read wait loop since we do not use subscribe_with_timeout
|
439
|
+
next unless data_type == 'list'
|
440
|
+
|
441
|
+
it_behaves_like "an interruptible input plugin", :redis => true do
|
442
|
+
let(:config) { { 'key' => 'foo', 'data_type' => data_type } }
|
403
443
|
end
|
404
444
|
end
|
405
445
|
end
|
446
|
+
|
406
447
|
end
|
407
448
|
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.
|
4
|
+
version: 3.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elastic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-05-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -47,17 +47,23 @@ dependencies:
|
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
requirements:
|
50
|
-
- - "
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 4.0.1
|
53
|
+
- - "<"
|
51
54
|
- !ruby/object:Gem::Version
|
52
|
-
version: '
|
55
|
+
version: '5'
|
53
56
|
name: redis
|
54
57
|
prerelease: false
|
55
58
|
type: :runtime
|
56
59
|
version_requirements: !ruby/object:Gem::Requirement
|
57
60
|
requirements:
|
58
|
-
- - "
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: 4.0.1
|
64
|
+
- - "<"
|
59
65
|
- !ruby/object:Gem::Version
|
60
|
-
version: '
|
66
|
+
version: '5'
|
61
67
|
- !ruby/object:Gem::Dependency
|
62
68
|
requirement: !ruby/object:Gem::Requirement
|
63
69
|
requirements:
|