Skip to content
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/next-release/bugfix-AWSSDKforJavav2-fa66812.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "bugfix",
"category": "AWS SDK for Java v2",
"contributor": "",
"description": "Set the RESOLVED_ACCOUNT_ID (T) user-agent metric only when accountID is actually resolved from credentials."
}
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,11 @@ public MethodSpec resolveAndRecordAccountIdFromIdentityMethod() {
builder.addStatement("$T accountId = accountIdFromIdentity(executionAttributes.getAttribute($T.SELECTED_AUTH_SCHEME))",
String.class, SdkInternalExecutionAttribute.class);

builder.addStatement("executionAttributes.getAttribute($T.BUSINESS_METRICS).addMetric($T.RESOLVED_ACCOUNT_ID.value())",
SdkInternalExecutionAttribute.class, BusinessMetricFeatureId.class);
builder
.beginControlFlow("if (accountId != null)")
.addStatement("executionAttributes.getAttribute($T.BUSINESS_METRICS).addMetric($T.RESOLVED_ACCOUNT_ID.value())",
SdkInternalExecutionAttribute.class, BusinessMetricFeatureId.class)
.endControlFlow();

builder.addStatement("return accountId");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,10 @@ private Supplier<Signer> signerProvider(EndpointAuthScheme authScheme) {
private static String resolveAndRecordAccountIdFromIdentity(ExecutionAttributes executionAttributes) {
String accountId = accountIdFromIdentity(executionAttributes
.getAttribute(SdkInternalExecutionAttribute.SELECTED_AUTH_SCHEME));
executionAttributes.getAttribute(SdkInternalExecutionAttribute.BUSINESS_METRICS).addMetric(
BusinessMetricFeatureId.RESOLVED_ACCOUNT_ID.value());
if (accountId != null) {
executionAttributes.getAttribute(SdkInternalExecutionAttribute.BUSINESS_METRICS).addMetric(
BusinessMetricFeatureId.RESOLVED_ACCOUNT_ID.value());
}
return accountId;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,10 @@ private static Optional<String> hostPrefix(String operationName, SdkRequest requ
private static String resolveAndRecordAccountIdFromIdentity(ExecutionAttributes executionAttributes) {
String accountId = accountIdFromIdentity(executionAttributes
.getAttribute(SdkInternalExecutionAttribute.SELECTED_AUTH_SCHEME));
executionAttributes.getAttribute(SdkInternalExecutionAttribute.BUSINESS_METRICS).addMetric(
BusinessMetricFeatureId.RESOLVED_ACCOUNT_ID.value());
if (accountId != null) {
executionAttributes.getAttribute(SdkInternalExecutionAttribute.BUSINESS_METRICS).addMetric(
BusinessMetricFeatureId.RESOLVED_ACCOUNT_ID.value());
}
return accountId;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,10 @@ private static Optional<String> hostPrefix(String operationName, SdkRequest requ
private static String resolveAndRecordAccountIdFromIdentity(ExecutionAttributes executionAttributes) {
String accountId = accountIdFromIdentity(executionAttributes
.getAttribute(SdkInternalExecutionAttribute.SELECTED_AUTH_SCHEME));
executionAttributes.getAttribute(SdkInternalExecutionAttribute.BUSINESS_METRICS).addMetric(
BusinessMetricFeatureId.RESOLVED_ACCOUNT_ID.value());
if (accountId != null) {
executionAttributes.getAttribute(SdkInternalExecutionAttribute.BUSINESS_METRICS).addMetric(
BusinessMetricFeatureId.RESOLVED_ACCOUNT_ID.value());
}
return accountId;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.net.URI;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -63,6 +64,12 @@ class BusinessMetricsUserAgentTest {
private static final String USER_AGENT_HEADER_NAME = "User-Agent";
private static final StaticCredentialsProvider CREDENTIALS_PROVIDER =
StaticCredentialsProvider.create(AwsBasicCredentials.create("akid", "skid"));
private static final StaticCredentialsProvider CREDENTIALS_PROVIDER_WITH_ACCOUNTID =
StaticCredentialsProvider.create(
AwsBasicCredentials.builder()
.accessKeyId("akid").secretAccessKey("skid")
.accountId("012345678901")
.build());

@BeforeEach
public void setup() {
Expand All @@ -76,10 +83,10 @@ public void cleanup() {

private static Stream<Arguments> inputValues() {
return Stream.of(
Arguments.of("Default values", null, Arrays.asList("D", "N", "P", "T")),
Arguments.of("Account ID preferred mode ", AccountIdEndpointMode.PREFERRED, Arrays.asList("P", "T")),
Arguments.of("Account ID disabled mode ", AccountIdEndpointMode.DISABLED, Arrays.asList("Q", "T")),
Arguments.of("Account ID required mode ", AccountIdEndpointMode.REQUIRED, Arrays.asList("R", "T"))
Arguments.of("Default values", null, Arrays.asList("D", "N", "P")),
Arguments.of("Account ID preferred mode ", AccountIdEndpointMode.PREFERRED, Collections.singletonList("P")),
Arguments.of("Account ID disabled mode ", AccountIdEndpointMode.DISABLED, Collections.singletonList("Q")),
Arguments.of("Account ID required mode ", AccountIdEndpointMode.REQUIRED, Collections.singletonList("R"))
);
}

Expand All @@ -101,6 +108,28 @@ void validate_metricsString_forDifferentConfigValues(String description,
expectedMetrics.forEach(expectedMetric -> assertThat(userAgent).matches(METRIC_SEARCH_PATTERN.apply(expectedMetric)));
}

@Test
void when_accountIdNotResolved_noMetricIsAdded() {
RestJsonEndpointProvidersAsyncClientBuilder clientBuilder = asyncClientBuilderForEndpointProvider();
clientBuilder.credentialsProvider(CREDENTIALS_PROVIDER);

assertThatThrownBy(() -> clientBuilder.build().operationWithNoInputOrOutput(r -> {}).join()).hasMessageContaining("stop");

String userAgent = assertAndGetUserAgentString();
assertThat(userAgent).doesNotMatch(METRIC_SEARCH_PATTERN.apply("T"));
}

@Test
void when_accountIdResolved_correctMetricIsAdded() {
RestJsonEndpointProvidersAsyncClientBuilder clientBuilder = asyncClientBuilderForEndpointProvider();
clientBuilder.credentialsProvider(CREDENTIALS_PROVIDER_WITH_ACCOUNTID);

assertThatThrownBy(() -> clientBuilder.build().operationWithNoInputOrOutput(r -> {}).join()).hasMessageContaining("stop");

String userAgent = assertAndGetUserAgentString();
assertThat(userAgent).matches(METRIC_SEARCH_PATTERN.apply("T"));
}

@Test
void when_waiterIsUsed_correctMetricIsAdded() throws ExecutionException, InterruptedException {
RestJsonWithWaitersAsyncClient asyncClient =
Expand Down
Loading