Skip to content

Commit 3343d58

Browse files
authored
Implementing Protocol Rpc V2 Cbor FeatureID (#6483)
* Implementing ProtocolRpcV2Cbor FeatureID * Add Changelog * Updating test * Add codegen tests * Address PR feedback * Address PR feedback * Additional changes * Adding test for rpc v2 cbor async client * PR feedback
1 parent 6144c8a commit 3343d58

File tree

10 files changed

+916
-4
lines changed

10 files changed

+916
-4
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "feature",
3+
"category": "AWS SDK for Java v2",
4+
"contributor": "",
5+
"description": "Add business metrics support for RPC v2 CBOR protocol to track smithy rpcv2 cbor protocol usage."
6+
}

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-rpcv2-async-client-class.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1170,4 +1170,4 @@ private HttpResponseHandler<AwsServiceException> createErrorResponseHandler(Base
11701170
public void close() {
11711171
clientHandler.close();
11721172
}
1173-
}
1173+
}

core/aws-core/src/main/java/software/amazon/awssdk/awscore/internal/AwsExecutionContextBuilder.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package software.amazon.awssdk.awscore.internal;
1717

1818
import static software.amazon.awssdk.auth.signer.internal.util.SignerMethodResolver.resolveSigningMethodUsed;
19+
import static software.amazon.awssdk.awscore.internal.AwsServiceProtocol.SMITHY_RPC_V2_CBOR;
1920
import static software.amazon.awssdk.core.client.config.SdkClientOption.RETRY_POLICY;
2021
import static software.amazon.awssdk.core.client.config.SdkClientOption.RETRY_STRATEGY;
2122
import static software.amazon.awssdk.core.interceptor.SdkExecutionAttribute.RESOLVED_CHECKSUM_SPECS;
@@ -35,6 +36,7 @@
3536
import software.amazon.awssdk.awscore.util.SignerOverrideUtils;
3637
import software.amazon.awssdk.core.HttpChecksumConstant;
3738
import software.amazon.awssdk.core.RequestOverrideConfiguration;
39+
import software.amazon.awssdk.core.SdkProtocolMetadata;
3840
import software.amazon.awssdk.core.SdkRequest;
3941
import software.amazon.awssdk.core.SdkResponse;
4042
import software.amazon.awssdk.core.SelectedAuthScheme;
@@ -56,6 +58,7 @@
5658
import software.amazon.awssdk.core.sync.ResponseTransformer;
5759
import software.amazon.awssdk.core.useragent.AdditionalMetadata;
5860
import software.amazon.awssdk.core.useragent.BusinessMetricCollection;
61+
import software.amazon.awssdk.core.useragent.BusinessMetricFeatureId;
5962
import software.amazon.awssdk.endpoints.EndpointProvider;
6063
import software.amazon.awssdk.http.ContentStreamProvider;
6164
import software.amazon.awssdk.http.auth.scheme.NoAuthAuthScheme;
@@ -133,7 +136,8 @@ private AwsExecutionContextBuilder() {
133136
clientConfig.option(SdkClientOption.REQUEST_CHECKSUM_CALCULATION))
134137
.putAttribute(SdkInternalExecutionAttribute.RESPONSE_CHECKSUM_VALIDATION,
135138
clientConfig.option(SdkClientOption.RESPONSE_CHECKSUM_VALIDATION))
136-
.putAttribute(SdkInternalExecutionAttribute.BUSINESS_METRICS, resolveUserAgentBusinessMetrics(clientConfig))
139+
.putAttribute(SdkInternalExecutionAttribute.BUSINESS_METRICS,
140+
resolveUserAgentBusinessMetrics(clientConfig, executionParams))
137141
.putAttribute(AwsExecutionAttribute.AWS_SIGV4A_SIGNING_REGION_SET,
138142
clientConfig.option(AwsClientOption.AWS_SIGV4A_SIGNING_REGION_SET));
139143

