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

New filter plugin: logstash-filter-lrucache #8530

Closed
sw-jung opened this issue Oct 25, 2017 · 2 comments
Closed

New filter plugin: logstash-filter-lrucache #8530

sw-jung opened this issue Oct 25, 2017 · 2 comments

Comments

@sw-jung
Copy link

sw-jung commented Oct 25, 2017

I want contribute my new plugin logstash-filter-lrucache to logstash-plugins.

This plugin provides caching using the LRU(Least Recently Used) algorithm.

It based on lru_redux.

Example of usage

filter {
  # Find `blacklisted_at` value for particular `host` in cache.
  lrucache {
    namespace => "blacklisted_at"
    action => "get"
    key => "%{host}"
    target => "blacklisted_at"
  }

  if ![blacklisted_at] {
    # If no value is found in cache, Query to elasticsearch.
    elasticsearch {
      query => "host:%{host}"
      index => "blacklist"
      fields => { "@timestamp" => "blacklisted_at" }
    }

    if [blacklisted_at] {
      # Store query result into cache.
      lrucache {
        namespace => "blacklisted_at"
        action => "set"
        key => "%{host}"
        value => "%{blacklisted_at}"
      }
    }
  }

  if [blacklisted_at] {
    # Drop incoming log from blacklisted host.
    drop {}
  }
}

Links

@sw-jung
Copy link
Author

sw-jung commented Oct 26, 2017

This is a plugin created because I can't wait for the logstash-elasticsearch-filter's cache support. ( See this issue)

But I don't like the structure of this plugin.

At first I wanted to create a plugin that looks like this:

filter {
  memoize {
    key => "%{cache_key}"
    fields => ["fields_for_result_expected"]
    filter => elasticsearch {
      # ...
    }
  }
}

But I failed. because grammer parsers always parse nested plugins as codecs!

{ "filter" => plugin("codec", "elasticsearch", ...) }

Do anyone have a solution to this problem?

@sw-jung
Copy link
Author

sw-jung commented Oct 26, 2017

I'm sorry, but I've found a solution to the above problem so I'll re-contribute after implementation new. It expect looks like this:

filter {
  memoize {
    key => "%{cache_key}"
    fields => ["fields_for_result_expected"]
    filter_name => "elasticsearch"
    filter_body => { ... }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant