Skip to content

Commit

Permalink
Check context.Canceled and fix s3 input config (#22036)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaiyan-sheng authored Oct 22, 2020
1 parent 5d07709 commit cc2217c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@
#session_token: '${AWS_SESSION_TOKEN:"”}'
#credential_profile_name: test-s3-input

# Queue urls (required) to receive queue messages from
#queue_urls: ["https://sqs.us-east-1.amazonaws.com/1234/test-s3-logs-queue"]
# Queue url (required) to receive queue messages from
#queue_url: "https://sqs.us-east-1.amazonaws.com/1234/test-s3-logs-queue"

# The duration (in seconds) that the received messages are hidden from subsequent
# retrieve requests after being retrieved by a ReceiveMessage request.
Expand Down
4 changes: 2 additions & 2 deletions x-pack/filebeat/filebeat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2410,8 +2410,8 @@ filebeat.inputs:
#session_token: '${AWS_SESSION_TOKEN:"”}'
#credential_profile_name: test-s3-input

# Queue urls (required) to receive queue messages from
#queue_urls: ["https://sqs.us-east-1.amazonaws.com/1234/test-s3-logs-queue"]
# Queue url (required) to receive queue messages from
#queue_url: "https://sqs.us-east-1.amazonaws.com/1234/test-s3-logs-queue"

# The duration (in seconds) that the received messages are hidden from subsequent
# retrieve requests after being retrieved by a ReceiveMessage request.
Expand Down
2 changes: 2 additions & 0 deletions x-pack/filebeat/input/s3/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,10 @@ func (c *s3Collector) processorKeepAlive(svcSQS sqsiface.ClientAPI, message sqs.
for {
select {
case <-c.cancellation.Done():
fmt.Println("------- c.cancellation.Done()")
return nil
case err := <-errC:
fmt.Println("------- err = ", err)
if err != nil {
if err == context.DeadlineExceeded {
c.logger.Info("Context deadline exceeded, updating visibility timeout")
Expand Down
8 changes: 7 additions & 1 deletion x-pack/filebeat/input/s3/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package s3

import (
"context"
"fmt"

"github.com/aws/aws-sdk-go-v2/service/s3"
Expand Down Expand Up @@ -67,7 +68,12 @@ func (in *s3Input) Run(ctx v2.Context, pipeline beat.Pipeline) error {

defer collector.publisher.Close()
collector.run()
return ctx.Cancelation.Err()

if ctx.Cancelation.Err() == context.Canceled {
return nil
} else {
return ctx.Cancelation.Err()
}
}

func (in *s3Input) createCollector(ctx v2.Context, pipeline beat.Pipeline) (*s3Collector, error) {
Expand Down

0 comments on commit cc2217c

Please sign in to comment.