@@ -350,11 +354,23 @@ private static EndpointProvider resolveEndpointProvider(SdkRequest request,
350354
.orElse(clientConfig.option(SdkClientOption.ENDPOINT_PROVIDER));
351355
}
352356

353-
private static BusinessMetricCollection resolveUserAgentBusinessMetrics(SdkClientConfiguration clientConfig) {
357+
private static <InputT extends SdkRequest, OutputT extends SdkResponse> BusinessMetricCollection
358+
resolveUserAgentBusinessMetrics(SdkClientConfiguration clientConfig,
359+
ClientExecutionParams<InputT, OutputT> executionParams) {
354360
BusinessMetricCollection businessMetrics = new BusinessMetricCollection();
355361
Optional<String> retryModeMetric = resolveRetryMode(clientConfig.option(RETRY_POLICY),
356362
clientConfig.option(RETRY_STRATEGY));
357363
retryModeMetric.ifPresent(businessMetrics::addMetric);
364+
365+
if (isRpcV2CborProtocol(executionParams.getProtocolMetadata())) {
366+
businessMetrics.addMetric(BusinessMetricFeatureId.PROTOCOL_RPC_V2_CBOR.value());
367+
}
368+
358369
return businessMetrics;
359370
}
371+
372+
private static boolean isRpcV2CborProtocol(SdkProtocolMetadata protocolMetadata) {
373+
return protocolMetadata != null &&
374+
SMITHY_RPC_V2_CBOR.toString().equals(protocolMetadata.serviceProtocol());
375+
}
360376
}

core/sdk-core/src/main/java/software/amazon/awssdk/core/useragent/BusinessMetricFeatureId.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
/**
2323
* An enum class representing a short form of identity providers to record in the UA string.
2424
*
25-
* Unimplemented metrics: I,J,K,M,O,S,U-c
25+
* Unimplemented metrics: I,J,K,O,S,U-c
2626
* Unsupported metrics (these will never be added): A,H
2727
*/
2828
@SdkProtectedApi
@@ -35,6 +35,7 @@ public enum BusinessMetricFeatureId {
3535
RETRY_MODE_ADAPTIVE("F"),
3636
S3_TRANSFER("G"),
3737
GZIP_REQUEST_COMPRESSION("L"), //TODO(metrics): Not working, compression happens after header
38+
PROTOCOL_RPC_V2_CBOR("M"),
3839
ENDPOINT_OVERRIDE("N"),
3940
ACCOUNT_ID_MODE_PREFERRED("P"),
4041
ACCOUNT_ID_MODE_DISABLED("Q"),

test/codegen-generated-classes-test/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@
145145
<artifactId>retries-spi</artifactId>
146146
<version>${awsjavasdk.version}</version>
147147
</dependency>
148+
<dependency>
149+
<groupId>software.amazon.awssdk</groupId>
150+
<artifactId>smithy-rpcv2-protocol</artifactId>
151+
<version>${awsjavasdk.version}</version>
152+
</dependency>
148153
<dependency>
149154
<artifactId>netty-nio-client</artifactId>
150155
<groupId>software.amazon.awssdk</groupId>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"enableGenerateCompiledEndpointRules": true,
3+
"skipEndpointTestGeneration": true
4+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"version": "1.3",
3+
"parameters": {
4+
"Region": {
5+
"builtIn": "AWS::Region",
6+
"required": true,
7+
"documentation": "The AWS region used to dispatch the request.",
8+
"type": "String"
9+
}
10+
},
11+
"rules": [
12+
{
13+
"conditions": [],
14+
"endpoint": {
15+
"url": "http://localhost/",
16+
"properties": {
17+
"authSchemes": [
18+
{
19+
"name": "sigv4",
20+
"signingRegion": "{Region}",
21+
"signingName": "jsonrpc"
22+
}
23+
]
24+
},
25+
"headers": {}
26+
},
27+
"type": "endpoint"
28+
}
29+
]
30+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"testCases": [
3+
],
4+
"version": "1.0"
5+
}

0 commit comments

Comments
 (0)