logstash-input-redis 3.4.0 → 3.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/LICENSE +199 -10
- data/README.md +1 -4
- data/docs/index.asciidoc +15 -14
- data/lib/logstash/inputs/redis.rb +15 -33
- data/logstash-input-redis.gemspec +2 -2
- data/spec/inputs/redis_spec.rb +121 -151
- 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: 63317e087d685718d569e6dde70a5e007d0d988abcac587f55f8f439ca354c87
|
4
|
+
data.tar.gz: 39410717e0a0a8fdcb3fd2a61553846bee7e82b3417a111ac36e1b222ccc782e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e3612cb6febfe05864710e56a02b4eb2c899e75fbd1e9f25a4b9bbca4e62114c13846f05fe9c73f92b45ad2e8301baf6d9d5ab7719d576bd9ec13a2026894f9a
|
7
|
+
data.tar.gz: c10673819296c367d1ca7de3c795fd2c212099fc505c6bbe0b6a169f2ca87801afc70dc521d8a5db4a3f53e77c3a476bfef9e4d5f7cdc3fcfae414f9f832a5d2
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
## 3.6.1
|
2
|
+
- Fix: resolve crash when commands_map is set [#86](https://github.com/logstash-plugins/logstash-input-redis/pull/86)
|
3
|
+
|
4
|
+
## 3.6.0
|
5
|
+
- 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)
|
6
|
+
|
7
|
+
## 3.5.1
|
8
|
+
- [DOC] Reordered config option to alpha order [#79](https://github.com/logstash-plugins/logstash-input-redis/issues/79)
|
9
|
+
|
10
|
+
## 3.5.0
|
11
|
+
- Updated redis client dependency to ~> 4
|
12
|
+
|
13
|
+
## 3.4.1
|
14
|
+
- 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)
|
15
|
+
|
1
16
|
## 3.4.0
|
2
17
|
- Added support for renamed redis commands [#29](https://github.com/logstash-plugins/logstash-input-redis/issues/29)
|
3
18
|
|
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
|
|
@@ -76,9 +87,9 @@ The number of events to return from Redis using EVAL.
|
|
76
87
|
* Value can be any of: `list`, `channel`, `pattern_channel`
|
77
88
|
* There is no default value for this setting.
|
78
89
|
|
79
|
-
Specify either list or channel. If `
|
80
|
-
key. If `
|
81
|
-
If `
|
90
|
+
Specify either list or channel. If `data_type` is `list`, then we will BLPOP the
|
91
|
+
key. If `data_type` is `channel`, then we will SUBSCRIBE to the key.
|
92
|
+
If `data_type` is `pattern_channel`, then we will PSUBSCRIBE to the key.
|
82
93
|
|
83
94
|
[id="plugins-{type}s-{plugin}-db"]
|
84
95
|
===== `db`
|
@@ -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
|
@@ -48,9 +49,9 @@ module LogStash module Inputs class Redis < LogStash::Inputs::Threadable
|
|
48
49
|
# The name of a Redis list or channel.
|
49
50
|
config :key, :validate => :string, :required => true
|
50
51
|
|
51
|
-
# Specify either list or channel. If `
|
52
|
-
# key. If `
|
53
|
-
# If `
|
52
|
+
# Specify either list or channel. If `data_type` is `list`, then we will BLPOP the
|
53
|
+
# key. If `data_type` is `channel`, then we will SUBSCRIBE to the key.
|
54
|
+
# If `data_type` is `pattern_channel`, then we will PSUBSCRIBE to the key.
|
54
55
|
config :data_type, :validate => [ "list", "channel", "pattern_channel" ], :required => true
|
55
56
|
|
56
57
|
# The number of events to return from Redis using EVAL.
|
@@ -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)
|
@@ -146,8 +129,7 @@ module LogStash module Inputs class Redis < LogStash::Inputs::Threadable
|
|
146
129
|
return connectionParams.merge(baseParams)
|
147
130
|
end
|
148
131
|
|
149
|
-
|
150
|
-
def internal_redis_builder
|
132
|
+
def new_redis_instance
|
151
133
|
::Redis.new(redis_params)
|
152
134
|
end
|
153
135
|
|
@@ -156,14 +138,12 @@ module LogStash module Inputs class Redis < LogStash::Inputs::Threadable
|
|
156
138
|
redis = new_redis_instance
|
157
139
|
|
158
140
|
# 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
|
141
|
+
@command_map.each do |name, renamed|
|
142
|
+
redis._client.command_map[name.to_sym] = renamed.to_sym
|
164
143
|
end
|
165
144
|
|
166
145
|
load_batch_script(redis) if batched? && is_list_type?
|
146
|
+
|
167
147
|
redis
|
168
148
|
end # def connect
|
169
149
|
|
@@ -207,7 +187,9 @@ EOF
|
|
207
187
|
@redis ||= connect
|
208
188
|
@list_method.call(@redis, output_queue)
|
209
189
|
rescue ::Redis::BaseError => e
|
210
|
-
|
190
|
+
info = { message: e.message, exception: e.class }
|
191
|
+
info[:backtrace] = e.backtrace if @logger.debug?
|
192
|
+
@logger.warn("Redis connection problem", info)
|
211
193
|
# Reset the redis variable to trigger reconnect
|
212
194
|
@redis = nil
|
213
195
|
# this sleep does not need to be stoppable as its
|
@@ -269,14 +251,14 @@ EOF
|
|
269
251
|
return if @redis.nil? || !@redis.connected?
|
270
252
|
# if its a SubscribedClient then:
|
271
253
|
# it does not have a disconnect method (yet)
|
272
|
-
if @redis.
|
254
|
+
if @redis.subscribed?
|
273
255
|
if @data_type == 'pattern_channel'
|
274
|
-
@redis.
|
256
|
+
@redis.punsubscribe
|
275
257
|
else
|
276
|
-
@redis.
|
258
|
+
@redis.unsubscribe
|
277
259
|
end
|
278
260
|
else
|
279
|
-
@redis.
|
261
|
+
@redis.disconnect!
|
280
262
|
end
|
281
263
|
@redis = nil
|
282
264
|
end
|
@@ -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.6.1'
|
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)
|
@@ -64,153 +65,138 @@ describe "inputs/redis", :redis => true do
|
|
64
65
|
end
|
65
66
|
end
|
66
67
|
|
67
|
-
# unit tests ---------------------
|
68
|
-
|
69
68
|
describe LogStash::Inputs::Redis do
|
70
|
-
let(:
|
71
|
-
|
72
|
-
let(:connection) { double('redis_connection') }
|
73
|
-
let(:connected) { [true] }
|
69
|
+
let(:queue) { Queue.new }
|
70
|
+
|
74
71
|
let(:data_type) { 'list' }
|
75
72
|
let(:batch_count) { 1 }
|
76
|
-
let(:
|
73
|
+
let(:config) { {'key' => 'foo', 'data_type' => data_type, 'batch_count' => batch_count} }
|
77
74
|
let(:quit_calls) { [:quit] }
|
78
|
-
let(:accumulator) { [] }
|
79
|
-
let(:command_map) { {} }
|
80
75
|
|
81
76
|
subject do
|
82
|
-
LogStash::
|
83
|
-
.new(cfg).add_external_redis_builder(builder)
|
77
|
+
LogStash::Inputs::Redis.new(config)
|
84
78
|
end
|
85
79
|
|
86
80
|
context 'construction' do
|
87
81
|
it 'registers the input' do
|
88
|
-
expect {subject.register}.not_to raise_error
|
82
|
+
expect { subject.register }.not_to raise_error
|
89
83
|
end
|
90
84
|
end
|
91
85
|
|
92
86
|
context 'renamed redis commands' do
|
93
|
-
let(:
|
94
|
-
{
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
87
|
+
let(:config) do
|
88
|
+
{
|
89
|
+
'key' => 'foo',
|
90
|
+
'data_type' => data_type,
|
91
|
+
'command_map' => {
|
92
|
+
'blpop' => 'testblpop',
|
93
|
+
'evalsha' => 'testevalsha',
|
94
|
+
'lrange' => 'testlrange',
|
95
|
+
'ltrim' => 'testltrim',
|
96
|
+
'script' => 'testscript',
|
97
|
+
'subscribe' => 'testsubscribe',
|
98
|
+
'psubscribe' => 'testpsubscribe',
|
99
|
+
},
|
100
|
+
'batch_count' => 2
|
107
101
|
}
|
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
102
|
end
|
116
103
|
|
117
104
|
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
|
105
|
+
allow_any_instance_of( Redis::Client ).to receive(:call) do |_, command|
|
106
|
+
expect(command[0]).to eql :script
|
107
|
+
expect(command[1]).to eql 'load'
|
124
108
|
end
|
125
109
|
|
126
|
-
subject.
|
127
|
-
|
110
|
+
subject.register
|
111
|
+
redis = subject.send :connect
|
112
|
+
|
113
|
+
command_map = redis._client.command_map
|
128
114
|
|
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
|
115
|
+
expect(command_map[:blpop]).to eq config['command_map']['blpop'].to_sym
|
116
|
+
expect(command_map[:evalsha]).to eq config['command_map']['evalsha'].to_sym
|
117
|
+
expect(command_map[:lrange]).to eq config['command_map']['lrange'].to_sym
|
118
|
+
expect(command_map[:ltrim]).to eq config['command_map']['ltrim'].to_sym
|
119
|
+
expect(command_map[:script]).to eq config['command_map']['script'].to_sym
|
120
|
+
expect(command_map[:subscribe]).to eq config['command_map']['subscribe'].to_sym
|
121
|
+
expect(command_map[:psubscribe]).to eq config['command_map']['psubscribe'].to_sym
|
136
122
|
end
|
137
123
|
|
138
124
|
it 'loads the batch script with the renamed command' do
|
139
|
-
|
140
|
-
|
141
|
-
|
125
|
+
expect_any_instance_of( Redis::Client ).to receive(:call) do |_, command|
|
126
|
+
expect(command[0]).to eql :script
|
127
|
+
expect(command[1]).to eql 'load'
|
142
128
|
|
143
|
-
|
144
|
-
|
145
|
-
|
129
|
+
script = command[2]
|
130
|
+
expect(script).to include "redis.call('#{config['command_map']['lrange']}', KEYS[1], 0, batchsize)"
|
131
|
+
expect(script).to include "redis.call('#{config['command_map']['ltrim']}', KEYS[1], batchsize + 1, -1)"
|
146
132
|
end
|
147
133
|
|
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)"
|
134
|
+
subject.register
|
135
|
+
subject.send :connect
|
153
136
|
end
|
154
137
|
end
|
155
138
|
|
156
|
-
|
157
139
|
context 'runtime for list data_type' do
|
140
|
+
|
158
141
|
before do
|
159
142
|
subject.register
|
143
|
+
allow_any_instance_of( Redis::Client ).to receive(:connected?).and_return true
|
144
|
+
allow_any_instance_of( Redis::Client ).to receive(:disconnect)
|
145
|
+
allow_any_instance_of( Redis ).to receive(:quit)
|
146
|
+
end
|
147
|
+
|
148
|
+
after do
|
149
|
+
subject.stop
|
160
150
|
end
|
161
151
|
|
162
152
|
context 'close when redis is unset' do
|
163
|
-
let(:quit_calls) { [:quit, :unsubscribe, :punsubscribe, :connection, :disconnect!] }
|
164
153
|
|
165
154
|
it 'does not attempt to quit' do
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
expect {subject.do_stop}.not_to raise_error
|
155
|
+
expect_any_instance_of( Redis::Client ).to_not receive(:call)
|
156
|
+
expect_any_instance_of( Redis::Client ).to_not receive(:disconnect)
|
157
|
+
|
158
|
+
expect { subject.do_stop }.not_to raise_error
|
171
159
|
end
|
172
160
|
end
|
173
161
|
|
174
162
|
it 'calling the run method, adds events to the queue' do
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
163
|
+
allow_any_instance_of( Redis::Client ).to receive(:call_with_timeout) do |_, command, timeout, &block|
|
164
|
+
expect(command[0]).to eql :blpop
|
165
|
+
expect(command[1]).to eql ['foo', 0]
|
166
|
+
expect(command[2]).to eql 1
|
167
|
+
end.and_return ['foo', "{\"foo1\":\"bar\""], nil
|
179
168
|
|
180
169
|
tt = Thread.new do
|
181
|
-
sleep 0.
|
170
|
+
sleep 0.25
|
182
171
|
subject.do_stop
|
183
172
|
end
|
184
173
|
|
185
|
-
subject.run(
|
174
|
+
subject.run(queue)
|
186
175
|
|
187
176
|
tt.join
|
188
177
|
|
189
|
-
expect(
|
178
|
+
expect( queue.size ).to be > 0
|
190
179
|
end
|
191
180
|
|
192
181
|
context "when the batch size is greater than 1" do
|
193
182
|
let(:batch_count) { 10 }
|
194
|
-
let(:rates) { [] }
|
195
|
-
|
196
|
-
before do
|
197
|
-
allow(redis).to receive(:connected?).and_return(connected.last)
|
198
|
-
allow(redis).to receive(:script)
|
199
|
-
allow(redis).to receive(:quit)
|
200
|
-
end
|
201
183
|
|
202
184
|
it 'calling the run method, adds events to the queue' do
|
203
|
-
|
185
|
+
allow_any_instance_of( Redis ).to receive(:script)
|
186
|
+
allow_any_instance_of( Redis::Client ).to receive(:call) do |_, command|
|
187
|
+
expect(command[0]).to eql :evalsha
|
188
|
+
end.and_return ['{"a": 1}', '{"b":'], []
|
204
189
|
|
205
190
|
tt = Thread.new do
|
206
|
-
sleep 0.
|
191
|
+
sleep 0.25
|
207
192
|
subject.do_stop
|
208
193
|
end
|
209
194
|
|
210
|
-
subject.run(
|
195
|
+
subject.run(queue)
|
211
196
|
|
212
197
|
tt.join
|
213
|
-
|
198
|
+
|
199
|
+
expect( queue.size ).to be > 0
|
214
200
|
end
|
215
201
|
end
|
216
202
|
|
@@ -219,20 +205,18 @@ describe LogStash::Inputs::Redis do
|
|
219
205
|
let(:rates) { [] }
|
220
206
|
|
221
207
|
it 'will throttle the loop' do
|
222
|
-
|
208
|
+
allow_any_instance_of( Redis ).to receive(:script)
|
209
|
+
allow_any_instance_of( Redis::Client ).to receive(:call) do |_, command|
|
210
|
+
expect(command[0]).to eql :evalsha
|
223
211
|
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)
|
212
|
+
end.and_return []
|
229
213
|
|
230
214
|
tt = Thread.new do
|
231
|
-
sleep
|
215
|
+
sleep 0.25
|
232
216
|
subject.do_stop
|
233
217
|
end
|
234
218
|
|
235
|
-
subject.run(
|
219
|
+
subject.run(queue)
|
236
220
|
|
237
221
|
tt.join
|
238
222
|
|
@@ -241,7 +225,7 @@ describe LogStash::Inputs::Redis do
|
|
241
225
|
inters << x - y
|
242
226
|
end
|
243
227
|
|
244
|
-
expect(
|
228
|
+
expect( queue.size ).to eq(0)
|
245
229
|
inters.each do |delta|
|
246
230
|
expect(delta).to be_within(0.01).of(LogStash::Inputs::Redis::BATCH_EMPTY_SLEEP)
|
247
231
|
end
|
@@ -249,16 +233,17 @@ describe LogStash::Inputs::Redis do
|
|
249
233
|
end
|
250
234
|
|
251
235
|
it 'multiple close calls, calls to redis once' do
|
252
|
-
subject.use_redis(redis)
|
253
|
-
allow(redis).to receive(:blpop).and_return(['foo', 'l1'])
|
254
|
-
expect(redis).to receive(:connected?).and_return(connected.last)
|
236
|
+
# subject.use_redis(redis)
|
237
|
+
# allow(redis).to receive(:blpop).and_return(['foo', 'l1'])
|
238
|
+
# expect(redis).to receive(:connected?).and_return(connected.last)
|
239
|
+
allow_any_instance_of( Redis::Client ).to receive(:connected?).and_return true, false
|
240
|
+
# allow_any_instance_of( Redis::Client ).to receive(:disconnect)
|
255
241
|
quit_calls.each do |call|
|
256
|
-
|
242
|
+
allow_any_instance_of( Redis ).to receive(call).at_most(:once)
|
257
243
|
end
|
258
244
|
|
259
245
|
subject.do_stop
|
260
|
-
|
261
|
-
expect {subject.do_stop}.not_to raise_error
|
246
|
+
expect { subject.do_stop }.not_to raise_error
|
262
247
|
subject.do_stop
|
263
248
|
end
|
264
249
|
end
|
@@ -266,7 +251,7 @@ describe LogStash::Inputs::Redis do
|
|
266
251
|
context 'for the subscribe data_types' do
|
267
252
|
def run_it_thread(inst)
|
268
253
|
Thread.new(inst) do |subj|
|
269
|
-
subj.run(
|
254
|
+
subj.run(queue)
|
270
255
|
end
|
271
256
|
end
|
272
257
|
|
@@ -282,35 +267,21 @@ describe LogStash::Inputs::Redis do
|
|
282
267
|
def close_thread(inst, rt)
|
283
268
|
Thread.new(inst, rt) do |subj, runner|
|
284
269
|
# block for the messages
|
285
|
-
e1 =
|
286
|
-
e2 =
|
270
|
+
e1 = queue.pop
|
271
|
+
e2 = queue.pop
|
287
272
|
# put em back for the tests
|
288
|
-
|
289
|
-
|
273
|
+
queue.push(e1)
|
274
|
+
queue.push(e2)
|
290
275
|
runner.raise(LogStash::ShutdownSignal)
|
291
276
|
subj.close
|
292
277
|
end
|
293
278
|
end
|
294
279
|
|
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
280
|
before(:example, type: :mocked) do
|
304
281
|
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
|
-
|
282
|
+
allow_any_instance_of( Redis::Client ).to receive(:connected?).and_return true, false
|
312
283
|
quit_calls.each do |call|
|
313
|
-
|
284
|
+
allow_any_instance_of( Redis ).to receive(call).at_most(:once)
|
314
285
|
end
|
315
286
|
end
|
316
287
|
|
@@ -321,8 +292,7 @@ describe LogStash::Inputs::Redis do
|
|
321
292
|
context 'mocked redis' do
|
322
293
|
it 'multiple stop calls, calls to redis once', type: :mocked do
|
323
294
|
subject.do_stop
|
324
|
-
|
325
|
-
expect {subject.do_stop}.not_to raise_error
|
295
|
+
expect { subject.do_stop }.not_to raise_error
|
326
296
|
subject.do_stop
|
327
297
|
end
|
328
298
|
end
|
@@ -330,23 +300,23 @@ describe LogStash::Inputs::Redis do
|
|
330
300
|
context 'real redis', :redis => true do
|
331
301
|
it 'calling the run method, adds events to the queue' do
|
332
302
|
#simulate the input thread
|
333
|
-
rt = run_it_thread(
|
303
|
+
rt = run_it_thread(subject)
|
334
304
|
#simulate the other system thread
|
335
|
-
publish_thread(
|
305
|
+
publish_thread(subject.send(:new_redis_instance), 'c').join
|
336
306
|
#simulate the pipeline thread
|
337
|
-
close_thread(
|
307
|
+
close_thread(subject, rt).join
|
338
308
|
|
339
|
-
expect(
|
309
|
+
expect(queue.size).to eq(2)
|
340
310
|
end
|
341
311
|
it 'events had redis_channel' do
|
342
312
|
#simulate the input thread
|
343
|
-
rt = run_it_thread(
|
313
|
+
rt = run_it_thread(subject)
|
344
314
|
#simulate the other system thread
|
345
|
-
publish_thread(
|
315
|
+
publish_thread(subject.send(:new_redis_instance), 'c').join
|
346
316
|
#simulate the pipeline thread
|
347
|
-
close_thread(
|
348
|
-
e1 =
|
349
|
-
e2 =
|
317
|
+
close_thread(subject, rt).join
|
318
|
+
e1 = queue.pop
|
319
|
+
e2 = queue.pop
|
350
320
|
expect(e1.get('[@metadata][redis_channel]')).to eq('foo')
|
351
321
|
expect(e2.get('[@metadata][redis_channel]')).to eq('foo')
|
352
322
|
end
|
@@ -360,8 +330,7 @@ describe LogStash::Inputs::Redis do
|
|
360
330
|
context 'mocked redis' do
|
361
331
|
it 'multiple stop calls, calls to redis once', type: :mocked do
|
362
332
|
subject.do_stop
|
363
|
-
|
364
|
-
expect {subject.do_stop}.not_to raise_error
|
333
|
+
expect { subject.do_stop }.not_to raise_error
|
365
334
|
subject.do_stop
|
366
335
|
end
|
367
336
|
end
|
@@ -369,23 +338,24 @@ describe LogStash::Inputs::Redis do
|
|
369
338
|
context 'real redis', :redis => true do
|
370
339
|
it 'calling the run method, adds events to the queue' do
|
371
340
|
#simulate the input thread
|
372
|
-
rt = run_it_thread(
|
341
|
+
rt = run_it_thread(subject)
|
373
342
|
#simulate the other system thread
|
374
|
-
publish_thread(
|
343
|
+
publish_thread(subject.send(:new_redis_instance), 'pc').join
|
375
344
|
#simulate the pipeline thread
|
376
|
-
close_thread(
|
345
|
+
close_thread(subject, rt).join
|
377
346
|
|
378
|
-
expect(
|
347
|
+
expect(queue.size).to eq(2)
|
379
348
|
end
|
349
|
+
|
380
350
|
it 'events had redis_channel' do
|
381
351
|
#simulate the input thread
|
382
|
-
rt = run_it_thread(
|
352
|
+
rt = run_it_thread(subject)
|
383
353
|
#simulate the other system thread
|
384
|
-
publish_thread(
|
354
|
+
publish_thread(subject.send(:new_redis_instance), 'pc').join
|
385
355
|
#simulate the pipeline thread
|
386
|
-
close_thread(
|
387
|
-
e1 =
|
388
|
-
e2 =
|
356
|
+
close_thread(subject, rt).join
|
357
|
+
e1 = queue.pop
|
358
|
+
e2 = queue.pop
|
389
359
|
expect(e1.get('[@metadata][redis_channel]')).to eq('foo')
|
390
360
|
expect(e2.get('[@metadata][redis_channel]')).to eq('foo')
|
391
361
|
end
|
@@ -393,15 +363,15 @@ describe LogStash::Inputs::Redis do
|
|
393
363
|
end
|
394
364
|
end
|
395
365
|
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
end
|
366
|
+
context "when using data type" do
|
367
|
+
|
368
|
+
["list", "channel", "pattern_channel"].each do |data_type|
|
369
|
+
context data_type do
|
370
|
+
it_behaves_like "an interruptible input plugin", :redis => true do
|
371
|
+
let(:config) { { 'key' => 'foo', 'data_type' => data_type } }
|
403
372
|
end
|
404
373
|
end
|
405
374
|
end
|
375
|
+
|
406
376
|
end
|
407
377
|
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.6.1
|
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-04-07 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:
|