Skip to content

Commit 5449093

Browse files
authored
misc: track business metrics change from set of string to set of business metrics (#1458)
1 parent 41e0f90 commit 5449093

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

aws-runtime/aws-http/common/src/aws/sdk/kotlin/runtime/http/interceptors/BusinessMetricsInterceptor.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ public class BusinessMetricsInterceptor : HttpInterceptor {
3535
/**
3636
* Makes sure the metrics do not exceed the maximum size and truncates them if so.
3737
*/
38-
private fun formatMetrics(metrics: MutableSet<String>): String {
38+
private fun formatMetrics(metrics: MutableSet<BusinessMetric>): String {
3939
if (metrics.isEmpty()) return ""
40-
val metricsString = metrics.joinToString(",", "m/")
40+
val metricsString = metrics.joinToString(",", "m/") { it.identifier }
4141
val metricsByteArray = metricsString.encodeToByteArray()
4242

4343
if (metricsByteArray.size <= BUSINESS_METRICS_MAX_LENGTH) return metricsString

aws-runtime/aws-http/common/test/aws/sdk/kotlin/runtime/http/interceptors/BusinessMetricsInterceptorTest.kt

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

77
import aws.sdk.kotlin.runtime.http.BUSINESS_METRICS_MAX_LENGTH
88
import aws.sdk.kotlin.runtime.http.middleware.USER_AGENT
9+
import aws.smithy.kotlin.runtime.businessmetrics.BusinessMetric
910
import aws.smithy.kotlin.runtime.businessmetrics.SmithyBusinessMetric
1011
import aws.smithy.kotlin.runtime.businessmetrics.emitBusinessMetric
1112
import aws.smithy.kotlin.runtime.client.ProtocolRequestInterceptorContext
@@ -70,7 +71,11 @@ class BusinessMetricsInterceptorTest {
7071
executionContext.attributes[aws.smithy.kotlin.runtime.businessmetrics.BusinessMetrics] = mutableSetOf()
7172

7273
for (i in 0..1024) {
73-
executionContext.attributes[aws.smithy.kotlin.runtime.businessmetrics.BusinessMetrics].add(i.toString())
74+
executionContext.emitBusinessMetric(
75+
object : BusinessMetric {
76+
override val identifier: String = i.toString()
77+
},
78+
)
7479
}
7580

7681
val rawMetrics = executionContext[aws.smithy.kotlin.runtime.businessmetrics.BusinessMetrics]
@@ -91,9 +96,12 @@ class BusinessMetricsInterceptorTest {
9196
@Test
9297
fun malformedBusinessMetrics() = runTest {
9398
val executionContext = ExecutionContext()
99+
val reallyLongMetric = "All work and no play makes Jack a dull boy".repeat(1000)
94100

95-
executionContext.attributes[aws.smithy.kotlin.runtime.businessmetrics.BusinessMetrics] = mutableSetOf(
96-
"A".repeat(BUSINESS_METRICS_MAX_LENGTH),
101+
executionContext.attributes.emitBusinessMetric(
102+
object : BusinessMetric {
103+
override val identifier: String = reallyLongMetric
104+
},
97105
)
98106

99107
val interceptor = BusinessMetricsInterceptor()

gradle/libs.versions.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ coroutines-version = "1.9.0"
1111
atomicfu-version = "0.25.0"
1212

1313
# smithy-kotlin codegen and runtime are versioned separately
14-
smithy-kotlin-runtime-version = "1.3.18"
15-
smithy-kotlin-codegen-version = "0.33.18"
14+
smithy-kotlin-runtime-version = "1.3.19"
15+
smithy-kotlin-codegen-version = "0.33.19"
1616

1717
# codegen
1818
smithy-version = "1.51.0"

hll/dynamodb-mapper/dynamodb-mapper/jvm/test/aws/sdk/kotlin/hll/dynamodbmapper/DynamoDbMapperTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class DynamoDbMapperTest : DdbLocalTest() {
7979
}
8080

8181
private class MetricCapturingInterceptor : HttpInterceptor {
82-
private val capturedMetrics = mutableSetOf<String>()
82+
private val capturedMetrics = mutableSetOf<BusinessMetric>()
8383

8484
override fun readBeforeTransmit(context: ProtocolRequestInterceptorContext<Any, HttpRequest>) {
8585
capturedMetrics += context.executionContext[BusinessMetrics]
@@ -88,12 +88,12 @@ private class MetricCapturingInterceptor : HttpInterceptor {
8888
fun assertMetric(metric: BusinessMetric, exists: Boolean = true) {
8989
if (exists) {
9090
assertTrue(
91-
metric.identifier in capturedMetrics,
91+
metric in capturedMetrics,
9292
"Expected metrics to contain $metric. Actual values: $capturedMetrics",
9393
)
9494
} else {
9595
assertFalse(
96-
metric.identifier in capturedMetrics,
96+
metric in capturedMetrics,
9797
"Expected metrics *not* to contain $metric. Actual values: $capturedMetrics",
9898
)
9999
}

0 commit comments

Comments
 (0)