Skip to content

Commit 08fd684

Browse files
authored
refactor: retry middleware name change; rm unsigned types from imds config (#409)
1 parent dd8af57 commit 08fd684

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/config/imds/ImdsClient.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
package aws.sdk.kotlin.runtime.config.imds
77

88
import aws.sdk.kotlin.runtime.AwsServiceException
9-
import aws.sdk.kotlin.runtime.client.AwsClientOption
109
import aws.sdk.kotlin.runtime.http.ApiMetadata
1110
import aws.sdk.kotlin.runtime.http.AwsUserAgentMetadata
1211
import aws.sdk.kotlin.runtime.http.engine.crt.CrtHttpEngine
@@ -17,12 +16,11 @@ import aws.smithy.kotlin.runtime.client.SdkLogMode
1716
import aws.smithy.kotlin.runtime.http.*
1817
import aws.smithy.kotlin.runtime.http.engine.HttpClientEngine
1918
import 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
2120
import aws.smithy.kotlin.runtime.http.operation.*
2221
import aws.smithy.kotlin.runtime.http.response.HttpResponse
2322
import aws.smithy.kotlin.runtime.io.Closeable
2423
import aws.smithy.kotlin.runtime.io.middleware.Phase
25-
import aws.smithy.kotlin.runtime.logging.Logger
2624
import aws.smithy.kotlin.runtime.retries.impl.*
2725
import aws.smithy.kotlin.runtime.time.Clock
2826
import aws.smithy.kotlin.runtime.util.Platform
@@ -34,7 +32,7 @@ import kotlin.time.ExperimentalTime
3432
* Maximum time allowed by default (6 hours)
3533
*/
3634
internal 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

3937
private const val SERVICE = "imds"
4038

@@ -61,9 +59,7 @@ public interface InstanceMetadataProvider : Closeable {
6159
public 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

codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsDefaultRetryIntegration.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ class AwsDefaultRetryIntegration : KotlinIntegration {
2323
override fun customizeMiddleware(
2424
ctx: ProtocolGenerator.GenerationContext,
2525
resolved: List<ProtocolMiddleware>
26-
): List<ProtocolMiddleware> = resolved.replace(middleware) { it.name == StandardRetryMiddleware.name }
26+
): List<ProtocolMiddleware> = resolved.replace(middleware) { it is StandardRetryMiddleware }
2727
}
2828

2929
private val middleware = object : HttpFeatureMiddleware() {
30-
override val name: String = "RetryFeature"
30+
override val name: String = "Retry"
3131

3232
override fun renderConfigure(writer: KotlinWriter) {
33-
writer.addImport(RuntimeTypes.Http.Middlware.RetryFeature)
33+
writer.addImport(RuntimeTypes.Http.Middlware.Retry)
3434
writer.addImport(AwsRuntimeTypes.Http.Retries.AwsDefaultRetryPolicy)
3535

3636
writer.write("strategy = config.retryStrategy")

0 commit comments

Comments
 (0)