Skip to content

Commit 304eca4

Browse files
authored
Fix _id field in s3 and googlepubsub inputs (#17026)
In #15859 the Elasticsearch output was changed to read from the @metadata._id field when it had been using @metadata.id. The s3 and googlepubsub inputs had both been setting @metadata.id, but were not updated with that change. This updates the s3 and googlepubsub inputs to use `beat.Event#SetID()` rather than creating the metadata object themselves.
1 parent efdab6f commit 304eca4

3 files changed

Lines changed: 38 additions & 37 deletions

File tree

CHANGELOG.next.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
9292
- Fix merging of fileset inputs to replace paths and append processors. {pull}16450{16450}
9393
- Add queue_url definition in manifest file for aws module. {pull}16640{16640}
9494
- Fix issue where autodiscover hints default configuration was not being copied. {pull}16987[16987]
95+
- Fix Elasticsearch `_id` field set by S3 and Google Pub/Sub inputs. {pull}17026[17026]
9596

9697
*Heartbeat*
9798

x-pack/filebeat/input/googlepubsub/input.go

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -193,25 +193,24 @@ func makeTopicID(project, topic string) string {
193193
func makeEvent(topicID string, msg *pubsub.Message) beat.Event {
194194
id := topicID + "-" + msg.ID
195195

196-
fields := common.MapStr{
197-
"event": common.MapStr{
198-
"id": id,
199-
"created": time.Now().UTC(),
196+
event := beat.Event{
197+
Timestamp: msg.PublishTime.UTC(),
198+
Fields: common.MapStr{
199+
"event": common.MapStr{
200+
"id": id,
201+
"created": time.Now().UTC(),
202+
},
203+
"message": string(msg.Data),
200204
},
201-
"message": string(msg.Data),
205+
Private: msg,
202206
}
207+
event.SetID(id)
208+
203209
if len(msg.Attributes) > 0 {
204-
fields.Put("labels", msg.Attributes)
210+
event.PutValue("labels", msg.Attributes)
205211
}
206212

207-
return beat.Event{
208-
Timestamp: msg.PublishTime.UTC(),
209-
Meta: common.MapStr{
210-
"id": id,
211-
},
212-
Fields: fields,
213-
Private: msg,
214-
}
213+
return event
215214
}
216215

217216
func (in *pubsubInput) getOrCreateSubscription(ctx context.Context, client *pubsub.Client) (*pubsub.Subscription, error) {

x-pack/filebeat/input/s3/input.go

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -587,33 +587,34 @@ func (p *s3Input) deleteMessage(queueURL string, messagesReceiptHandle string, s
587587
}
588588

589589
func createEvent(log string, offset int, info s3Info, objectHash string, s3Ctx *s3Context) beat.Event {
590-
f := common.MapStr{
591-
"message": log,
592-
"log": common.MapStr{
593-
"offset": int64(offset),
594-
"file.path": constructObjectURL(info),
595-
},
596-
"aws": common.MapStr{
597-
"s3": common.MapStr{
598-
"bucket": common.MapStr{
599-
"name": info.name,
600-
"arn": info.arn},
601-
"object.key": info.key,
590+
s3Ctx.Inc()
591+
592+
event := beat.Event{
593+
Timestamp: time.Now().UTC(),
594+
Fields: common.MapStr{
595+
"message": log,
596+
"log": common.MapStr{
597+
"offset": int64(offset),
598+
"file.path": constructObjectURL(info),
599+
},
600+
"aws": common.MapStr{
601+
"s3": common.MapStr{
602+
"bucket": common.MapStr{
603+
"name": info.name,
604+
"arn": info.arn},
605+
"object.key": info.key,
606+
},
607+
},
608+
"cloud": common.MapStr{
609+
"provider": "aws",
610+
"region": info.region,
602611
},
603612
},
604-
"cloud": common.MapStr{
605-
"provider": "aws",
606-
"region": info.region,
607-
},
613+
Private: s3Ctx,
608614
}
615+
event.SetID(objectHash + "-" + fmt.Sprintf("%012d", offset))
609616

610-
s3Ctx.Inc()
611-
return beat.Event{
612-
Timestamp: time.Now(),
613-
Fields: f,
614-
Meta: common.MapStr{"id": objectHash + "-" + fmt.Sprintf("%012d", offset)},
615-
Private: s3Ctx,
616-
}
617+
return event
617618
}
618619

619620
func constructObjectURL(info s3Info) string {

0 commit comments

Comments
 (0)