Skip to content

Commit 86c3e63

Browse files
authored
[Filebeat] Add timeout to GetObjectRequest for s3 input (#15590)
* Add timeout to GetObjectRequest which will cancel the request if it takes too long * Close resp.Body from S3 GetObject API to prevent resource leak * Change aws_api_timeout to api_timeout
1 parent 387bae0 commit 86c3e63

File tree

16 files changed

+314
-150
lines changed

16 files changed

+314
-150
lines changed

CHANGELOG.next.asciidoc

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
5555

5656
*Filebeat*
5757

58+
- Fix s3 input hanging with GetObjectRequest API call by adding context_timeout config. {issue}15502[15502] {pull}15590[15590]
5859
- Add shared_credential_file to cloudtrail config {issue}15652[15652] {pull}15656[15656]
5960
- Fix typos in zeek notice fileset config file. {issue}15764[15764] {pull}15765[15765]
6061

x-pack/filebeat/docs/inputs/input-aws-s3.asciidoc

+10-2
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ URL of the AWS SQS queue that messages will be received from. Required.
4545
[float]
4646
==== `visibility_timeout`
4747

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

64+
[float]
65+
==== `api_timeout`
66+
67+
The maximum duration of AWS API can take. If it exceeds the timeout, AWS API
68+
will be interrupted.
69+
The default AWS API timeout for a message is 120 seconds. The minimum
70+
is 0 seconds. The maximum is half of the visibility timeout value.
71+
6472
["source","json"]
6573
----
6674
{

x-pack/filebeat/filebeat.reference.yml

+32
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@ filebeat.modules:
111111
# If not set the default profile is used
112112
#var.credential_profile_name: fb-aws
113113

114+
# The duration that the received messages are hidden from ReceiveMessage request
115+
# Default to be 300s
116+
#var.visibility_timeout: 300s
117+
118+
# Maximum duration before AWS API request will be interrupted
119+
# Default to be 120s
120+
#var.api_timeout: 120s
121+
114122
elb:
115123
enabled: false
116124

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

137+
# The duration that the received messages are hidden from ReceiveMessage request
138+
# Default to be 300s
139+
#var.visibility_timeout: 300s
140+
141+
# Maximum duration before AWS API request will be interrupted
142+
# Default to be 120s
143+
#var.api_timeout: 120s
144+
129145
vpcflow:
130146
enabled: false
131147

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

160+
# The duration that the received messages are hidden from ReceiveMessage request
161+
# Default to be 300s
162+
#var.visibility_timeout: 300s
163+
164+
# Maximum duration before AWS API request will be interrupted
165+
# Default to be 120s
166+
#var.api_timeout: 120s
167+
144168
cloudtrail:
145169
enabled: false
146170

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

183+
# The duration that the received messages are hidden from ReceiveMessage request
184+
# Default to be 300s
185+
#var.visibility_timeout: 300s
186+
187+
# Maximum duration before AWS API request will be interrupted
188+
# Default to be 120s
189+
#var.api_timeout: 120s
190+
159191
#-------------------------------- Azure Module --------------------------------
160192
- module: azure
161193
# All logs

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

+6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type config struct {
1818
VisibilityTimeout time.Duration `config:"visibility_timeout"`
1919
AwsConfig awscommon.ConfigAWS `config:",inline"`
2020
ExpandEventListFromField string `config:"expand_event_list_from_field"`
21+
APITimeout time.Duration `config:"api_timeout"`
2122
}
2223

2324
func defaultConfig() config {
@@ -26,6 +27,7 @@ func defaultConfig() config {
2627
Type: "s3",
2728
},
2829
VisibilityTimeout: 300 * time.Second,
30+
APITimeout: 120 * time.Second,
2931
}
3032
}
3133

@@ -34,5 +36,9 @@ func (c *config) Validate() error {
3436
return fmt.Errorf("visibility timeout %v is not within the "+
3537
"required range 0s to 12h", c.VisibilityTimeout)
3638
}
39+
if c.APITimeout < 0 || c.APITimeout > c.VisibilityTimeout/2 {
40+
return fmt.Errorf("api timeout %v needs to be larger than"+
41+
" 0s and smaller than half of the visibility timeout", c.APITimeout)
42+
}
3743
return nil
3844
}

0 commit comments

Comments
 (0)