Comments (6)
This patch removes the check on if kv
exists, it seems to fix this issues:
--- lib/logstash/filters/kv.rb 2014-04-29 21:37:18.335010728 +0000
+++ lib/logstash/filters/kv.rb 2014-04-29 21:37:20.230012427 +0000
@@ -182,23 +182,22 @@
# Add default key-values for missing keys
kv = @default_keys.merge(kv)
- # If we have any keys, create/append the hash
- if kv.length > 0
- if @target.nil?
- # Default is to write to the root of the event.
- dest = event.to_hash
+ # If we have any keys, create/append the hash.
+ # If we don't, at least set @target as expected.
+ if @target.nil?
+ # Default is to write to the root of the event.
+ dest = event.to_hash
+ else
+ if !event[@target].is_a?(Hash)
+ @logger.debug("Overwriting existing target field", :target => @target)
+ dest = event[@target] = {}
else
- if !event[@target].is_a?(Hash)
- @logger.debug("Overwriting existing target field", :target => @target)
- dest = event[@target] = {}
- else
- dest = event[@target]
- end
+ dest = event[@target]
end
-
- dest.merge!(kv)
- filter_matched(event)
end
+
+ dest.merge!(kv)
+ filter_matched(event)
end # def filter
private
from logstash.
Thanks for reporting this and you solution proposal. We will review this. Is it possible for you to submit a pull request with your changes? Also it would be great if you could add specs for this in spec/filters/kv.rb
. Let us know if you need help with writing specs.
from logstash.
@avleen If I'm reading your report correctly, you're saying that if you have kv { source => "foo" target => "foo" }
and an event { "foo": "bar" }
(no kv to parse!) that the result should be { "foo": { } }
?
from logstash.
Example -
% bin/logstash -e 'filter { kv { source => "message" target => "message" } }'
hello=world
{
"message" => {
"hello" => "world"
},
...
}
fancy pants
{
"message" => "fancy pants",
...
}
In the 2nd case, no kv was matched and left the original source alone (as a string). This would cause Elasticsearch to be upset if it the field were mapped as an object, right?
I'm not sure what the best default behavior would be, here.
Options when @source
== @target
:
- Promote
@target
to be empty hash{}
as proposed by @avleen (I think?). This would cause data loss because we obliterate the old value. - Promote
@target
to be a hash of{ "_original" => <original field value> }
so it's still a hash but we don't lose data.
Thoughts?
from logstash.
That's correct. This comes down to object mappings and potential loss of
data.
@target should always become a hash. Either it ends up empty, or it has
some data. But it's always a hash. If it's empty, just drop it at the end
of the run.
I think the user should get a choice in whether @target is overwritten, or
if the original is preserved. Different people may expect different things.
On Fri Jan 23 2015 at 2:28:29 PM Jordan Sissel [email protected]
wrote:
Example -
% bin/logstash -e 'filter { kv { source => "message" target => "message" } }'
hello=world
{
"message" => {
"hello" => "world"
},
...
}fancy pants
{
"message" => "fancy pants",
...
}In the 2nd case, no kv was matched and left the original source alone (as
a string). This would cause Elasticsearch to be upset if it the field were
mapped as an object, right?I'm not sure what the best default behavior would be, here.
Options when @source == @target:
- Promote @target to be empty hash {} as proposed by @avleen
https://github.com/avleen (I think?). This would cause data loss
because we obliterate the old value.- Promote @target to be a hash of { "_original" => } so it's still a hash but we don't lose data.
Thoughts?
Reply to this email directly or view it on GitHub
#1315 (comment)
.
from logstash.
For Logstash 1.5.0, we've moved all plugins to individual repositories, so I have moved this issue to logstash-plugins/logstash-filter-kv#11. Let's continue the discussion there! :)
from logstash.
Related Issues (20)
- Logstash crashes when running with JRE instead of JDK
- Logstash Ingest Pipeline Converter Does not handle "copy_from" option for Set processor
- "No Available connections" container vs host HOT 3
- Inputs using schedulers can hang when trying to restart pipelines
- Remove/replace unnecessary stack trace print lines.
- Improve pipeline reload feature.
- Docs: Logstash 7.17.21 release docs
- Docs: Logstash 8.13.3 release docs
- Exception if Connection between beat and Logstash is closed
- Vulnerability found in logstash-oss:8.13.2 HOT 2
- Doc: Add VPR landing page placeholder for new snmp-integration
- Doc: Add LSR landing page placeholder for new snmp-integration
- Document already exist (http 409) cases document improvements. HOT 1
- [Stack monitoring] Doc improvements
- OSS issue in "Developing Logstash Core"
- JSON formatted logs aren't suitable for ingestion into elasticsearch
- Docs: Logstash 8.13.4 release docs
- Update guide for monitoring with Elastic Agent to include also `` role
- Exceptions thrown in CompiledPipeline constructor lose stack trace context
- Doc: SNMP integration: Manage messaging and set user expections during rollout HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from logstash.