logstash-plugins / logstash-filter-memcached

Memcached Filter plugin for Logstash
Apache License 2.0
4 stars 11 forks source link

filter_matched is called regardless of get or set success #4

Closed guyboertje closed 5 years ago

guyboertje commented 5 years ago

Means that tags will always be added and can be used in conditionals to test whether the value is in the cache.

Consider the following config, the conditional must test for a missing field that should have been filled and this field must either not exist or have a known value that is not at all like the the value that could be in the cache. It would be better if filter_matched is called on successful get or set.

input {
  generator {
    message => '12345.67'
    count => 1
  }
}
filter {
  mutate {
    rename => {
      "message" => "millimeters"
    }
  }
  memcached {
    hosts => ["localhost"]
    get => {
      "neutrinoapi_convert_mm_to_in" => "[inches]"
    }
  }
  if ![inches] {
    http {
      url => "https://neutrinoapi.com/convert"
      body => {
        "user-id" => "a-user"
        "api-key" => "i479hT-------5A03rQSm"
        "from-value" => "%{millimeters}"
        "from-type" => "mm"
        "to-type" => "inch"
      }
      verb => "POST"
      body_format => "json"
      target_body => "neutrinoapi_convert_mm_to_in"
      add_tag => ["from_api"]
    }
    memcached {
      hosts => ["localhost"]
      set => {
        "[neutrinoapi_convert_mm_to_in][result]" => "neutrinoapi_convert_mm_to_in"
      }
    }
    mutate {
      copy => {"[neutrinoapi_convert_mm_to_in][result]" => "[inches]"}
      remove_field => ["neutrinoapi_convert_mm_to_in"]
    }
  } else {
    mutate {
      add_tag => ["from_cache"]
    }
  }
}
output {
  stdout { codec => rubydebug }
}