Skip to content

Cherry-pick #24741 to 7.x: Fix nil panic when overwriting metadata#25180

Merged
jsoriano merged 1 commit intoelastic:7.xfrom
jsoriano:backport_24741_7.x
Apr 20, 2021
Merged

Cherry-pick #24741 to 7.x: Fix nil panic when overwriting metadata#25180
jsoriano merged 1 commit intoelastic:7.xfrom
jsoriano:backport_24741_7.x

Conversation

@jsoriano
Copy link
Copy Markdown
Member

@jsoriano jsoriano commented Apr 20, 2021

Cherry-pick of PR #24741 to 7.x branch. Original message:

What does this PR do?

I'm using Filebeat writing data into Kafka and having another Filebeat reading from Kafka. I got this error when I was trying to decode the message field into root-level via decode_json_fields processor.

panic: assignment to entry in nil map

goroutine 105 [running]:
github.com/elastic/beats/libbeat/common.MapStr.Update(0x0, 0xc0001620c0)
	/go/src/github.com/elastic/beats/libbeat/common/mapstr.go:61 +0xd3
github.com/elastic/beats/libbeat/common/jsontransform.WriteJSONKeys(0xc0000b8080, 0xc000162090, 0x101)
	/go/src/github.com/elastic/beats/libbeat/common/jsontransform/jsonhelper.go:67 +0x9ad
github.com/elastic/beats/libbeat/processors/actions.(*decodeJSONFields).Run(0xc0001710c0, 0xc0000b8080, 0xc00017bb00, 0x0, 0x0)
	/go/src/github.com/elastic/beats/libbeat/processors/actions/decode_json_fields.go:145 +0x751
github.com/elastic/beats/libbeat/publisher/processing.(*group).Run(0xc000768d50, 0xc0000b8080, 0xc0000b8080, 0x0, 0x0)
	/go/src/github.com/elastic/beats/libbeat/publisher/processing/processors.go:104 +0x94
github.com/elastic/beats/libbeat/publisher/processing.(*group).Run(0xc000768d20, 0xc0000b8080, 0x203000, 0x7f10562985b0, 0x7f1056295ff8)
	/go/src/github.com/elastic/beats/libbeat/publisher/processing/processors.go:104 +0x94
github.com/elastic/beats/libbeat/publisher/pipeline.(*client).publish(0xc000184f80, 0xe3ed9c0, 0xed7ed39c7, 0x3da5020, 0x0, 0xc00017abd0, 0x2551760, 0xc0001b8410, 0x0)
	/go/src/github.com/elastic/beats/libbeat/publisher/pipeline/client.go:89 +0x571
github.com/elastic/beats/libbeat/publisher/pipeline.(*client).Publish(0xc000184f80, 0xe3ed9c0, 0xed7ed39c7, 0x3da5020, 0x0, 0xc00017abd0, 0x2551760, 0xc0001b8410, 0x0)
	/go/src/github.com/elastic/beats/libbeat/publisher/pipeline/client.go:68 +0xc2
github.com/elastic/beats/filebeat/channel.(*outlet).OnEvent(0xc000768f60, 0xe3ed9c0, 0xed7ed39c7, 0x3da5020, 0x0, 0xc00017abd0, 0x2551760, 0xc0001b8410, 0x0, 0x0)
	/go/src/github.com/elastic/beats/filebeat/channel/outlet.go:64 +0x7e
github.com/elastic/beats/filebeat/input/kafka.(*groupHandler).ConsumeClaim(0xc000164000, 0x2a49a00, 0xc0007b6080, 0x2a3cd60, 0xc000495c80, 0xa, 0x0)
	/go/src/github.com/elastic/beats/filebeat/input/kafka/input.go:332 +0x1c5
github.com/elastic/beats/vendor/github.com/Shopify/sarama.(*consumerGroupSession).consume(0xc0007b6080, 0xc00027f380, 0xa, 0x0)
	/go/src/github.com/elastic/beats/vendor/github.com/Shopify/sarama/consumer_group.go:615 +0x27f
github.com/elastic/beats/vendor/github.com/Shopify/sarama.newConsumerGroupSession.func2(0xc0007b6080, 0xc00027f380, 0xa, 0xc000000000)
	/go/src/github.com/elastic/beats/vendor/github.com/Shopify/sarama/consumer_group.go:544 +0xd0
created by github.com/elastic/beats/vendor/github.com/Shopify/sarama.newConsumerGroupSession
	/go/src/github.com/elastic/beats/vendor/github.com/Shopify/sarama/consumer_group.go:536 +0x526

Why is it important?

The Filebeat process will crash without the fix.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in CHANGELOG.next.asciidoc or CHANGELOG-developer.next.asciidoc.

How to test this PR locally

using unittest.

Related issues

Note

Filebeat will actually output JSONs with duplicated keys when I'm trying to overwrite the @metadata field. And I'm not pretty sure if that's good for beats. Check the example below:

Filebeat configuration

filebeat.inputs:
  - type: stdin
    enabled: true
output.console:
    enabled: true

processors:
  - decode_json_fields:
      fields: [ "message" ]
      target: ""
      overwrite_keys: true

Input

{"@timestamp":"2021-03-24T12:17:54.978Z","@metadata":{"beat":"filebeat","type":"_doc","version":"7.0.0"},"message":"overwrite metadata test"}

Output

{"@timestamp":"2021-03-24T12:17:54.978Z","@metadata":{"beat":"filebeat","type":"_doc","version":"8.0.0","type":"_doc","version":"7.0.0","beat":"filebeat"},"log":{"offset":0,"file":{"path":""}},"message":"overwrite metadata test","input":{"type":"stdin"},"agent":{"name":"MacBook","type":"filebeat","version":"8.0.0","ephemeral_id":"ephemeral_id","id":"id"},"ecs":{"version":"1.8.0"},"host":{"name":"MacBook"}}

Fix panic when overwriting metadata using the  decode_json_fields processor.

(cherry picked from commit ce680e1)
@jsoriano jsoriano added [zube]: In Review backport Team:Elastic-Agent Label for the Agent team Team:Integrations Label for the Integrations team labels Apr 20, 2021
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Apr 20, 2021
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/agent (Team:Agent)

@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/integrations (Team:Integrations)

@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Apr 20, 2021
@elasticmachine
Copy link
Copy Markdown
Contributor

elasticmachine commented Apr 20, 2021

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview

Expand to view the summary

Build stats

  • Build Cause: jsoriano commented: /test

  • Start Time: 2021-04-20T20:36:48.939+0000

  • Duration: 47 min 13 sec

  • Commit: fa88da8

Test stats 🧪

Test Results
Failed 0
Passed 231
Skipped 15
Total 246

Trends 🧪

Image of Build Times

Image of Tests

💚 Flaky test report

Tests succeeded.

Expand to view the summary

Test stats 🧪

Test Results
Failed 0
Passed 231
Skipped 15
Total 246

@jsoriano
Copy link
Copy Markdown
Member Author

/test

@jsoriano jsoriano merged commit 82e1226 into elastic:7.x Apr 20, 2021
@jsoriano jsoriano deleted the backport_24741_7.x branch April 20, 2021 21:26
@zube zube bot removed the [zube]: Done label Jul 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport Team:Elastic-Agent Label for the Agent team Team:Integrations Label for the Integrations team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants