-
Notifications
You must be signed in to change notification settings - Fork 46
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
Feat: (optional) event target => namespace support #80
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea of a namespaced event, but I think there are a couple more things to consider.
First, the Event API handles the @timestamp
top-level field and sub-fields of [@metadata]
in distinct ways that we should likely consider when building a wrapper. How should these behave when a plugin is working with a namespaced subset of the event?
Second, I am hesitant to include the event target decorator in the ECS Compatibility Support adapter (which currently has a single responsibility) simply because it is part of the same effort. My hope with these adapter gems is to give us a clear path for introducing and consuming simple new APIs in Logstash, and I worry that introducing or maintaining multiple APIs in a single adapter gem will add complexity that is hard to test. If a plugin needs to use multiple new APIs, I believe it is much simpler if they simply include/activate explicitly what they need (making testing of interactions a responsibility of the plugin that needs the interactions).
As far as usage goes, it would be convenient to have an Event#namespace(ns, &block)
method that yielded a namespaced decorator/proxy (or yielded the event itself if no namespace was given; this could be provided via Logstash core or via an adapter gem). Would Ruby 2.3's Refinements be a good way to allow plugins to explicitly use this behaviour instead of having a plugin that monkey-patches the entire Event class?
class Event
# ...
##
# @param target_namespace [String,nil]: a field-reference style string indicating the target namespace
# @yieldparam [Event]: an event whose functionality is relative to the provided target_namespace
# @return [Void]
def namespace(target_namespace)
if target_namespace.nil? || target_namespace.empty?
yield self
else
yield EventTargetDecorator.wrap(self, target_namespace)
end
end
end
lib/logstash/codecs/cef.rb
Outdated
event = LogStash::Event.new | ||
event.set(raw_data_field, data) unless raw_data_field.nil? | ||
event = EventTargetDecorator.wrap(event_factory.new_event, @target) | ||
event.set_raw(raw_data_field, data) unless raw_data_field.nil? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not convinced we need a set_raw
for the decorator; we could bind the unnamespaced event to a local variable as we did previously, then bind a namespaced wrapper of it to another local variable and use the two indepndently based on our need. In a push, we could include a raw
method on the decorator as an accessor for the unnamespaced event.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kk - its a bit redundant
not against the idea - let's have a refinements might be a solution, and I am not against trying those out in the long run, but its uses so far out-there just made things more confusing in terms of readability + its not that used in the wild e.g. Rails has pretty much zero refinement adoption (due bugs in MRI). |
this is unclear, but another option would be to simply make the decorator only handle some ( might be for an architectural discussion but do you recall a place where user configuration allows for an arbitrary event selector?
okay, will try to put up a PR for a think we really need to start with something 0.X and take it from there - migrating a few plugins. |
While the Event API has a special accessor for Additionally, calls to many of the event apis take field references, and when the given field reference starts with IMO these are not reasons to hold back, but we should explore and document these edge-cases, and find solutions to them where practical.
The CSV Codec takes column names (individual field reference destinations per field) as configuration. Config-driven field names is also a prolific pattern in filters and in many inputs that pull directly from datastores. |
also a step towards using an ECS-like event factory.
kares/logstash-mixin-ecs_compatibility_support@pre-1.0.0...events
EventFactory
adapter will need to exist somewhere (even after its added to LS itself)target => ns
easily is also something needed due ECS(not directly ecs-relevant but cna always get extracted later)
resolves #35