Skip to content

Commit ea77363

Browse files
authored
Set api timeout to 10s by default and make configurable via settings (#20)
1 parent 8813c2a commit ea77363

File tree

2 files changed

+29
-21
lines changed

2 files changed

+29
-21
lines changed

crates/fig_api_client/src/clients/shared.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
use std::time::Duration;
2+
13
use aws_config::Region;
4+
use aws_config::timeout::TimeoutConfig;
25
use aws_credential_types::Credentials;
36
use aws_credential_types::provider::ProvideCredentials;
47
use aws_types::SdkConfig;
8+
use aws_types::sdk_config::StalledStreamProtectionConfig;
59
use fig_aws_common::behavior_version;
610

711
use crate::credentials::CredentialsChain;
@@ -10,10 +14,34 @@ use crate::{
1014
Error,
1115
};
1216

17+
const DEFAULT_TIMEOUT_DURATION: Duration = Duration::from_millis(10100);
18+
19+
pub(crate) fn timeout_config() -> TimeoutConfig {
20+
let timeout = fig_settings::settings::get_int("api.timeout")
21+
.ok()
22+
.flatten()
23+
.and_then(|i| i.try_into().ok())
24+
.map_or(DEFAULT_TIMEOUT_DURATION, Duration::from_millis);
25+
26+
TimeoutConfig::builder()
27+
.read_timeout(timeout)
28+
.operation_timeout(timeout)
29+
.operation_attempt_timeout(timeout)
30+
.connect_timeout(timeout)
31+
.build()
32+
}
33+
34+
pub(crate) fn stalled_stream_protection_config() -> StalledStreamProtectionConfig {
35+
StalledStreamProtectionConfig::enabled()
36+
.grace_period(Duration::from_secs(100))
37+
.build()
38+
}
39+
1340
async fn base_sdk_config(region: Region, credentials_provider: impl ProvideCredentials + 'static) -> SdkConfig {
1441
aws_config::defaults(behavior_version())
1542
.region(region)
1643
.credentials_provider(credentials_provider)
44+
.timeout_config(timeout_config())
1745
.load()
1846
.await
1947
}

crates/fig_api_client/src/clients/streaming_client.rs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
use std::time::Duration;
2-
31
use amzn_codewhisperer_streaming_client::Client as CodewhispererStreamingClient;
42
use amzn_qdeveloper_streaming_client::Client as QDeveloperStreamingClient;
5-
use aws_config::timeout::TimeoutConfig;
63
use aws_types::request_id::RequestId;
7-
use aws_types::sdk_config::StalledStreamProtectionConfig;
84
use fig_auth::builder_id::BearerResolver;
95
use fig_aws_common::{
106
UserAgentOverrideInterceptor,
@@ -14,6 +10,7 @@ use fig_aws_common::{
1410
use super::shared::{
1511
bearer_sdk_config,
1612
sigv4_sdk_config,
13+
stalled_stream_protection_config,
1714
};
1815
use crate::interceptor::opt_out::OptOutInterceptor;
1916
use crate::model::{
@@ -25,21 +22,6 @@ use crate::{
2522
Error,
2623
};
2724

28-
fn stalled_stream_protection_config() -> StalledStreamProtectionConfig {
29-
StalledStreamProtectionConfig::enabled()
30-
.grace_period(Duration::from_secs(100))
31-
.build()
32-
}
33-
34-
fn timeout_config() -> TimeoutConfig {
35-
TimeoutConfig::builder()
36-
.read_timeout(Duration::from_secs(10))
37-
.operation_timeout(Duration::from_secs(10))
38-
.operation_attempt_timeout(Duration::from_secs(10))
39-
.connect_timeout(Duration::from_secs(10))
40-
.build()
41-
}
42-
4325
mod inner {
4426
use amzn_codewhisperer_streaming_client::Client as CodewhispererStreamingClient;
4527
use amzn_qdeveloper_streaming_client::Client as QDeveloperStreamingClient;
@@ -81,7 +63,6 @@ impl StreamingClient {
8163
.app_name(app_name())
8264
.endpoint_url(endpoint.url())
8365
.stalled_stream_protection(stalled_stream_protection_config())
84-
.timeout_config(timeout_config())
8566
.build();
8667
let client = CodewhispererStreamingClient::from_conf(conf);
8768
Self(inner::Inner::Codewhisperer(client))
@@ -96,7 +77,6 @@ impl StreamingClient {
9677
.app_name(app_name())
9778
.endpoint_url(endpoint.url())
9879
.stalled_stream_protection(stalled_stream_protection_config())
99-
.timeout_config(timeout_config())
10080
.build();
10181
let client = QDeveloperStreamingClient::from_conf(conf);
10282
Ok(Self(inner::Inner::QDeveloper(client)))

0 commit comments

Comments
 (0)