├── .ci ├── docker-compose.override.yml └── run.sh ├── .github ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── CONTRIBUTORS ├── Gemfile ├── LICENSE ├── NOTICE.TXT ├── README.md ├── Rakefile ├── batch_perf ├── perf_batch.rb └── results.txt ├── docs └── index.asciidoc ├── lib └── logstash │ └── inputs │ └── redis.rb ├── logstash-input-redis.gemspec └── spec └── inputs └── redis_spec.rb /.ci/docker-compose.override.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | logstash: 5 | network_mode: host 6 | -------------------------------------------------------------------------------- /.ci/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # This is intended to be run inside the docker container as the command of the docker-compose. 3 | 4 | env 5 | 6 | set -ex 7 | 8 | jruby -rbundler/setup -S rspec -fd 9 | 10 | jruby -rbundler/setup -S rspec -fd --tag redis 11 | -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to Logstash 2 | 3 | All contributions are welcome: ideas, patches, documentation, bug reports, 4 | complaints, etc! 5 | 6 | Programming is not a required skill, and there are many ways to help out! 7 | It is more important to us that you are able to contribute. 8 | 9 | That said, some basic guidelines, which you are free to ignore :) 10 | 11 | ## Want to learn? 12 | 13 | Want to lurk about and see what others are doing with Logstash? 14 | 15 | * The irc channel (#logstash on irc.freenode.org) is a good place for this 16 | * The [forum](https://discuss.elastic.co/c/logstash) is also 17 | great for learning from others. 18 | 19 | ## Got Questions? 20 | 21 | Have a problem you want Logstash to solve for you? 22 | 23 | * You can ask a question in the [forum](https://discuss.elastic.co/c/logstash) 24 | * Alternately, you are welcome to join the IRC channel #logstash on 25 | irc.freenode.org and ask for help there! 26 | 27 | ## Have an Idea or Feature Request? 28 | 29 | * File a ticket on [GitHub](https://github.com/elastic/logstash/issues). Please remember that GitHub is used only for issues and feature requests. If you have a general question, the [forum](https://discuss.elastic.co/c/logstash) or IRC would be the best place to ask. 30 | 31 | ## Something Not Working? Found a Bug? 32 | 33 | If you think you found a bug, it probably is a bug. 34 | 35 | * If it is a general Logstash or a pipeline issue, file it in [Logstash GitHub](https://github.com/elasticsearch/logstash/issues) 36 | * If it is specific to a plugin, please file it in the respective repository under [logstash-plugins](https://github.com/logstash-plugins) 37 | * or ask the [forum](https://discuss.elastic.co/c/logstash). 38 | 39 | # Contributing Documentation and Code Changes 40 | 41 | If you have a bugfix or new feature that you would like to contribute to 42 | logstash, and you think it will take more than a few minutes to produce the fix 43 | (ie; write code), it is worth discussing the change with the Logstash users and developers first! You can reach us via [GitHub](https://github.com/elastic/logstash/issues), the [forum](https://discuss.elastic.co/c/logstash), or via IRC (#logstash on freenode irc) 44 | Please note that Pull Requests without tests will not be merged. If you would like to contribute but do not have experience with writing tests, please ping us on IRC/forum or create a PR and ask our help. 45 | 46 | ## Contributing to plugins 47 | 48 | Check our [documentation](https://www.elastic.co/guide/en/logstash/current/contributing-to-logstash.html) on how to contribute to plugins or write your own! It is super easy! 49 | 50 | ## Contribution Steps 51 | 52 | 1. Test your changes! [Run](https://github.com/elastic/logstash#testing) the test suite 53 | 2. Please make sure you have signed our [Contributor License 54 | Agreement](https://www.elastic.co/contributor-agreement/). We are not 55 | asking you to assign copyright to us, but to give us the right to distribute 56 | your code without restriction. We ask this of all contributors in order to 57 | assure our users of the origin and continuing existence of the code. You 58 | only need to sign the CLA once. 59 | 3. Send a pull request! Push your changes to your fork of the repository and 60 | [submit a pull 61 | request](https://help.github.com/articles/using-pull-requests). In the pull 62 | request, describe what your changes do and mention any bugs/issues related 63 | to the pull request. 64 | 65 | 66 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Please post all product and debugging questions on our [forum](https://discuss.elastic.co/c/logstash). Your questions will reach our wider community members there, and if we confirm that there is a bug, then we can open a new issue here. 2 | 3 | For all general issues, please provide the following details for fast resolution: 4 | 5 | - Version: 6 | - Operating System: 7 | - Config File (if you have sensitive info, please remove it): 8 | - Sample Data: 9 | - Steps to Reproduce: 10 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Thanks for contributing to Logstash! If you haven't already signed our CLA, here's a handy link: https://www.elastic.co/contributor-agreement/ 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | Gemfile.lock 3 | .bundle 4 | vendor 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | import: 2 | - logstash-plugins/.ci:travis/travis.yml@1.x 3 | 4 | addons: 5 | apt: 6 | sources: 7 | - sourceline: 'ppa:chris-lea/redis-server' 8 | packages: 9 | - redis-server 10 | 11 | before_install: 12 | - sudo service redis-server stop 13 | - sudo service redis-server start --bind 0.0.0.0 14 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 3.7.1 2 | - Add documentation to "threads" option [#95](https://github.com/logstash-plugins/logstash-input-redis/pull/95) 3 | 4 | ## 3.7.0 5 | - Fix: better (Redis) exception handling [#89](https://github.com/logstash-plugins/logstash-input-redis/pull/89) 6 | - Test: start running integration specs on CI 7 | 8 | ## 3.6.1 9 | - Fix: resolve crash when commands_map is set [#86](https://github.com/logstash-plugins/logstash-input-redis/pull/86) 10 | 11 | ## 3.6.0 12 | - 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) 13 | 14 | ## 3.5.1 15 | - [DOC] Reordered config option to alpha order [#79](https://github.com/logstash-plugins/logstash-input-redis/issues/79) 16 | 17 | ## 3.5.0 18 | - Updated redis client dependency to ~> 4 19 | 20 | ## 3.4.1 21 | - 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) 22 | 23 | ## 3.4.0 24 | - Added support for renamed redis commands [#29](https://github.com/logstash-plugins/logstash-input-redis/issues/29) 25 | 26 | ## 3.3.0 27 | - Add channel to the event #46 28 | 29 | ## 3.2.2 30 | - Docs: Set the default_codec doc attribute. 31 | 32 | ## 3.2.1 33 | - Docs: Fix broken asciidoc ID 34 | 35 | ## 3.2.0 36 | - Add support for SSL #61 37 | - Add support for Redis unix sockets #64 38 | 39 | ## 3.1.6 40 | - Update gemspec summary 41 | 42 | ## 3.1.5 43 | - Pin 'redis' gem dependency to major version range 3.x 44 | 45 | ## 3.1.4 46 | - Fix some documentation issues 47 | 48 | ## 3.1.2 49 | - use correct unsubscribe method for channel_listener data type 50 | 51 | ## 3.1.1 52 | - Relax constraint on logstash-core-plugin-api to >= 1.60 <= 2.99 53 | 54 | ## 3.1.0 55 | - breaking,config: Remove deprecated config `queue`. Please use `key` and `data_type`. 56 | - breaking,config: Remove deprecated config `name`. 57 | 58 | ## 3.0.1 59 | - Republish all the gems under jruby. 60 | 61 | ## 3.0.0 62 | - Update the plugin to the version 2.0 of the plugin api, this change is required for Logstash 5.0 compatibility. See https://github.com/elastic/logstash/issues/5141 63 | 64 | ## 2.0.6 65 | - make integration tests more reliable because of occasional travis failures 66 | 67 | ## 2.0.5 68 | - Depend on logstash-core-plugin-api instead of logstash-core, removing the need to mass update plugins on major releases of logstash 69 | 70 | ## 2.0.4 71 | - New dependency requirements for logstash-core for the 5.0 release 72 | 73 | ## 2.0.3 74 | - Changed default batch size to 125. Improve batch handling code. Add travis ci build with redis integration. 75 | 76 | ## 2.0.0 77 | - Plugins were updated to follow the new shutdown semantic, this mainly allows Logstash to instruct input plugins to terminate gracefully, 78 | instead of using Thread.raise on the plugins' threads. Ref: https://github.com/elastic/logstash/pull/3895 79 | - Dependency on logstash-core update to 2.0 80 | 81 | ## 1.0.3 82 | - Fix typo in module name in test (Causing CI build failures) 83 | 84 | ## 1.0.2 85 | - Fix typo in module name (Causing the module to not be loaded) 86 | 87 | ## 1.0.1 88 | - Make teardown more reliable 89 | - Re-organise code and tests 90 | -------------------------------------------------------------------------------- /CONTRIBUTORS: -------------------------------------------------------------------------------- 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 | * Bob Corsaro (dokipen) 7 | * Colin Surprenant (colinsurprenant) 8 | * Graham Bleach (bleach) 9 | * Jason Woods (driskell) 10 | * John E. Vincent (lusis) 11 | * Jordan Sissel (jordansissel) 12 | * Kurt Hurtado (kurtado) 13 | * Pete Fritchman (fetep) 14 | * Pier-Hugues Pellerin (ph) 15 | * Richard Pijnenburg (electrical) 16 | * piavlo 17 | * Guy Boertje (guyboertje) 18 | 19 | Note: If you've sent us patches, bug reports, or otherwise contributed to 20 | Logstash, and you aren't on the list above and want to be, please let us know 21 | and we'll make sure you're here. Contributions from folks like you are what make 22 | open source awesome. 23 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gemspec 4 | 5 | logstash_path = ENV["LOGSTASH_PATH"] || "../../logstash" 6 | use_logstash_source = ENV["LOGSTASH_SOURCE"] && ENV["LOGSTASH_SOURCE"].to_s == "1" 7 | 8 | if Dir.exist?(logstash_path) && use_logstash_source 9 | gem 'logstash-core', :path => "#{logstash_path}/logstash-core" 10 | gem 'logstash-core-plugin-api', :path => "#{logstash_path}/logstash-core-plugin-api" 11 | end 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 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. 203 | -------------------------------------------------------------------------------- /NOTICE.TXT: -------------------------------------------------------------------------------- 1 | Elasticsearch 2 | Copyright 2012-2015 Elasticsearch 3 | 4 | This product includes software developed by The Apache Software 5 | Foundation (http://www.apache.org/). -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Logstash Plugin 2 | 3 | Travis Build 4 | [![Travis Build Status](https://travis-ci.com/logstash-plugins/logstash-input-redis.svg)](https://travis-ci.com/logstash-plugins/logstash-input-redis) 5 | 6 | This is a plugin for [Logstash](https://github.com/elastic/logstash). 7 | 8 | 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. 9 | 10 | ## Documentation 11 | 12 | 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/). 13 | 14 | - For formatting code or config example, you can use the asciidoc `[source,ruby]` directive 15 | - For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide 16 | 17 | ## Need Help? 18 | 19 | Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum. 20 | 21 | ## Developing 22 | 23 | ### 1. Plugin Developement and Testing 24 | 25 | #### Code 26 | - To get started, you'll need JRuby with the Bundler gem installed. 27 | 28 | - 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). 29 | 30 | - Install dependencies 31 | ```sh 32 | bundle install 33 | ``` 34 | 35 | #### Test 36 | 37 | - Update your dependencies 38 | 39 | ```sh 40 | bundle install 41 | ``` 42 | 43 | - Run tests 44 | 45 | ```sh 46 | bundle exec rspec 47 | ``` 48 | 49 | ### 2. Running your unpublished Plugin in Logstash 50 | 51 | #### 2.1 Run in a local Logstash clone 52 | 53 | - Edit Logstash `Gemfile` and add the local plugin path, for example: 54 | ```ruby 55 | gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome" 56 | ``` 57 | - Install plugin 58 | ```sh 59 | # Logstash 2.3 and higher 60 | bin/logstash-plugin install --no-verify 61 | 62 | # Prior to Logstash 2.3 63 | bin/plugin install --no-verify 64 | 65 | ``` 66 | - Run Logstash with your plugin 67 | ```sh 68 | bin/logstash -e 'filter {awesome {}}' 69 | ``` 70 | At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash. 71 | 72 | #### 2.2 Run in an installed Logstash 73 | 74 | 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: 75 | 76 | - Build your plugin gem 77 | ```sh 78 | gem build logstash-filter-awesome.gemspec 79 | ``` 80 | - Install the plugin from the Logstash home 81 | ```sh 82 | # Logstash 2.3 and higher 83 | bin/logstash-plugin install --no-verify 84 | 85 | # Prior to Logstash 2.3 86 | bin/plugin install --no-verify 87 | 88 | ``` 89 | - Start Logstash and proceed to test the plugin 90 | 91 | ## Contributing 92 | 93 | All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin. 94 | 95 | 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. 96 | 97 | It is more important to the community that you are able to contribute. 98 | 99 | For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file. 100 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | @files=[] 2 | 3 | task :default do 4 | system("rake -T") 5 | end 6 | 7 | require "logstash/devutils/rake" 8 | -------------------------------------------------------------------------------- /batch_perf/perf_batch.rb: -------------------------------------------------------------------------------- 1 | require "benchmark" 2 | require "redis" 3 | require "securerandom" 4 | 5 | require "logstash/event" 6 | require "logstash/java_pipeline" 7 | require_relative "../lib/logstash/inputs/redis" 8 | 9 | class BenchOptions 10 | attr_reader :output_width, :redis 11 | attr_reader :key, :event_count, :sizes 12 | 13 | def initialize 14 | @output_width = 70 15 | @redis = Redis.new(:host => "localhost") 16 | @event_count = 5000 17 | @key = SecureRandom.hex 18 | @sizes = [1, 10, 100, 125, 250, 1000, 1, 10, 100, 125, 250, 1000] 19 | end 20 | 21 | def cfg_batch(d) 22 | <<-CONFIG 23 | input { 24 | redis { 25 | type => "blah" 26 | key => "#{key}" 27 | data_type => "list" 28 | batch_count => #{d} 29 | } 30 | } 31 | CONFIG 32 | end 33 | end 34 | 35 | bench_options = BenchOptions.new 36 | 37 | def input(cfg, slow, &block) 38 | pipeline = LogStash::JavaPipeline.new(cfg) 39 | queue = Queue.new 40 | 41 | pipeline.instance_eval do 42 | # create closure to capture queue 43 | @output_func = lambda do |event| 44 | (0...slow).to_a.reduce(&:+) if slow > 0 45 | queue << event 46 | end 47 | 48 | # output_func is now a method, call closure 49 | def output_func(event) 50 | @output_func.call(event) 51 | end 52 | end 53 | 54 | pipeline_thread = Thread.new { pipeline.run } 55 | sleep 0.1 while !pipeline.ready? 56 | 57 | result = block.call(pipeline, queue) 58 | 59 | pipeline.shutdown 60 | pipeline_thread.join 61 | 62 | result 63 | end 64 | 65 | def setup(bo, multiplier) 66 | temp = [] 67 | (bo.event_count * multiplier).times do |value| 68 | temp << LogStash::Event.new("sequence" => value).to_json 69 | end 70 | temp.each_cons(10) do |arr| 71 | bo.redis.rpush(bo.key, arr) 72 | end 73 | end 74 | 75 | def teardown(bo) 76 | bo.redis.del(bo.key) 77 | end 78 | 79 | Benchmark.bm(bench_options.output_width) do |x| 80 | setup(bench_options, bench_options.sizes.size + 2) 81 | delay = 2000 82 | bench_options.sizes.reverse.each do |batchs| 83 | input(bench_options.cfg_batch(batchs), delay) do |pipeline, queue| 84 | x.report("redis input batch: #{batchs}, size: #{bench_options.event_count}, slow: #{delay} delay") do 85 | bench_options.event_count.times.map{queue.pop} 86 | end 87 | end 88 | end 89 | teardown(bench_options) 90 | end 91 | -------------------------------------------------------------------------------- /batch_perf/results.txt: -------------------------------------------------------------------------------- 1 | On a 8 core 16MB - Apple MBP El Capitan 2 | 3 | MK2 - All sizes run twice for warmup 4 | larger latency 5 | user system total real 6 | redis input batch: 1, size: 5000, slow: 2000 delay 2.670000 0.330000 3.000000 ( 0.973000) 7 | redis input batch: 10, size: 5000, slow: 2000 delay 1.150000 0.090000 1.240000 ( 0.289000) 8 | redis input batch: 100, size: 5000, slow: 2000 delay 1.130000 0.060000 1.190000 ( 0.188000) 9 | redis input batch: 125, size: 5000, slow: 2000 delay 1.060000 0.060000 1.120000 ( 0.203000) 10 | redis input batch: 250, size: 5000, slow: 2000 delay 1.210000 0.050000 1.260000 ( 0.187000) 11 | redis input batch: 1000, size: 5000, slow: 2000 delay 1.130000 0.050000 1.180000 ( 0.195000) 12 | 13 | redis input batch: 1, size: 5000, slow: 2000 delay 2.350000 0.330000 2.680000 ( 0.935000) 14 | redis input batch: 10, size: 5000, slow: 2000 delay 1.040000 0.090000 1.130000 ( 0.243000) 15 | redis input batch: 100, size: 5000, slow: 2000 delay 1.100000 0.050000 1.150000 ( 0.175000) 16 | redis input batch: 125, size: 5000, slow: 2000 delay 1.210000 0.070000 1.280000 ( 0.195000) 17 | redis input batch: 250, size: 5000, slow: 2000 delay 1.160000 0.060000 1.220000 ( 0.178000) 18 | redis input batch: 1000, size: 5000, slow: 2000 delay 1.180000 0.050000 1.230000 ( 0.182000) 19 | 20 | redis input batch: 1, size: 5000, slow: 2000 delay 2.610000 0.330000 2.940000 ( 0.941000) 21 | redis input batch: 10, size: 5000, slow: 2000 delay 1.430000 0.110000 1.540000 ( 0.315000) 22 | redis input batch: 100, size: 5000, slow: 2000 delay 1.280000 0.050000 1.330000 ( 0.195000) 23 | redis input batch: 125, size: 5000, slow: 2000 delay 1.190000 0.060000 1.250000 ( 0.190000) 24 | redis input batch: 250, size: 5000, slow: 2000 delay 1.150000 0.050000 1.200000 ( 0.185000) 25 | redis input batch: 1000, size: 5000, slow: 2000 delay 1.050000 0.060000 1.110000 ( 0.193000) 26 | 27 | redis input batch: 1, size: 5000, slow: 2000 delay 1.900000 0.230000 2.130000 ( 0.648000) 28 | redis input batch: 10, size: 5000, slow: 2000 delay 0.960000 0.080000 1.040000 ( 0.199000) 29 | redis input batch: 100, size: 5000, slow: 2000 delay 1.130000 0.050000 1.180000 ( 0.169000) 30 | redis input batch: 125, size: 5000, slow: 2000 delay 1.080000 0.050000 1.130000 ( 0.160000) 31 | redis input batch: 250, size: 5000, slow: 2000 delay 1.080000 0.050000 1.130000 ( 0.159000) 32 | redis input batch: 1000, size: 5000, slow: 2000 delay 1.030000 0.040000 1.070000 ( 0.154000) 33 | 34 | redis input batch: 1, size: 5000, slow: 2000 delay 2.850000 0.300000 3.150000 ( 0.767000) 35 | redis input batch: 10, size: 5000, slow: 2000 delay 0.970000 0.080000 1.050000 ( 0.204000) 36 | redis input batch: 100, size: 5000, slow: 2000 delay 1.170000 0.050000 1.220000 ( 0.175000) 37 | redis input batch: 125, size: 5000, slow: 2000 delay 1.310000 0.060000 1.370000 ( 0.191000) 38 | redis input batch: 250, size: 5000, slow: 2000 delay 1.190000 0.050000 1.240000 ( 0.172000) 39 | redis input batch: 1000, size: 5000, slow: 2000 delay 1.100000 0.050000 1.150000 ( 0.177000) 40 | 41 | 42 | v small latency 43 | user system total real 44 | redis input batch: 1, size: 5000, slow: 20 delay 0.930000 0.170000 1.100000 ( 0.503000) 45 | redis input batch: 10, size: 5000, slow: 20 delay 0.100000 0.020000 0.120000 ( 0.071000) 46 | redis input batch: 100, size: 5000, slow: 20 delay 0.020000 0.000000 0.020000 ( 0.012000) 47 | redis input batch: 125, size: 5000, slow: 20 delay 0.020000 0.000000 0.020000 ( 0.017000) 48 | redis input batch: 250, size: 5000, slow: 20 delay 0.060000 0.000000 0.060000 ( 0.023000) 49 | redis input batch: 1000, size: 5000, slow: 20 delay 0.010000 0.000000 0.010000 ( 0.005000) 50 | 51 | redis input batch: 1, size: 5000, slow: 20 delay 1.060000 0.180000 1.240000 ( 0.533000) 52 | redis input batch: 10, size: 5000, slow: 20 delay 0.100000 0.030000 0.130000 ( 0.072000) 53 | redis input batch: 100, size: 5000, slow: 20 delay 0.020000 0.000000 0.020000 ( 0.013000) 54 | redis input batch: 125, size: 5000, slow: 20 delay 0.030000 0.000000 0.030000 ( 0.020000) 55 | redis input batch: 250, size: 5000, slow: 20 delay 0.020000 0.010000 0.030000 ( 0.019000) 56 | redis input batch: 1000, size: 5000, slow: 20 delay 0.010000 0.000000 0.010000 ( 0.003000) 57 | 58 | redis input batch: 1, size: 5000, slow: 20 delay 1.170000 0.190000 1.360000 ( 0.548000) 59 | redis input batch: 10, size: 5000, slow: 20 delay 0.070000 0.020000 0.090000 ( 0.069000) 60 | redis input batch: 100, size: 5000, slow: 20 delay 0.050000 0.000000 0.050000 ( 0.019000) 61 | redis input batch: 125, size: 5000, slow: 20 delay 0.010000 0.000000 0.010000 ( 0.006000) 62 | redis input batch: 250, size: 5000, slow: 20 delay 0.020000 0.010000 0.030000 ( 0.015000) 63 | redis input batch: 1000, size: 5000, slow: 20 delay 0.010000 0.000000 0.010000 ( 0.012000) 64 | 65 | redis input batch: 1, size: 5000, slow: 20 delay 0.710000 0.170000 0.880000 ( 0.511000) 66 | redis input batch: 10, size: 5000, slow: 20 delay 0.110000 0.020000 0.130000 ( 0.082000) 67 | redis input batch: 100, size: 5000, slow: 20 delay 0.050000 0.010000 0.060000 ( 0.025000) 68 | redis input batch: 125, size: 5000, slow: 20 delay 0.030000 0.010000 0.040000 ( 0.024000) 69 | redis input batch: 250, size: 5000, slow: 20 delay 0.030000 0.010000 0.040000 ( 0.020000) 70 | redis input batch: 1000, size: 5000, slow: 20 delay 0.030000 0.010000 0.040000 ( 0.020000) 71 | 72 | redis input batch: 1, size: 5000, slow: 20 delay 1.040000 0.180000 1.220000 ( 0.525000) 73 | redis input batch: 10, size: 5000, slow: 20 delay 0.070000 0.020000 0.090000 ( 0.058000) 74 | redis input batch: 100, size: 5000, slow: 20 delay 0.030000 0.010000 0.040000 ( 0.022000) 75 | redis input batch: 125, size: 5000, slow: 20 delay 0.020000 0.000000 0.020000 ( 0.019000) 76 | redis input batch: 250, size: 5000, slow: 20 delay 0.020000 0.000000 0.020000 ( 0.011000) 77 | redis input batch: 1000, size: 5000, slow: 20 delay 0.020000 0.000000 0.020000 ( 0.014000) 78 | 79 | redis input batch: 1, size: 5000, slow: 20 delay 1.040000 0.200000 1.240000 ( 0.511000) 80 | redis input batch: 10, size: 5000, slow: 20 delay 0.090000 0.020000 0.110000 ( 0.068000) 81 | redis input batch: 100, size: 5000, slow: 20 delay 0.010000 0.000000 0.010000 ( 0.007000) 82 | redis input batch: 125, size: 5000, slow: 20 delay 0.020000 0.000000 0.020000 ( 0.014000) 83 | redis input batch: 250, size: 5000, slow: 20 delay 0.020000 0.000000 0.020000 ( 0.016000) 84 | redis input batch: 1000, size: 5000, slow: 20 delay 0.000000 0.000000 0.000000 ( 0.004000) 85 | 86 | redis input batch: 1, size: 5000, slow: 20 delay 1.020000 0.190000 1.210000 ( 0.516000) 87 | redis input batch: 10, size: 5000, slow: 20 delay 0.080000 0.020000 0.100000 ( 0.072000) 88 | redis input batch: 100, size: 5000, slow: 20 delay 0.030000 0.010000 0.040000 ( 0.025000) 89 | redis input batch: 125, size: 5000, slow: 20 delay 0.020000 0.000000 0.020000 ( 0.011000) 90 | redis input batch: 250, size: 5000, slow: 20 delay 0.010000 0.000000 0.010000 ( 0.003000) 91 | redis input batch: 1000, size: 5000, slow: 20 delay 0.020000 0.000000 0.020000 ( 0.014000) 92 | 93 | 94 | Sizes reversed 95 | user system total real 96 | redis input batch: 1000, size: 5000, slow: 20 delay 0.080000 0.000000 0.080000 ( 0.026000) 97 | redis input batch: 250, size: 5000, slow: 20 delay 0.020000 0.000000 0.020000 ( 0.011000) 98 | redis input batch: 125, size: 5000, slow: 20 delay 0.040000 0.000000 0.040000 ( 0.023000) 99 | redis input batch: 100, size: 5000, slow: 20 delay 0.040000 0.010000 0.050000 ( 0.023000) 100 | redis input batch: 10, size: 5000, slow: 20 delay 0.060000 0.020000 0.080000 ( 0.060000) 101 | redis input batch: 1, size: 5000, slow: 20 delay 0.680000 0.170000 0.850000 ( 0.484000) 102 | 103 | redis input batch: 1000, size: 5000, slow: 20 delay 0.060000 0.010000 0.070000 ( 0.020000) 104 | redis input batch: 250, size: 5000, slow: 20 delay 0.020000 0.010000 0.030000 ( 0.011000) 105 | redis input batch: 125, size: 5000, slow: 20 delay 0.020000 0.000000 0.020000 ( 0.017000) 106 | redis input batch: 100, size: 5000, slow: 20 delay 0.020000 0.010000 0.030000 ( 0.014000) 107 | redis input batch: 10, size: 5000, slow: 20 delay 0.060000 0.010000 0.070000 ( 0.051000) 108 | redis input batch: 1, size: 5000, slow: 20 delay 0.640000 0.170000 0.810000 ( 0.487000) 109 | 110 | redis input batch: 1000, size: 5000, slow: 20 delay 0.060000 0.010000 0.070000 ( 0.020000) 111 | redis input batch: 250, size: 5000, slow: 20 delay 0.030000 0.010000 0.040000 ( 0.014000) 112 | redis input batch: 125, size: 5000, slow: 20 delay 0.030000 0.000000 0.030000 ( 0.023000) 113 | redis input batch: 100, size: 5000, slow: 20 delay 0.030000 0.010000 0.040000 ( 0.030000) 114 | redis input batch: 10, size: 5000, slow: 20 delay 0.070000 0.020000 0.090000 ( 0.060000) 115 | redis input batch: 1, size: 5000, slow: 20 delay 0.690000 0.170000 0.860000 ( 0.492000) 116 | 117 | redis input batch: 1000, size: 5000, slow: 20 delay 0.080000 0.010000 0.090000 ( 0.035000) 118 | redis input batch: 250, size: 5000, slow: 20 delay 0.000000 0.000000 0.000000 ( 0.006000) 119 | redis input batch: 125, size: 5000, slow: 20 delay 0.020000 0.000000 0.020000 ( 0.016000) 120 | redis input batch: 100, size: 5000, slow: 20 delay 0.030000 0.010000 0.040000 ( 0.024000) 121 | redis input batch: 10, size: 5000, slow: 20 delay 0.070000 0.020000 0.090000 ( 0.067000) 122 | redis input batch: 1, size: 5000, slow: 20 delay 0.770000 0.190000 0.960000 ( 0.564000) 123 | 124 | redis input batch: 1000, size: 5000, slow: 20 delay 0.020000 0.000000 0.020000 ( 0.016000) 125 | redis input batch: 250, size: 5000, slow: 20 delay 0.020000 0.010000 0.030000 ( 0.016000) 126 | redis input batch: 125, size: 5000, slow: 20 delay 0.080000 0.020000 0.100000 ( 0.061000) 127 | redis input batch: 100, size: 5000, slow: 20 delay 0.100000 0.020000 0.120000 ( 0.045000) 128 | redis input batch: 10, size: 5000, slow: 20 delay 0.060000 0.020000 0.080000 ( 0.063000) 129 | redis input batch: 1, size: 5000, slow: 20 delay 0.790000 0.170000 0.960000 ( 0.525000) 130 | 131 | Larger latency 132 | user system total real 133 | redis input batch: 1000, size: 5000, slow: 2000 delay 2.380000 0.230000 2.610000 ( 0.514000) 134 | redis input batch: 250, size: 5000, slow: 2000 delay 1.760000 0.150000 1.910000 ( 0.357000) 135 | redis input batch: 125, size: 5000, slow: 2000 delay 2.220000 0.200000 2.420000 ( 0.491000) 136 | redis input batch: 100, size: 5000, slow: 2000 delay 2.600000 0.200000 2.800000 ( 0.581000) 137 | redis input batch: 10, size: 5000, slow: 2000 delay 2.640000 0.280000 2.920000 ( 0.752000) 138 | redis input batch: 1, size: 5000, slow: 2000 delay 2.880000 0.430000 3.310000 ( 1.263000) 139 | 140 | redis input batch: 1000, size: 5000, slow: 2000 delay 1.150000 0.060000 1.210000 ( 0.191000) 141 | redis input batch: 250, size: 5000, slow: 2000 delay 1.240000 0.060000 1.300000 ( 0.185000) 142 | redis input batch: 125, size: 5000, slow: 2000 delay 1.270000 0.060000 1.330000 ( 0.207000) 143 | redis input batch: 100, size: 5000, slow: 2000 delay 1.270000 0.060000 1.330000 ( 0.194000) 144 | redis input batch: 10, size: 5000, slow: 2000 delay 1.120000 0.100000 1.220000 ( 0.267000) 145 | redis input batch: 1, size: 5000, slow: 2000 delay 1.600000 0.250000 1.850000 ( 0.683000) 146 | 147 | redis input batch: 1000, size: 5000, slow: 2000 delay 1.100000 0.050000 1.150000 ( 0.164000) 148 | redis input batch: 250, size: 5000, slow: 2000 delay 1.080000 0.060000 1.140000 ( 0.179000) 149 | redis input batch: 125, size: 5000, slow: 2000 delay 1.020000 0.050000 1.070000 ( 0.169000) 150 | redis input batch: 100, size: 5000, slow: 2000 delay 1.050000 0.060000 1.110000 ( 0.170000) 151 | redis input batch: 10, size: 5000, slow: 2000 delay 0.910000 0.070000 0.980000 ( 0.189000) 152 | redis input batch: 1, size: 5000, slow: 2000 delay 1.470000 0.220000 1.690000 ( 0.618000) 153 | -------------------------------------------------------------------------------- /docs/index.asciidoc: -------------------------------------------------------------------------------- 1 | :plugin: redis 2 | :type: input 3 | :default_codec: json 4 | 5 | /////////////////////////////////////////// 6 | START - GENERATED VARIABLES, DO NOT EDIT! 7 | /////////////////////////////////////////// 8 | :version: %VERSION% 9 | :release_date: %RELEASE_DATE% 10 | :changelog_url: %CHANGELOG_URL% 11 | :include_path: ../../../../logstash/docs/include 12 | /////////////////////////////////////////// 13 | END - GENERATED VARIABLES, DO NOT EDIT! 14 | /////////////////////////////////////////// 15 | 16 | [id="plugins-{type}s-{plugin}"] 17 | 18 | === Redis input plugin 19 | 20 | include::{include_path}/plugin_header.asciidoc[] 21 | 22 | ==== Description 23 | 24 | This input will read events from a Redis instance; it supports both Redis channels and lists. 25 | The list command (BLPOP) used by Logstash is supported in Redis v1.3.1+, and 26 | the channel commands used by Logstash are found in Redis v1.3.8+. 27 | While you may be able to make these Redis versions work, the best performance 28 | and stability will be found in more recent stable versions. Versions 2.6.0+ 29 | are recommended. 30 | 31 | For more information about Redis, see 32 | 33 | `batch_count` note: If you use the `batch_count` setting, you *must* use a Redis version 2.6.0 or 34 | newer. Anything older does not support the operations used by batching. 35 | 36 | 37 | [id="plugins-{type}s-{plugin}-options"] 38 | ==== Redis Input Configuration Options 39 | 40 | This plugin supports the following configuration options plus the <> described later. 41 | 42 | [cols="<,<,<",options="header",] 43 | |======================================================================= 44 | |Setting |Input type|Required 45 | | <> |<>|No 46 | | <> |<>|No 47 | | <> |<>, one of `["list", "channel", "pattern_channel"]`|Yes 48 | | <> |<>|No 49 | | <> |<>|No 50 | | <> |<>|No 51 | | <> |<>|Yes 52 | | <> |<>|No 53 | | <> |<>|No 54 | | <> |<>|No 55 | | <> |<>|No 56 | | <> |<>|No 57 | |======================================================================= 58 | 59 | Also see <> for a list of options supported by all 60 | input plugins. 61 | 62 |   63 | 64 | [id="plugins-{type}s-{plugin}-batch_count"] 65 | ===== `batch_count` 66 | 67 | * Value type is <> 68 | * Default value is `125` 69 | 70 | The number of events to return from Redis using EVAL. 71 | 72 | [id="plugins-{type}s-{plugin}-command_map"] 73 | ===== `command_map` 74 | 75 | * Value type is <> 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 | 83 | [id="plugins-{type}s-{plugin}-data_type"] 84 | ===== `data_type` 85 | 86 | * This is a required setting. 87 | * Value can be any of: `list`, `channel`, `pattern_channel` 88 | * There is no default value for this setting. 89 | 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. 93 | 94 | [id="plugins-{type}s-{plugin}-db"] 95 | ===== `db` 96 | 97 | * Value type is <> 98 | * Default value is `0` 99 | 100 | The Redis database number. 101 | 102 | [id="plugins-{type}s-{plugin}-host"] 103 | ===== `host` 104 | 105 | * Value type is <> 106 | * Default value is `"127.0.0.1"` 107 | 108 | The hostname of your Redis server. 109 | 110 | [id="plugins-{type}s-{plugin}-path"] 111 | ===== `path` 112 | 113 | * Value type is <> 114 | * There is no default value for this setting. 115 | * Path will override Host configuration if both specified. 116 | 117 | The unix socket path of your Redis server. 118 | 119 | [id="plugins-{type}s-{plugin}-key"] 120 | ===== `key` 121 | 122 | * This is a required setting. 123 | * Value type is <> 124 | * There is no default value for this setting. 125 | 126 | The name of a Redis list or channel. 127 | 128 | [id="plugins-{type}s-{plugin}-password"] 129 | ===== `password` 130 | 131 | * Value type is <> 132 | * There is no default value for this setting. 133 | 134 | Password to authenticate with. There is no authentication by default. 135 | 136 | [id="plugins-{type}s-{plugin}-port"] 137 | ===== `port` 138 | 139 | * Value type is <> 140 | * Default value is `6379` 141 | 142 | The port to connect on. 143 | 144 | [id="plugins-{type}s-{plugin}-ssl"] 145 | ===== `ssl` 146 | 147 | * Value type is <> 148 | * Default value is `false` 149 | 150 | Enable SSL support. 151 | 152 | 153 | [id="plugins-{type}s-{plugin}-threads"] 154 | ===== `threads` 155 | 156 | * Value type is <> 157 | * Default value is `1` 158 | 159 | Number of instances of the input to start, each on its own thread. 160 | Increase from one to improve concurrency in consuming messages from Redis. 161 | 162 | NOTE: Increasing the number of threads when consuming from a channel will result in duplicate messages since a `SUBSCRIBE` delivers each message to all subscribers. 163 | 164 | [id="plugins-{type}s-{plugin}-timeout"] 165 | ===== `timeout` 166 | 167 | * Value type is <> 168 | * Default value is `5` 169 | 170 | Initial connection timeout in seconds. 171 | 172 | [id="plugins-{type}s-{plugin}-common-options"] 173 | include::{include_path}/{type}.asciidoc[] 174 | 175 | :default_codec!: 176 | -------------------------------------------------------------------------------- /lib/logstash/inputs/redis.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require "logstash/namespace" 3 | require "logstash/inputs/base" 4 | require "logstash/inputs/threadable" 5 | require 'redis' 6 | require "stud/interval" 7 | 8 | # This input will read events from a Redis instance; it supports both Redis channels and lists. 9 | # The list command (BLPOP) used by Logstash is supported in Redis v1.3.1+, and 10 | # the channel commands used by Logstash are found in Redis v1.3.8+. 11 | # While you may be able to make these Redis versions work, the best performance 12 | # and stability will be found in more recent stable versions. Versions 2.6.0+ 13 | # are recommended. 14 | # 15 | # For more information about Redis, see 16 | # 17 | # `batch_count` note: If you use the `batch_count` setting, you *must* use a Redis version 2.6.0 or 18 | # newer. Anything older does not support the operations used by batching. 19 | # 20 | module LogStash module Inputs class Redis < LogStash::Inputs::Threadable 21 | BATCH_EMPTY_SLEEP = 0.25 22 | 23 | config_name "redis" 24 | 25 | default :codec, "json" 26 | 27 | # The hostname of your Redis server. 28 | config :host, :validate => :string, :default => "127.0.0.1" 29 | 30 | # The port to connect on. 31 | config :port, :validate => :number, :default => 6379 32 | 33 | # SSL 34 | config :ssl, :validate => :boolean, :default => false 35 | 36 | # The unix socket path to connect on. Will override host and port if defined. 37 | # There is no unix socket path by default. 38 | config :path, :validate => :string 39 | 40 | # The Redis database number. 41 | config :db, :validate => :number, :default => 0 42 | 43 | # Initial connection timeout in seconds. 44 | config :timeout, :validate => :number, :default => 5 45 | 46 | # Password to authenticate with. There is no authentication by default. 47 | config :password, :validate => :password 48 | 49 | # The name of a Redis list or channel. 50 | config :key, :validate => :string, :required => true 51 | 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. 55 | config :data_type, :validate => [ "list", "channel", "pattern_channel" ], :required => true 56 | 57 | # The number of events to return from Redis using EVAL. 58 | config :batch_count, :validate => :number, :default => 125 59 | 60 | # Redefined Redis commands to be passed to the Redis client. 61 | config :command_map, :validate => :hash, :default => {} 62 | 63 | public 64 | 65 | def register 66 | @redis_url = @path.nil? ? "redis://#{@password}@#{@host}:#{@port}/#{@db}" : "#{@password}@#{@path}/#{@db}" 67 | 68 | # just switch on data_type once 69 | if @data_type == 'list' || @data_type == 'dummy' 70 | @run_method = method(:list_runner) 71 | @stop_method = method(:list_stop) 72 | elsif @data_type == 'channel' 73 | @run_method = method(:channel_runner) 74 | @stop_method = method(:subscribe_stop) 75 | elsif @data_type == 'pattern_channel' 76 | @run_method = method(:pattern_channel_runner) 77 | @stop_method = method(:subscribe_stop) 78 | end 79 | 80 | @list_method = batched? ? method(:list_batch_listener) : method(:list_single_listener) 81 | 82 | @identity = "#{@redis_url} #{@data_type}:#{@key}" 83 | @logger.info("Registering Redis", :identity => @identity) 84 | end # def register 85 | 86 | def run(output_queue) 87 | @run_method.call(output_queue) 88 | rescue LogStash::ShutdownSignal 89 | # ignore and quit 90 | end # def run 91 | 92 | def stop 93 | @stop_method.call 94 | end 95 | 96 | # private methods ----------------------------- 97 | private 98 | 99 | def batched? 100 | @batch_count > 1 101 | end 102 | 103 | # private 104 | def is_list_type? 105 | @data_type == 'list' 106 | end 107 | 108 | # private 109 | def redis_params 110 | params = { 111 | :timeout => @timeout, 112 | :db => @db, 113 | :password => @password.nil? ? nil : @password.value, 114 | :ssl => @ssl 115 | } 116 | 117 | if @path.nil? 118 | params[:host] = @host 119 | params[:port] = @port 120 | else 121 | @logger.warn("Parameter 'path' is set, ignoring parameters: 'host' and 'port'") 122 | params[:path] = @path 123 | end 124 | 125 | params 126 | end 127 | 128 | def new_redis_instance 129 | ::Redis.new(redis_params) 130 | end 131 | 132 | # private 133 | def connect 134 | redis = new_redis_instance 135 | 136 | # register any renamed Redis commands 137 | @command_map.each do |name, renamed| 138 | redis._client.command_map[name.to_sym] = renamed.to_sym 139 | end 140 | 141 | load_batch_script(redis) if batched? && is_list_type? 142 | 143 | redis 144 | end # def connect 145 | 146 | # private 147 | def load_batch_script(redis) 148 | #A Redis Lua EVAL script to fetch a count of keys 149 | redis_script = < e # parse or event creation error 167 | @logger.error("Failed to create event", :message => msg, :exception => e, :backtrace => e.backtrace); 168 | end 169 | end 170 | 171 | # private 172 | def list_stop 173 | redis = @redis # might change during method invocation 174 | return if redis.nil? || !redis.connected? 175 | 176 | redis.quit rescue nil # does client.disconnect internally 177 | # check if input retried while executing 178 | list_stop unless redis.equal? @redis 179 | @redis = nil 180 | end 181 | 182 | # private 183 | def list_runner(output_queue) 184 | while !stop? 185 | begin 186 | @redis ||= connect 187 | @list_method.call(@redis, output_queue) 188 | rescue => e 189 | log_error(e) 190 | retry if reset_for_error_retry(e) 191 | end 192 | end 193 | end 194 | 195 | def list_batch_listener(redis, output_queue) 196 | begin 197 | results = redis.evalsha(@redis_script_sha, [@key], [@batch_count-1]) 198 | results.each do |item| 199 | queue_event(item, output_queue) 200 | end 201 | 202 | if results.size.zero? 203 | sleep BATCH_EMPTY_SLEEP 204 | end 205 | 206 | # Below is a commented-out implementation of 'batch fetch' 207 | # using pipelined LPOP calls. This in practice has been observed to 208 | # perform exactly the same in terms of event throughput as 209 | # the evalsha method. Given that the EVALSHA implementation uses 210 | # one call to Redis instead of N (where N == @batch_count) calls, 211 | # I decided to go with the 'evalsha' method of fetching N items 212 | # from Redis in bulk. 213 | #redis.pipelined do 214 | #error, item = redis.lpop(@key) 215 | #(@batch_count-1).times { redis.lpop(@key) } 216 | #end.each do |item| 217 | #queue_event(item, output_queue) if item 218 | #end 219 | # --- End commented out implementation of 'batch fetch' 220 | # further to the above, the LUA script now uses lrange and trim 221 | # which should further improve the efficiency of the script 222 | rescue ::Redis::CommandError => e 223 | if e.to_s =~ /NOSCRIPT/ then 224 | @logger.warn("Redis may have been restarted, reloading Redis batch EVAL script", :exception => e); 225 | load_batch_script(redis) 226 | retry 227 | else 228 | raise e 229 | end 230 | end 231 | end 232 | 233 | def list_single_listener(redis, output_queue) 234 | item = redis.blpop(@key, 0, :timeout => 1) 235 | return unless item # from timeout or other conditions 236 | 237 | # blpop returns the 'key' read from as well as the item result 238 | # we only care about the result (2nd item in the list). 239 | queue_event(item.last, output_queue) 240 | end 241 | 242 | # private 243 | def subscribe_stop 244 | redis = @redis # might change during method invocation 245 | return if redis.nil? || !redis.connected? 246 | 247 | if redis.subscribed? 248 | if @data_type == 'pattern_channel' 249 | redis.punsubscribe 250 | else 251 | redis.unsubscribe 252 | end 253 | end 254 | redis.close rescue nil # does client.disconnect 255 | # check if input retried while executing 256 | subscribe_stop unless redis.equal? @redis 257 | @redis = nil 258 | end 259 | 260 | # private 261 | def redis_runner 262 | begin 263 | @redis ||= connect 264 | yield 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) 288 | end 289 | end 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 | 302 | # private 303 | def channel_runner(output_queue) 304 | redis_runner do 305 | channel_listener(output_queue) 306 | end 307 | end 308 | 309 | # private 310 | def channel_listener(output_queue) 311 | @redis.subscribe(@key) do |on| 312 | on.subscribe do |channel, count| 313 | @logger.info("Subscribed", :channel => channel, :count => count) 314 | end 315 | 316 | on.message do |channel, message| 317 | queue_event(message, output_queue, channel) 318 | end 319 | 320 | on.unsubscribe do |channel, count| 321 | @logger.info("Unsubscribed", :channel => channel, :count => count) 322 | end 323 | end 324 | end 325 | 326 | def pattern_channel_runner(output_queue) 327 | redis_runner do 328 | pattern_channel_listener(output_queue) 329 | end 330 | end 331 | 332 | # private 333 | def pattern_channel_listener(output_queue) 334 | @redis.psubscribe @key do |on| 335 | on.psubscribe do |channel, count| 336 | @logger.info("Subscribed", :channel => channel, :count => count) 337 | end 338 | 339 | on.pmessage do |pattern, channel, message| 340 | queue_event(message, output_queue, channel) 341 | end 342 | 343 | on.punsubscribe do |channel, count| 344 | @logger.info("Unsubscribed", :channel => channel, :count => count) 345 | end 346 | end 347 | end 348 | 349 | end end end # Redis Inputs LogStash 350 | -------------------------------------------------------------------------------- /logstash-input-redis.gemspec: -------------------------------------------------------------------------------- 1 | Gem::Specification.new do |s| 2 | 3 | s.name = 'logstash-input-redis' 4 | s.version = '3.7.1' 5 | s.licenses = ['Apache License (2.0)'] 6 | s.summary = "Reads events from a Redis instance" 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" 8 | s.authors = ["Elastic"] 9 | s.email = 'info@elastic.co' 10 | s.homepage = "http://www.elastic.co/guide/en/logstash/current/index.html" 11 | s.require_paths = ["lib"] 12 | 13 | # Files 14 | s.files = Dir["lib/**/*","spec/**/*","*.gemspec","*.md","CONTRIBUTORS","Gemfile","LICENSE","NOTICE.TXT", "vendor/jar-dependencies/**/*.jar", "vendor/jar-dependencies/**/*.rb", "VERSION", "docs/**/*"] 15 | 16 | # Tests 17 | s.test_files = s.files.grep(%r{^(test|spec|features)/}) 18 | 19 | # Special flag to let us know this is actually a logstash plugin 20 | s.metadata = { "logstash_plugin" => "true", "logstash_group" => "input" } 21 | 22 | # Gem dependencies 23 | s.add_runtime_dependency "logstash-core-plugin-api", ">= 1.60", "<= 2.99" 24 | 25 | s.add_runtime_dependency 'logstash-codec-json' 26 | s.add_runtime_dependency 'redis', '>= 4.0.1', '< 5' 27 | 28 | s.add_development_dependency 'logstash-devutils' 29 | end 30 | 31 | -------------------------------------------------------------------------------- /spec/inputs/redis_spec.rb: -------------------------------------------------------------------------------- 1 | require "logstash/devutils/rspec/spec_helper" 2 | require "logstash/devutils/rspec/shared_examples" 3 | require 'logstash/inputs/redis' 4 | require 'securerandom' 5 | 6 | def populate(key, event_count) 7 | require "logstash/event" 8 | require "redis" 9 | require "stud/try" 10 | redis = Redis.new(:host => "localhost") 11 | event_count.times do |value| 12 | event = LogStash::Event.new("sequence" => value) 13 | Stud.try(10.times) do 14 | redis.rpush(key, event.to_json) 15 | end 16 | end 17 | end 18 | 19 | def process(conf, event_count) 20 | events = input(conf) do |_, queue| 21 | sleep 0.1 until queue.size >= event_count 22 | queue.size.times.map { queue.pop } 23 | end 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) 29 | end 30 | 31 | # integration tests --------------------- 32 | 33 | describe "inputs/redis", :redis => true do 34 | 35 | it "should read events from a list" do 36 | key = SecureRandom.hex 37 | event_count = 1000 + rand(50) 38 | conf = <<-CONFIG 39 | input { 40 | redis { 41 | type => "blah" 42 | key => "#{key}" 43 | data_type => "list" 44 | batch_count => 1 45 | } 46 | } 47 | CONFIG 48 | 49 | populate(key, event_count) 50 | process(conf, event_count) 51 | end 52 | 53 | it "should read events from a list using batch_count (default 125)" do 54 | key = SecureRandom.hex 55 | event_count = 1000 + rand(50) 56 | conf = <<-CONFIG 57 | input { 58 | redis { 59 | type => "blah" 60 | key => "#{key}" 61 | data_type => "list" 62 | } 63 | } 64 | CONFIG 65 | 66 | populate(key, event_count) 67 | process(conf, event_count) 68 | end 69 | end 70 | 71 | describe LogStash::Inputs::Redis do 72 | let(:queue) { Queue.new } 73 | 74 | let(:data_type) { 'list' } 75 | let(:batch_count) { 1 } 76 | let(:config) { {'key' => 'foo', 'data_type' => data_type, 'batch_count' => batch_count} } 77 | let(:quit_calls) { [:quit] } 78 | 79 | subject do 80 | LogStash::Inputs::Redis.new(config) 81 | end 82 | 83 | context 'construction' do 84 | it 'registers the input' do 85 | expect { subject.register }.not_to raise_error 86 | end 87 | end 88 | 89 | context 'renamed redis commands' do 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 104 | } 105 | end 106 | 107 | it 'sets the renamed commands in the command map' do 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' 111 | end 112 | 113 | subject.register 114 | redis = subject.send :connect 115 | 116 | command_map = redis._client.command_map 117 | 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 125 | end 126 | 127 | it 'loads the batch script with the renamed command' do 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' 131 | 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)" 135 | end 136 | 137 | subject.register 138 | subject.send :connect 139 | end 140 | end 141 | 142 | context 'runtime for list data_type' do 143 | 144 | before do 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 153 | end 154 | 155 | context 'close when redis is unset' do 156 | 157 | it 'does not attempt to quit' do 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 162 | end 163 | end 164 | 165 | it 'calling the run method, adds events to the queue' do 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 193 | 194 | expect(subject.logger).to receive(:warn).with('Redis connection error', 195 | hash_including(:message=>"test", :exception=>Redis::CannotConnectError) 196 | ).and_call_original 197 | 198 | tt = Thread.new do 199 | sleep 2.0 # allow for retry (sleep) after handle_error 200 | subject.do_stop 201 | end 202 | 203 | subject.run(queue) 204 | 205 | tt.join 206 | 207 | try(3) { expect( queue.size ).to be > 0 } 208 | end 209 | 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 233 | 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 242 | end 243 | 244 | end 245 | 246 | context "when the batch size is greater than 1" do 247 | let(:batch_count) { 10 } 248 | 249 | it 'calling the run method, adds events to the queue' do 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":'], [] 254 | 255 | tt = Thread.new do 256 | sleep 0.25 257 | subject.do_stop 258 | end 259 | 260 | subject.run(queue) 261 | 262 | tt.join 263 | 264 | expect( queue.size ).to be > 0 265 | end 266 | end 267 | 268 | context "when there is no data" do 269 | let(:batch_count) { 10 } 270 | let(:rates) { [] } 271 | 272 | it 'will throttle the loop' do 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 276 | rates.unshift Time.now.to_f 277 | end.and_return [] 278 | 279 | tt = Thread.new do 280 | sleep 0.25 281 | subject.do_stop 282 | end 283 | 284 | subject.run(queue) 285 | 286 | tt.join 287 | 288 | inters = [] 289 | rates.each_cons(2) do |x, y| 290 | inters << x - y 291 | end 292 | 293 | expect( queue.size ).to eq(0) 294 | inters.each do |delta| 295 | expect(delta).to be_within(0.01).of(LogStash::Inputs::Redis::BATCH_EMPTY_SLEEP) 296 | end 297 | end 298 | end 299 | 300 | it 'multiple close calls, calls to redis once' do 301 | allow_any_instance_of( Redis::Client ).to receive(:connected?).and_return true, false 302 | # allow_any_instance_of( Redis::Client ).to receive(:disconnect) 303 | quit_calls.each do |call| 304 | allow_any_instance_of( Redis ).to receive(call).at_most(:once) 305 | end 306 | 307 | subject.do_stop 308 | expect { subject.do_stop }.not_to raise_error 309 | subject.do_stop 310 | end 311 | end 312 | 313 | context 'for the subscribe data_types' do 314 | 315 | before { subject.register } 316 | 317 | def run_it_thread(inst) 318 | Thread.new(inst) do |subj| 319 | subj.run(queue) 320 | end 321 | end 322 | 323 | def publish_thread(new_redis, prefix) 324 | Thread.new(new_redis, prefix) do |r, p| 325 | sleep 0.1 326 | 2.times do |i| 327 | r.publish('foo', "#{p}#{i.next}") 328 | end 329 | end 330 | end 331 | 332 | def close_thread(inst, rt) 333 | Thread.new(inst, rt) do |subj, runner| 334 | # block for the messages 335 | e1 = queue.pop 336 | e2 = queue.pop 337 | # put em back for the tests 338 | queue.push(e1) 339 | queue.push(e2) 340 | runner.raise(LogStash::ShutdownSignal) 341 | subj.close 342 | end 343 | end 344 | 345 | before(:example, type: :mocked) do 346 | subject.register 347 | allow_any_instance_of( Redis::Client ).to receive(:connected?).and_return true, false 348 | quit_calls.each do |call| 349 | allow_any_instance_of( Redis ).to receive(call).at_most(:once) 350 | end 351 | end 352 | 353 | context 'runtime for channel data_type' do 354 | let(:data_type) { 'channel' } 355 | let(:quit_calls) { [:unsubscribe, :connection] } 356 | 357 | before { subject.register } 358 | 359 | context 'mocked redis' do 360 | it 'multiple stop calls, calls to redis once', type: :mocked do 361 | subject.do_stop 362 | expect { subject.do_stop }.not_to raise_error 363 | subject.do_stop 364 | end 365 | end 366 | 367 | context 'real redis', :redis => true do 368 | it 'calling the run method, adds events to the queue' do 369 | #simulate the input thread 370 | rt = run_it_thread(subject) 371 | #simulate the other system thread 372 | publish_thread(subject.send(:new_redis_instance), 'c').join 373 | #simulate the pipeline thread 374 | close_thread(subject, rt).join 375 | 376 | expect(queue.size).to eq(2) 377 | end 378 | it 'events had redis_channel' do 379 | #simulate the input thread 380 | rt = run_it_thread(subject) 381 | #simulate the other system thread 382 | publish_thread(subject.send(:new_redis_instance), 'c').join 383 | #simulate the pipeline thread 384 | close_thread(subject, rt).join 385 | e1 = queue.pop 386 | e2 = queue.pop 387 | expect(e1.get('[@metadata][redis_channel]')).to eq('foo') 388 | expect(e2.get('[@metadata][redis_channel]')).to eq('foo') 389 | end 390 | end 391 | end 392 | 393 | context 'runtime for pattern_channel data_type' do 394 | let(:data_type) { 'pattern_channel' } 395 | let(:quit_calls) { [:punsubscribe, :connection] } 396 | 397 | context 'mocked redis' do 398 | it 'multiple stop calls, calls to redis once', type: :mocked do 399 | subject.do_stop 400 | expect { subject.do_stop }.not_to raise_error 401 | subject.do_stop 402 | end 403 | end 404 | 405 | context 'real redis', :redis => true do 406 | it 'calling the run method, adds events to the queue' do 407 | #simulate the input thread 408 | rt = run_it_thread(subject) 409 | #simulate the other system thread 410 | publish_thread(subject.send(:new_redis_instance), 'pc').join 411 | #simulate the pipeline thread 412 | close_thread(subject, rt).join 413 | 414 | expect(queue.size).to eq(2) 415 | end 416 | 417 | it 'events had redis_channel' do 418 | #simulate the input thread 419 | rt = run_it_thread(subject) 420 | #simulate the other system thread 421 | publish_thread(subject.send(:new_redis_instance), 'pc').join 422 | #simulate the pipeline thread 423 | close_thread(subject, rt).join 424 | e1 = queue.pop 425 | e2 = queue.pop 426 | expect(e1.get('[@metadata][redis_channel]')).to eq('foo') 427 | expect(e2.get('[@metadata][redis_channel]')).to eq('foo') 428 | end 429 | end 430 | end 431 | end 432 | 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 } } 443 | end 444 | end 445 | end 446 | 447 | end 448 | end 449 | --------------------------------------------------------------------------------