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

[Filebeat] Add timeout to GetObjectRequest for s3 input #15590

Merged
merged 22 commits into from
Jan 28, 2020
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
445aaf2
Add timeout to GetObjectRequest which will cancel the request if it t…
kaiyan-sheng Jan 15, 2020
90350ff
Add changelog
kaiyan-sheng Jan 15, 2020
269ea66
Add context_timeout into config for all aws filesets
kaiyan-sheng Jan 16, 2020
32678e7
fix unit test
kaiyan-sheng Jan 16, 2020
3093ffa
Merge remote-tracking branch 'upstream/master' into handle_s3_objects
kaiyan-sheng Jan 16, 2020
dee7785
Close resp.Body from S3 GetObject API to prevent resource leak
kaiyan-sheng Jan 17, 2020
adf908a
fix unit test
kaiyan-sheng Jan 17, 2020
b211663
close resp.Body after getS3ObjectResponse function
kaiyan-sheng Jan 21, 2020
c0c511e
use context.WithTimeout for GetObjectRequest
kaiyan-sheng Jan 21, 2020
48e85f2
Add timeout to p.context
kaiyan-sheng Jan 22, 2020
5859549
Merge remote-tracking branch 'upstream/master' into handle_s3_objects
kaiyan-sheng Jan 22, 2020
bb5201f
Fix unit test for s3 input
kaiyan-sheng Jan 22, 2020
1a09c74
Add cancelFn for context.WithTimeout
kaiyan-sheng Jan 23, 2020
a1e4e18
Change context_timeout to aws_api_timeout
kaiyan-sheng Jan 23, 2020
fb07d96
create separate ctx with timeout for each request
kaiyan-sheng Jan 23, 2020
1c63a8f
Change AwsApiTimeout to AwsAPITimeout
kaiyan-sheng Jan 23, 2020
47b6fbe
fix typo
kaiyan-sheng Jan 23, 2020
8b7c544
Fix aws_api_timeout name in configs
kaiyan-sheng Jan 24, 2020
2b85538
Change back to use channelContext
kaiyan-sheng Jan 24, 2020
cbb92e7
Remove predefine cancelFn
kaiyan-sheng Jan 24, 2020
f4f8cbd
improve info message
kaiyan-sheng Jan 24, 2020
1cafa79
Change aws_api_timeout to api_timeout
kaiyan-sheng Jan 24, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ TLS or Beats that accept connections over TLS and validate client certificates.

*Filebeat*

- Fix s3 input hanging with GetObjectRequest API call by adding context_timeout config. {issue}15502[15502] {pull}15590[15590]
- Add shared_credential_file to cloudtrail config {issue}15652[15652] {pull}15656[15656]

*Heartbeat*
Expand Down
12 changes: 10 additions & 2 deletions x-pack/filebeat/docs/inputs/input-aws-s3.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ URL of the AWS SQS queue that messages will be received from. Required.
[float]
==== `visibility_timeout`

The duration (in seconds) that the received messages are hidden from subsequent
The duration that the received messages are hidden from subsequent
retrieve requests after being retrieved by a ReceiveMessage request.
This value needs to be a lot bigger than filebeat collection frequency so
This value needs to be a lot bigger than Filebeat collection frequency so
kaiyan-sheng marked this conversation as resolved.
Show resolved Hide resolved
if it took too long to read the s3 log, this sqs message will not be reprocessed.
The default visibility timeout for a message is 300 seconds. The minimum
is 0 seconds. The maximum is 12 hours.
Expand All @@ -61,6 +61,14 @@ can be assigned the name of the field. This setting will be able to split the
messages under the group value into separate events. For example, CloudTrail logs
are in JSON format and events are found under the JSON object "Records":

[float]
==== `context_timeout`

The maximum duration of GetObjectRequest AWS API can take. If it exceeds the
timeout, GetObjectRequest will be interrupted.
The default context timeout for a message is 120 seconds. The minimum
is 0 seconds. The maximum is half of the visibility timeout value.

["source","json"]
----
{
Expand Down
32 changes: 32 additions & 0 deletions x-pack/filebeat/filebeat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ filebeat.modules:
# If not set the default profile is used
#var.credential_profile_name: fb-aws

# The duration that the received messages are hidden from ReceiveMessage request
# Default to be 300s
#var.visibility_timeout: 300s
kaiyan-sheng marked this conversation as resolved.
Show resolved Hide resolved

# Maximum duration before GetObject request will be interrupted by context
# Default to be 120s
#var.context_timeout: 120s

elb:
enabled: false

Expand All @@ -126,6 +134,14 @@ filebeat.modules:
# If not set the default profile is used
#var.credential_profile_name: fb-aws

# The duration that the received messages are hidden from ReceiveMessage request
# Default to be 300s
#var.visibility_timeout: 300s

# Maximum duration before GetObject request will be interrupted by context
# Default to be 120s
#var.context_timeout: 120s

vpcflow:
enabled: false

Expand All @@ -141,6 +157,14 @@ filebeat.modules:
# If not set the default profile is used
#var.credential_profile_name: fb-aws

# The duration that the received messages are hidden from ReceiveMessage request
# Default to be 300s
#var.visibility_timeout: 300s

# Maximum duration before GetObject request will be interrupted by context
# Default to be 120s
#var.context_timeout: 120s

cloudtrail:
enabled: false

Expand All @@ -156,6 +180,14 @@ filebeat.modules:
# If not set the default profile is used
#var.credential_profile_name: fb-aws

# The duration that the received messages are hidden from ReceiveMessage request
# Default to be 300s
#var.visibility_timeout: 300s

# Maximum duration before GetObject request will be interrupted by context
# Default to be 120s
#var.context_timeout: 120s

#-------------------------------- Azure Module --------------------------------
- module: azure
# All logs
Expand Down
6 changes: 6 additions & 0 deletions x-pack/filebeat/input/s3/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type config struct {
VisibilityTimeout time.Duration `config:"visibility_timeout"`
AwsConfig awscommon.ConfigAWS `config:",inline"`
ExpandEventListFromField string `config:"expand_event_list_from_field"`
ContextTimeout time.Duration `config:"context_timeout"`
kaiyan-sheng marked this conversation as resolved.
Show resolved Hide resolved
}

func defaultConfig() config {
Expand All @@ -26,6 +27,7 @@ func defaultConfig() config {
Type: "s3",
},
VisibilityTimeout: 300 * time.Second,
ContextTimeout: 120 * time.Second,
}
}

Expand All @@ -34,5 +36,9 @@ func (c *config) Validate() error {
return fmt.Errorf("visibility timeout %v is not within the "+
"required range 0s to 12h", c.VisibilityTimeout)
}
if c.ContextTimeout < 0 || c.ContextTimeout > c.VisibilityTimeout/2 {
return fmt.Errorf("context timeout %v needs to be larger than"+
" 0s and smaller than half of the visibility timeout", c.ContextTimeout)
}
return nil
}
Loading