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

misc: Upgrade to Kotlin 2.1.0 #1479

Merged
merged 8 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions .changes/0833e425-f3e6-4bea-a4ce-c2b73f7f39b6.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"id": "0833e425-f3e6-4bea-a4ce-c2b73f7f39b6",
"type": "misc",
"description": "⚠️ **IMPORTANT**: Upgrade to Kotlin 2.1.0",
"requiresMinorVersionBump": true
}
12 changes: 2 additions & 10 deletions aws-runtime/aws-http/api/aws-http.api
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,6 @@ public final class aws/sdk/kotlin/runtime/http/interceptors/AddUserAgentMetadata
public fun readBeforeTransmit (Laws/smithy/kotlin/runtime/client/ProtocolRequestInterceptorContext;)V
}

public final class aws/sdk/kotlin/runtime/http/interceptors/AwsBusinessMetric : java/lang/Enum, aws/smithy/kotlin/runtime/businessmetrics/BusinessMetric {
public static final field DDB_MAPPER Laws/sdk/kotlin/runtime/http/interceptors/AwsBusinessMetric;
public static final field S3_EXPRESS_BUCKET Laws/sdk/kotlin/runtime/http/interceptors/AwsBusinessMetric;
public static fun getEntries ()Lkotlin/enums/EnumEntries;
public fun getIdentifier ()Ljava/lang/String;
public fun toString ()Ljava/lang/String;
public static fun valueOf (Ljava/lang/String;)Laws/sdk/kotlin/runtime/http/interceptors/AwsBusinessMetric;
public static fun values ()[Laws/sdk/kotlin/runtime/http/interceptors/AwsBusinessMetric;
}

public final class aws/sdk/kotlin/runtime/http/interceptors/AwsSpanInterceptor : aws/smithy/kotlin/runtime/client/Interceptor {
public static final field INSTANCE Laws/sdk/kotlin/runtime/http/interceptors/AwsSpanInterceptor;
public fun modifyBeforeAttemptCompletion-gIAlu-s (Laws/smithy/kotlin/runtime/client/ResponseInterceptorContext;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
Expand Down Expand Up @@ -197,9 +187,11 @@ public final class aws/sdk/kotlin/runtime/http/interceptors/UnsupportedSigningAl
}

public final class aws/sdk/kotlin/runtime/http/interceptors/businessmetrics/AwsBusinessMetric : java/lang/Enum, aws/smithy/kotlin/runtime/businessmetrics/BusinessMetric {
public static final field DDB_MAPPER Laws/sdk/kotlin/runtime/http/interceptors/businessmetrics/AwsBusinessMetric;
public static final field S3_EXPRESS_BUCKET Laws/sdk/kotlin/runtime/http/interceptors/businessmetrics/AwsBusinessMetric;
public static fun getEntries ()Lkotlin/enums/EnumEntries;
public fun getIdentifier ()Ljava/lang/String;
public fun toString ()Ljava/lang/String;
public static fun valueOf (Ljava/lang/String;)Laws/sdk/kotlin/runtime/http/interceptors/businessmetrics/AwsBusinessMetric;
public static fun values ()[Laws/sdk/kotlin/runtime/http/interceptors/businessmetrics/AwsBusinessMetric;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,26 @@ import aws.smithy.kotlin.runtime.businessmetrics.BusinessMetric
import aws.smithy.kotlin.runtime.businessmetrics.emitBusinessMetric
import aws.smithy.kotlin.runtime.collections.MutableAttributes
import aws.smithy.kotlin.runtime.collections.toMutableAttributes
import aws.smithy.kotlin.runtime.telemetry.logging.Logger

/**
* Makes sure the metrics do not exceed the maximum size and truncates them if so.
* Makes sure that metric identifiers are not > 2 chars in length. Skips them if so.
*/
internal fun formatMetrics(metrics: MutableSet<BusinessMetric>): String {
if (metrics.isEmpty()) return ""
val metricsString = metrics.joinToString(",", "m/") { it.identifier }
internal fun formatMetrics(metrics: MutableSet<BusinessMetric>, logger: Logger): String {
val allowedMetrics = metrics.filter {
if (it.identifier.length > 2) {
logger.warn {
"Business metric '${it.identifier}' will be skipped due to length being > 2. " +
"This is likely a bug. Please raise an issue at https://github.com/awslabs/aws-sdk-kotlin/issues/new/choose"
}
false
} else {
true
}
}
if (allowedMetrics.isEmpty()) return ""
val metricsString = allowedMetrics.joinToString(",", "m/") { it.identifier }
val metricsByteArray = metricsString.encodeToByteArray()

if (metricsByteArray.size <= BUSINESS_METRICS_MAX_LENGTH) return metricsString
Expand All @@ -41,6 +54,7 @@ internal fun formatMetrics(metrics: MutableSet<BusinessMetric>): String {
@InternalApi
public enum class AwsBusinessMetric(public override val identifier: String) : BusinessMetric {
S3_EXPRESS_BUCKET("J"),
DDB_MAPPER("d"),
;

@InternalApi
Expand All @@ -64,6 +78,8 @@ public enum class AwsBusinessMetric(public override val identifier: String) : Bu
CREDENTIALS_HTTP("z"),
CREDENTIALS_IMDS("0"),
}

override fun toString(): String = identifier
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ import aws.smithy.kotlin.runtime.client.ProtocolRequestInterceptorContext
import aws.smithy.kotlin.runtime.http.interceptors.HttpInterceptor
import aws.smithy.kotlin.runtime.http.request.HttpRequest
import aws.smithy.kotlin.runtime.http.request.toBuilder
import aws.smithy.kotlin.runtime.telemetry.logging.logger
import kotlin.coroutines.coroutineContext

/**
* Appends business metrics to the `User-Agent` header.
*/
public class BusinessMetricsInterceptor : HttpInterceptor {
override suspend fun modifyBeforeTransmit(context: ProtocolRequestInterceptorContext<Any, HttpRequest>): HttpRequest {
val logger = coroutineContext.logger<BusinessMetricsInterceptor>()

context.executionContext.getOrNull(BusinessMetrics)?.let { metrics ->
val metricsString = formatMetrics(metrics)
val metricsString = formatMetrics(metrics, logger)
val currentUserAgentHeader = context.protocolRequest.headers[USER_AGENT]
val modifiedRequest = context.protocolRequest.toBuilder()

Expand Down
9 changes: 5 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
[versions]
kotlin-version = "2.0.21"
ksp-version = "2.0.21-1.0.25" # Keep in sync with kotlin-version
kotlin-version = "2.1.0"
ksp-version = "2.1.0-1.0.29" # Keep in sync with kotlin-version

dokka-version = "1.9.10"

aws-kotlin-repo-tools-version = "0.4.14"
aws-kotlin-repo-tools-version = "0.4.17"

# libs
coroutines-version = "1.9.0"
atomicfu-version = "0.25.0"
binary-compatibility-validator-version = "0.16.3"

# smithy-kotlin codegen and runtime are versioned separately
smithy-kotlin-runtime-version = "1.3.30"
Expand Down Expand Up @@ -140,7 +141,7 @@ dokka = { id = "org.jetbrains.dokka", version.ref = "dokka-version"}
kotlin-jvm = {id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin-version" }
kotlin-multiplatform = {id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin-version" }
kotlinx-benchmark = { id = "org.jetbrains.kotlinx.benchmark", version.ref = "kotlinx-benchmark-version" }
kotlinx-binary-compatibility-validator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version = "0.13.2" }
kotlinx-binary-compatibility-validator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version.ref = "binary-compatibility-validator-version" }
kotlinx-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin-version"}
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp-version" }
aws-kotlin-repo-tools-kmp = { id = "aws.sdk.kotlin.gradle.kmp", version.ref = "aws-kotlin-repo-tools-version" }
Expand Down
Loading