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: credentials business metrics #1164

Open
wants to merge 17 commits into
base: credentials-chain-order
Choose a base branch
from

Conversation

0marperez
Copy link
Contributor

@0marperez 0marperez commented Oct 16, 2024

Issue #

Description of changes

-Emits an Identity's attributes BusinessMetrics into an ExecutionContext during SDK call
-Business metrics utils

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@0marperez 0marperez added the no-changelog Indicates that a changelog entry isn't required for a pull request. Use sparingly. label Oct 16, 2024
@0marperez 0marperez marked this pull request as ready for review October 16, 2024 17:09
@0marperez 0marperez requested a review from a team as a code owner October 16, 2024 17:09
Comment on lines 425 to 432
if (identityAttributes.contains(BusinessMetrics)) {
identityAttributes[BusinessMetrics]
.toList()
.reversed()
.forEach { metric ->
context.emitBusinessMetric(metric)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Why is reversing the order significant? Could this just be:

identity.attributes.getOrNull(BusinessMetrics)?.forEach(context::emitBusinessMetric)

Copy link
Contributor Author

@0marperez 0marperez Oct 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new approach of tracking credentials BM in credentials attributes reverses the order in which credentials BM are recorded. The profile credentials provider starts from the latest node, you can see it's reversed before credentials start being resolved.

Comment on lines 84 to 93
public final class aws/smithy/kotlin/runtime/businessmetrics/BusinessMetricsUtilsKt {
public static final fun containsBusinessMetric (Laws/smithy/kotlin/runtime/operation/ExecutionContext;Laws/smithy/kotlin/runtime/businessmetrics/BusinessMetric;)Z
public static final fun emitBusinessMetric (Laws/smithy/kotlin/runtime/operation/ExecutionContext;Laws/smithy/kotlin/runtime/businessmetrics/BusinessMetric;)V
public static final fun containsBusinessMetric (Laws/smithy/kotlin/runtime/collections/Attributes;Laws/smithy/kotlin/runtime/businessmetrics/BusinessMetric;)Z
public static final fun emitBusinessMetric (Laws/smithy/kotlin/runtime/collections/MutableAttributes;Laws/smithy/kotlin/runtime/businessmetrics/BusinessMetric;)V
public static final fun emitBusinessMetric (Laws/smithy/kotlin/runtime/collections/MutableAttributes;Ljava/lang/String;)V
public static final fun emitBusinessMetrics (Laws/smithy/kotlin/runtime/collections/MutableAttributes;Ljava/util/Set;)V
public static final fun getAccountIdBasedEndpointAccountId ()Laws/smithy/kotlin/runtime/collections/AttributeKey;
public static final fun getBusinessMetrics ()Laws/smithy/kotlin/runtime/collections/AttributeKey;
public static final fun getServiceEndpointOverride ()Laws/smithy/kotlin/runtime/collections/AttributeKey;
public static final fun removeBusinessMetric (Laws/smithy/kotlin/runtime/operation/ExecutionContext;Laws/smithy/kotlin/runtime/businessmetrics/BusinessMetric;)V
public static final fun removeBusinessMetric (Laws/smithy/kotlin/runtime/collections/MutableAttributes;Laws/smithy/kotlin/runtime/businessmetrics/BusinessMetric;)V
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correctness: These are backwards-incompatible changes. We should not change the signatures of existing methods. If we need new capabilities (I'm not yet convinced we do in this case) we should add new methods/overloads.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct here, I'll fix the breaking changes.

Comment on lines 32 to 39
@InternalApi
public fun ExecutionContext.emitBusinessMetric(metric: BusinessMetric) {
if (this.attributes.contains(BusinessMetrics)) {
this.attributes[BusinessMetrics].add(metric.identifier)
public fun MutableAttributes.emitBusinessMetric(identifier: String) {
if (this.contains(BusinessMetrics)) {
this[BusinessMetrics].add(identifier)
} else {
this.attributes[BusinessMetrics] = mutableSetOf(metric.identifier)
this[BusinessMetrics] = mutableSetOf(identifier)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Why would we want to track metrics as pure strings? We already have well-named constants for BusinessMetric instances. It seems like this could only increase the likelihood of emitting an invalid metric identifier.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to save the state of credentials business metrics here. Once the metrics are in the business metrics attribute the constants information is gone and all that is left is the identifier.

In hindsight it would've been useful to have the business metrics attribute be a set of business metrics not of set of string and convert them to strings (using their identifiers) before adding them to the UA header.

@0marperez
Copy link
Contributor Author

Reminder for myself: DO NOT MERGE this into main until you get changes tracking the business metrics attribute from Set<String> -> Set<BusinessMetric> into aws-sdk-kotlin main❗️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-changelog Indicates that a changelog entry isn't required for a pull request. Use sparingly.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants