Skip to content

Commit 287e050

Browse files
committed
Downstream attributes utils
1 parent eb4999d commit 287e050

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

runtime/runtime-core/api/runtime-core.api

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public final class aws/smithy/kotlin/runtime/businessmetrics/BusinessMetricsUtil
8989
public static final fun getAccountIdBasedEndpointAccountId ()Laws/smithy/kotlin/runtime/collections/AttributeKey;
9090
public static final fun getBusinessMetrics ()Laws/smithy/kotlin/runtime/collections/AttributeKey;
9191
public static final fun getServiceEndpointOverride ()Laws/smithy/kotlin/runtime/collections/AttributeKey;
92+
public static final fun mergeBusinessMetrics (Laws/smithy/kotlin/runtime/collections/MutableAttributes;Laws/smithy/kotlin/runtime/collections/Attributes;)V
9293
public static final fun removeBusinessMetric (Laws/smithy/kotlin/runtime/operation/ExecutionContext;Laws/smithy/kotlin/runtime/businessmetrics/BusinessMetric;)V
9394
}
9495

@@ -139,6 +140,7 @@ public final class aws/smithy/kotlin/runtime/collections/AttributesKt {
139140
public static final fun get (Laws/smithy/kotlin/runtime/collections/Attributes;Laws/smithy/kotlin/runtime/collections/AttributeKey;)Ljava/lang/Object;
140141
public static final fun isNotEmpty (Laws/smithy/kotlin/runtime/collections/Attributes;)Z
141142
public static final fun merge (Laws/smithy/kotlin/runtime/collections/MutableAttributes;Laws/smithy/kotlin/runtime/collections/Attributes;)V
143+
public static final fun mergeExcept (Laws/smithy/kotlin/runtime/collections/MutableAttributes;Laws/smithy/kotlin/runtime/collections/Attributes;Ljava/util/Set;)V
142144
public static final fun mutableAttributes ()Laws/smithy/kotlin/runtime/collections/MutableAttributes;
143145
public static final fun mutableAttributesOf (Lkotlin/jvm/functions/Function1;)Laws/smithy/kotlin/runtime/collections/MutableAttributes;
144146
public static final fun putIfAbsent (Laws/smithy/kotlin/runtime/collections/MutableAttributes;Laws/smithy/kotlin/runtime/collections/AttributeKey;Ljava/lang/Object;)V

runtime/runtime-core/common/src/aws/smithy/kotlin/runtime/businessmetrics/BusinessMetricsUtils.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,10 @@ public fun Attributes.copyBusinessMetrics(): MutableSet<String> {
9898
}
9999
return copy
100100
}
101+
102+
/**
103+
* Merges another [Attributes] business metrics into this instance of [MutableAttributes].
104+
*/
105+
public fun MutableAttributes.mergeBusinessMetrics(other: Attributes) {
106+
this[BusinessMetrics] = this[BusinessMetrics].union(other[BusinessMetrics]).toMutableSet()
107+
}

runtime/runtime-core/common/src/aws/smithy/kotlin/runtime/collections/Attributes.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,18 @@ public fun MutableAttributes.merge(other: Attributes) {
115115
}
116116
}
117117

118+
/**
119+
* Merge another attributes instance into this set of attributes favoring [other] except for any keys that are
120+
* specified in the [exceptions] set
121+
*/
122+
public fun MutableAttributes.mergeExcept(other: Attributes, exceptions: Set<AttributeKey<*>>) {
123+
other.keys.forEach {
124+
if (it in exceptions) return@forEach
125+
@Suppress("UNCHECKED_CAST")
126+
set(it as AttributeKey<Any>, other[it])
127+
}
128+
}
129+
118130
private class AttributesImpl constructor(seed: Attributes) : MutableAttributes {
119131
private val map: MutableMap<AttributeKey<*>, Any> = mutableMapOf()
120132
constructor() : this(emptyAttributes())

0 commit comments

Comments
 (0)