Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List pattern support #81

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

juusom
Copy link

@juusom juusom commented Apr 8, 2020

Add support for reading from list patterns such as logstash.*. Related issue: #49

The motivation in our case is that we want to be able to see and control when individual applications produce spammy logs for whatever reason. In those situations, it's also important to be able to guarantee some level of fairness when consuming the queues, as opposed to having just one queue dominated by a potentially misbehaving application.

The implementation supports consuming single items per list using LPOP, as well as batched consuming using the same EVAL based logic as the regular list data_type input.

The logic is based on using a configurable-size concurrent-ruby thread pool. The main loop keeps polling the key pattern using the KEYS command and whenever the thread pool queue isn't full, posts a new job to the thread pool for consuming a single key. It keeps track of the keys currently queued and makes sure there's only one job per key at a time.

I also did some refactoring and wanted to do more but decided to make this PR before going further in order to get some opinions. So far I extracted the Redis connection logic as a MixIn - it's all in a single commit and can be reverted if need be. (edit: scratch that, I reverted this bit already, for now) What I'd like to do is make all the 3 different use cases (list, pattern list, PubSub) independent classes implementing an interface. It's currently quite messy with so much unrelated code in a single class.

I'm not a Ruby developer (although I did gather input from colleagues who are) so let me know if there's anything silly, or if this somehow violates any logstash/elastic practices :)

@cla-checker-service
Copy link

cla-checker-service bot commented Apr 8, 2020

💚 CLA has been signed

@juusom juusom force-pushed the list-pattern-input branch from a26004a to 12e270c Compare April 8, 2020 05:13
@bbmhmmad
Copy link

@juusom im unable to get this to work after installing logstash-input-redis off this branch. Logstash is not pulling redis messages.

Redis Key: new.data.2020-06-16-01-24-21

input {

    redis {
        host => "iris-redis-slave"
        port => 6379
        data_type => "list"
        password => "${TL_REDIS_PASSWORD}"
        key   => "new.data*"
        threads => 4
        batch_count => 1000
    }

@juusom
Copy link
Author

juusom commented Jun 16, 2020

Thanks for your interest in this @bbmhmmad! In your config snippet, the data type is wrong. It should be pattern_list. Also, you probably don't want to use threads to configure this, but instead use pattern_list_threads.

@juusom juusom force-pushed the list-pattern-input branch from 5a1298b to 944c713 Compare May 7, 2021 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants