-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Refactor input.Event similar to outputs.Data #3823
Changes from 3 commits
d63d93b
dd89989
c78db55
3a620e6
33c9e1f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,24 +11,37 @@ import ( | |
|
||
// Event is sent to the output and must contain all relevant information | ||
type Event struct { | ||
common.EventMetadata | ||
ReadTime time.Time | ||
InputType string | ||
DocumentType string | ||
Bytes int | ||
Text *string | ||
JSONConfig *reader.JSONConfig | ||
State file.State | ||
Data common.MapStr // Use in readers to add data to the event | ||
EventMeta | ||
Text *string | ||
JSONConfig *reader.JSONConfig | ||
Data common.MapStr // Use in readers to add data to the event | ||
|
||
} | ||
|
||
type EventMeta struct { | ||
Pipeline string | ||
Fileset string | ||
Module string | ||
InputType string | ||
DocumentType string | ||
common.EventMetadata | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lets move the common.EventMetadata to the the first line of EventMeta There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||
ReadTime time.Time | ||
Bytes int | ||
State file.State | ||
} | ||
|
||
type EventHolder struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we rename |
||
Event common.MapStr | ||
Metadata EventMeta | ||
} | ||
|
||
func NewEvent(state file.State) *Event { | ||
return &Event{ | ||
State: state, | ||
EventMeta: EventMeta{ | ||
State: state, | ||
}, | ||
} | ||
|
||
} | ||
|
||
func (e *Event) ToMapStr() common.MapStr { | ||
|
@@ -68,21 +81,36 @@ func (e *Event) ToMapStr() common.MapStr { | |
return event | ||
} | ||
|
||
func (e *Event) GetEventHolder() EventHolder { | ||
return EventHolder{ | ||
Event: e.ToMapStr(), | ||
Metadata: EventMeta{ | ||
Pipeline: e.Pipeline, | ||
Bytes: e.Bytes, | ||
State: e.State, | ||
Fileset: e.Fileset, | ||
Module: e.Module, | ||
ReadTime: e.ReadTime, | ||
EventMetadata: e.EventMetadata, | ||
}, | ||
} | ||
} | ||
|
||
// Metadata creates a common.MapStr containing the metadata to | ||
// be associated with the event. | ||
func (e *Event) Metadata() common.MapStr { | ||
if e.Pipeline != "" { | ||
func (eh *EventHolder) GetMetadata() common.MapStr { | ||
if eh.Metadata.Pipeline != "" { | ||
return common.MapStr{ | ||
"pipeline": e.Pipeline, | ||
"pipeline": eh.Metadata.Pipeline, | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
// HasData returns true if the event itself contains data | ||
// Events without data are only state updates | ||
func (e *Event) HasData() bool { | ||
return e.Bytes > 0 | ||
func (eh *EventHolder) HasData() bool { | ||
return eh.Metadata.Bytes > 0 | ||
} | ||
|
||
// mergeJSONFields writes the JSON fields in the event map, | ||
|
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.
So currently we have EventMeta twice, means two copies of the data? What would be the affect if we not have it in the Event? I think we will need in the future processors to have access to the meta data too, but do we need this in the first step?
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.
Event will be used in harvesters and when it reaches the processor, we do a event.GetEventHolder(), which would (you are right), copy the metadata from Event to EventHolder and generate the MapStr. But after that since Event object goes out of scope, it would be garbage collected if I am not wrong. Would that be an issue? Today when we generate the common.MapStr, we copy all the log related fields over. Now with this change, we additionally copy over the meta fields as well. Please correct me if I'm wrong.