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

Add line number counter for multiline #2279

Closed
wants to merge 1 commit into from

Conversation

ruflin
Copy link
Contributor

@ruflin ruflin commented Aug 16, 2016

This allows to indicate if an event was multiline or not. The number of lines will be put under the multiline namespace and looks as following:

{
  ...
  "message": "[2015] hello world\n  First Line\n  Second Line",
  "multiline": {
    "lines": 3
  },
  ...
}

See elastic#957

@ruflin ruflin added Filebeat Filebeat in progress Pull request is currently in progress. review labels Aug 16, 2016
}
reader.Content, reader.Fields = r.decodeJSON(reader.Content)
return reader, nil
var fields = common.MapStr{}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be var fields common.MapStr since you don't need to allocate a MapStr because decodeJSON will be returning one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

@ruflin
Copy link
Contributor Author

ruflin commented Aug 17, 2016

#2290 should be reviewed and merged first as it will require additional changes in this PR.

@@ -99,6 +99,13 @@ func (h *Harvester) Harvest() {
event.Text = &text
event.JSONFields = message.Fields
event.EventMetadata = h.config.EventMetadata
if message.Fields != nil {
if event.EventMetadata.Fields != nil {
event.EventMetadata.Fields.Update(message.Fields)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this overwriting EventMetadata.Fields or does it create a new common.MapStr internally? EventMetadata directly uses config.EventMetadata.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will get more obvious when is merged: #2290 Meta data addition and merging should not be a task of the harvester.

@ruflin ruflin force-pushed the multiline-lines branch 3 times, most recently from 6469e3f to 509dd52 Compare September 2, 2016 11:43
@ruflin ruflin force-pushed the multiline-lines branch 3 times, most recently from 76a3a7b to 517ff24 Compare September 19, 2016 13:10
@ruflin ruflin removed the in progress Pull request is currently in progress. label Sep 19, 2016
@@ -225,6 +227,8 @@ func (mlr *Multiline) clear() {
// finalize writes the existing content into the returned message and resets all reader variables.
func (mlr *Multiline) finalize() Message {

lines := common.MapStr{"lines": mlr.numLines}
mlr.message.AddFields(common.MapStr{"multiline": lines})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What will happen if someone defines json or multiline as fields in the config file, together with fields_under_root?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Our current behaviour here is that is that fields will overwrite it. For json the behaviour does not change here. So in case someone has

fields: 
  json: "Hello world"

already now, this would overwrite the fields from the json reader. The same applies multiline. So I think the behaviour didn't change even though I was never really thinking of the json overwriting by fields before. Seems like it wasn't an issue so far. The good thing is that we have it even mentioned in our docs: https://www.elastic.co/guide/en/beats/filebeat/1.3/configuration-filebeat-options.html#fields-under-root

@ruflin ruflin force-pushed the multiline-lines branch 2 times, most recently from da69d9e to 5fc39ec Compare November 18, 2016 16:02
@ruflin ruflin added in progress Pull request is currently in progress. and removed review labels Nov 21, 2016
ruflin added a commit to ruflin/beats that referenced this pull request Nov 21, 2016
Each reader can add fields to the message object. The reader itself should always add data under its own namespace to prevent conflicts. All these fields are then added to the Data object. This will allow each reader in the future to add its own data if needed.

The JSON reader was simplified in the way that data by default is written under the `json` namespace. Now no special fields have to be passed for JSON and the processing can still happen on the event level.

This PR was extracted from elastic#2279
urso pushed a commit that referenced this pull request Nov 22, 2016
* Refactor fields handling with readers

Each reader can add fields to the message object. The reader itself should always add data under its own namespace to prevent conflicts. All these fields are then added to the Data object. This will allow each reader in the future to add its own data if needed.

The JSON reader was simplified in the way that data by default is written under the `json` namespace. Now no special fields have to be passed for JSON and the processing can still happen on the event level.

This PR was extracted from #2279

* Add comment and switch field
suraj-soni pushed a commit to suraj-soni/beats that referenced this pull request Dec 15, 2016
* Refactor fields handling with readers

Each reader can add fields to the message object. The reader itself should always add data under its own namespace to prevent conflicts. All these fields are then added to the Data object. This will allow each reader in the future to add its own data if needed.

The JSON reader was simplified in the way that data by default is written under the `json` namespace. Now no special fields have to be passed for JSON and the processing can still happen on the event level.

This PR was extracted from elastic#2279

* Add comment and switch field
@ruflin ruflin force-pushed the multiline-lines branch 2 times, most recently from c1a10fe to 34b1234 Compare February 2, 2017 20:36
@ruflin ruflin added review and removed in progress Pull request is currently in progress. labels Feb 3, 2017
@ruflin ruflin force-pushed the multiline-lines branch 2 times, most recently from ba8d0d3 to 54b882b Compare February 3, 2017 09:00
@monicasarbu
Copy link
Contributor

@ruflin Can you please rebase this PR?

@ruflin ruflin force-pushed the multiline-lines branch 2 times, most recently from 5d18acc to 1865dcf Compare September 25, 2017 14:27
This allows to indicate if an event was multiline or not. The number of lines will be put under the multiline namespace and looks as following:

```
{
  ...
  "message": "[2015] hello world\n  First Line\n  Second Line",
  "multiline": {
    "lines": 3
  },
  ...
}
```

See elastic#957
@ruflin
Copy link
Contributor Author

ruflin commented Oct 9, 2017

Closing this PR as no request for this feature has shown up recently.

@ruflin ruflin closed this Oct 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants