66package aws.sdk.kotlin.runtime.config.imds
77
88import aws.sdk.kotlin.runtime.AwsServiceException
9- import aws.sdk.kotlin.runtime.client.AwsClientOption
109import aws.sdk.kotlin.runtime.http.ApiMetadata
1110import aws.sdk.kotlin.runtime.http.AwsUserAgentMetadata
1211import aws.sdk.kotlin.runtime.http.engine.crt.CrtHttpEngine
@@ -17,12 +16,11 @@ import aws.smithy.kotlin.runtime.client.SdkLogMode
1716import aws.smithy.kotlin.runtime.http.*
1817import aws.smithy.kotlin.runtime.http.engine.HttpClientEngine
1918import aws.smithy.kotlin.runtime.http.middleware.ResolveEndpoint
20- import aws.smithy.kotlin.runtime.http.middleware.RetryFeature
19+ import aws.smithy.kotlin.runtime.http.middleware.Retry
2120import aws.smithy.kotlin.runtime.http.operation.*
2221import aws.smithy.kotlin.runtime.http.response.HttpResponse
2322import aws.smithy.kotlin.runtime.io.Closeable
2423import aws.smithy.kotlin.runtime.io.middleware.Phase
25- import aws.smithy.kotlin.runtime.logging.Logger
2624import aws.smithy.kotlin.runtime.retries.impl.*
2725import aws.smithy.kotlin.runtime.time.Clock
2826import aws.smithy.kotlin.runtime.util.Platform
@@ -34,7 +32,7 @@ import kotlin.time.ExperimentalTime
3432 * Maximum time allowed by default (6 hours)
3533 */
3634internal const val DEFAULT_TOKEN_TTL_SECONDS : Int = 21_600
37- internal const val DEFAULT_MAX_RETRIES : UInt = 3u
35+ internal const val DEFAULT_MAX_RETRIES : Int = 3
3836
3937private const val SERVICE = " imds"
4038
@@ -61,9 +59,7 @@ public interface InstanceMetadataProvider : Closeable {
6159public class ImdsClient private constructor(builder : Builder ) : InstanceMetadataProvider {
6260 public constructor () : this (Builder ())
6361
64- private val logger = Logger .getLogger<ImdsClient >()
65-
66- private val maxRetries: UInt = builder.maxRetries
62+ private val maxRetries: Int = builder.maxRetries
6763 private val endpointConfiguration: EndpointConfiguration = builder.endpointConfiguration
6864 private val tokenTtl: Duration = builder.tokenTtl
6965 private val clock: Clock = builder.clock
@@ -72,6 +68,7 @@ public class ImdsClient private constructor(builder: Builder) : InstanceMetadata
7268 private val httpClient: SdkHttpClient
7369
7470 init {
71+ require(maxRetries > 0 ) { " maxRetries must be greater than zero" }
7572 val engine = builder.engine ? : CrtHttpEngine {
7673 connectTimeout = Duration .seconds(1 )
7774 socketReadTimeout = Duration .seconds(1 )
@@ -88,10 +85,14 @@ public class ImdsClient private constructor(builder: Builder) : InstanceMetadata
8885 UserAgent .create {
8986 staticMetadata = AwsUserAgentMetadata .fromEnvironment(ApiMetadata (SERVICE , " unknown" ))
9087 },
91- RetryFeature .create {
88+ Retry .create {
9289 val tokenBucket = StandardRetryTokenBucket (StandardRetryTokenBucketOptions .Default )
9390 val delayProvider = ExponentialBackoffWithJitter (ExponentialBackoffWithJitterOptions .Default )
94- strategy = StandardRetryStrategy (StandardRetryStrategyOptions .Default , tokenBucket, delayProvider)
91+ strategy = StandardRetryStrategy (
92+ StandardRetryStrategyOptions .Default .copy(maxAttempts = maxRetries),
93+ tokenBucket,
94+ delayProvider
95+ )
9596 policy = ImdsRetryPolicy ()
9697 },
9798 // must come after retries
@@ -138,7 +139,6 @@ public class ImdsClient private constructor(builder: Builder) : InstanceMetadata
138139 operationName = path
139140 service = SERVICE
140141 // artifact of re-using ServiceEndpointResolver middleware
141- set(AwsClientOption .Region , " not-used" )
142142 set(SdkClientOption .LogMode , sdkLogMode)
143143 }
144144 }
@@ -160,7 +160,7 @@ public class ImdsClient private constructor(builder: Builder) : InstanceMetadata
160160 /* *
161161 * The maximum number of retries for fetching tokens and metadata
162162 */
163- public var maxRetries: UInt = DEFAULT_MAX_RETRIES
163+ public var maxRetries: Int = DEFAULT_MAX_RETRIES
164164
165165 /* *
166166 * The endpoint configuration to use when making requests
0 commit comments