Skip to content

Commit 6c88840

Browse files
committed
Minor metrics fixes
- move ServiceId and OperationName reporting into try block - ServiceName -> ServiceId - Fix typo in test
1 parent 27fbcfd commit 6c88840

File tree

6 files changed

+38
-40
lines changed

6 files changed

+38
-40
lines changed

codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/SyncClientClass.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,13 @@ private List<MethodSpec> operationMethodSpecs(OperationModel opModel) {
196196
method.addStatement("$1T $2N = $1T.create($3S)",
197197
MetricCollector.class, metricCollectorName, "ApiCall");
198198

199-
method.addStatement("$N.reportMetric($T.$L, $S)", metricCollectorName, CoreMetric.class, "SERVICE_ID",
200-
model.getMetadata().getServiceId());
201-
method.addStatement("$N.reportMetric($T.$L, $S)", metricCollectorName, CoreMetric.class, "OPERATION_NAME",
202-
opModel.getOperationName());
203-
204199
String publisherName = "metricPublisher";
205200

206201
method.beginControlFlow("try")
202+
.addStatement("$N.reportMetric($T.$L, $S)", metricCollectorName, CoreMetric.class, "SERVICE_ID",
203+
model.getMetadata().getServiceId())
204+
.addStatement("$N.reportMetric($T.$L, $S)", metricCollectorName, CoreMetric.class, "OPERATION_NAME",
205+
opModel.getOperationName())
207206
.addCode(protocolSpec.executionHandler(opModel))
208207
.endControlFlow()
209208
.beginControlFlow("finally")

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-endpoint-discovery-sync.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ public DescribeEndpointsResponse describeEndpoints(DescribeEndpointsRequest desc
9494
HttpResponseHandler<AwsServiceException> errorResponseHandler = createErrorResponseHandler(protocolFactory,
9595
operationMetadata);
9696
MetricCollector apiCallMetricCollector = MetricCollector.create("ApiCall");
97-
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "AwsEndpointDiscoveryTest");
98-
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "DescribeEndpoints");
9997
try {
98+
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "AwsEndpointDiscoveryTest");
99+
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "DescribeEndpoints");
100100

101101
return clientHandler.execute(new ClientExecutionParams<DescribeEndpointsRequest, DescribeEndpointsResponse>()
102102
.withOperationName("DescribeEndpoints").withResponseHandler(responseHandler)
@@ -145,9 +145,9 @@ public TestDiscoveryIdentifiersRequiredResponse testDiscoveryIdentifiersRequired
145145
cachedEndpoint = endpointDiscoveryCache.get(key, endpointDiscoveryRequest);
146146
}
147147
MetricCollector apiCallMetricCollector = MetricCollector.create("ApiCall");
148-
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "AwsEndpointDiscoveryTest");
149-
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "TestDiscoveryIdentifiersRequired");
150148
try {
149+
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "AwsEndpointDiscoveryTest");
150+
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "TestDiscoveryIdentifiersRequired");
151151

152152
return clientHandler
153153
.execute(new ClientExecutionParams<TestDiscoveryIdentifiersRequiredRequest, TestDiscoveryIdentifiersRequiredResponse>()
@@ -196,9 +196,9 @@ public TestDiscoveryOptionalResponse testDiscoveryOptional(TestDiscoveryOptional
196196
cachedEndpoint = endpointDiscoveryCache.get(key, endpointDiscoveryRequest);
197197
}
198198
MetricCollector apiCallMetricCollector = MetricCollector.create("ApiCall");
199-
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "AwsEndpointDiscoveryTest");
200-
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "TestDiscoveryOptional");
201199
try {
200+
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "AwsEndpointDiscoveryTest");
201+
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "TestDiscoveryOptional");
202202

203203
return clientHandler.execute(new ClientExecutionParams<TestDiscoveryOptionalRequest, TestDiscoveryOptionalResponse>()
204204
.withOperationName("TestDiscoveryOptional").withResponseHandler(responseHandler)
@@ -246,9 +246,9 @@ public TestDiscoveryRequiredResponse testDiscoveryRequired(TestDiscoveryRequired
246246
cachedEndpoint = endpointDiscoveryCache.get(key, endpointDiscoveryRequest);
247247
}
248248
MetricCollector apiCallMetricCollector = MetricCollector.create("ApiCall");
249-
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "AwsEndpointDiscoveryTest");
250-
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "TestDiscoveryRequired");
251249
try {
250+
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "AwsEndpointDiscoveryTest");
251+
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "TestDiscoveryRequired");
252252

253253
return clientHandler.execute(new ClientExecutionParams<TestDiscoveryRequiredRequest, TestDiscoveryRequiredResponse>()
254254
.withOperationName("TestDiscoveryRequired").withResponseHandler(responseHandler)

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ public APostOperationResponse aPostOperation(APostOperationRequest aPostOperatio
119119
HttpResponseHandler<AwsServiceException> errorResponseHandler = createErrorResponseHandler(protocolFactory,
120120
operationMetadata);
121121
MetricCollector apiCallMetricCollector = MetricCollector.create("ApiCall");
122-
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service");
123-
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "APostOperation");
124122
try {
123+
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service");
124+
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "APostOperation");
125125

126126
return clientHandler.execute(new ClientExecutionParams<APostOperationRequest, APostOperationResponse>()
127127
.withOperationName("APostOperation").withResponseHandler(responseHandler)
@@ -167,9 +167,9 @@ public APostOperationWithOutputResponse aPostOperationWithOutput(
167167
HttpResponseHandler<AwsServiceException> errorResponseHandler = createErrorResponseHandler(protocolFactory,
168168
operationMetadata);
169169
MetricCollector apiCallMetricCollector = MetricCollector.create("ApiCall");
170-
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service");
171-
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "APostOperationWithOutput");
172170
try {
171+
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service");
172+
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "APostOperationWithOutput");
173173

174174
return clientHandler
175175
.execute(new ClientExecutionParams<APostOperationWithOutputRequest, APostOperationWithOutputResponse>()
@@ -217,9 +217,9 @@ public GetWithoutRequiredMembersResponse getWithoutRequiredMembers(
217217
HttpResponseHandler<AwsServiceException> errorResponseHandler = createErrorResponseHandler(protocolFactory,
218218
operationMetadata);
219219
MetricCollector apiCallMetricCollector = MetricCollector.create("ApiCall");
220-
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service");
221-
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "GetWithoutRequiredMembers");
222220
try {
221+
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service");
222+
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "GetWithoutRequiredMembers");
223223

224224
return clientHandler
225225
.execute(new ClientExecutionParams<GetWithoutRequiredMembersRequest, GetWithoutRequiredMembersResponse>()
@@ -263,9 +263,9 @@ public PaginatedOperationWithResultKeyResponse paginatedOperationWithResultKey(
263263
HttpResponseHandler<AwsServiceException> errorResponseHandler = createErrorResponseHandler(protocolFactory,
264264
operationMetadata);
265265
MetricCollector apiCallMetricCollector = MetricCollector.create("ApiCall");
266-
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service");
267-
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "PaginatedOperationWithResultKey");
268266
try {
267+
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service");
268+
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "PaginatedOperationWithResultKey");
269269

270270
return clientHandler
271271
.execute(new ClientExecutionParams<PaginatedOperationWithResultKeyRequest, PaginatedOperationWithResultKeyResponse>()
@@ -387,9 +387,9 @@ public PaginatedOperationWithoutResultKeyResponse paginatedOperationWithoutResul
387387
HttpResponseHandler<AwsServiceException> errorResponseHandler = createErrorResponseHandler(protocolFactory,
388388
operationMetadata);
389389
MetricCollector apiCallMetricCollector = MetricCollector.create("ApiCall");
390-
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service");
391-
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "PaginatedOperationWithoutResultKey");
392390
try {
391+
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service");
392+
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "PaginatedOperationWithoutResultKey");
393393

394394
return clientHandler
395395
.execute(new ClientExecutionParams<PaginatedOperationWithoutResultKeyRequest, PaginatedOperationWithoutResultKeyResponse>()
@@ -522,9 +522,9 @@ public StreamingInputOperationResponse streamingInputOperation(StreamingInputOpe
522522
HttpResponseHandler<AwsServiceException> errorResponseHandler = createErrorResponseHandler(protocolFactory,
523523
operationMetadata);
524524
MetricCollector apiCallMetricCollector = MetricCollector.create("ApiCall");
525-
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service");
526-
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "StreamingInputOperation");
527525
try {
526+
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service");
527+
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "StreamingInputOperation");
528528

529529
return clientHandler
530530
.execute(new ClientExecutionParams<StreamingInputOperationRequest, StreamingInputOperationResponse>()
@@ -595,9 +595,9 @@ public <ReturnT> ReturnT streamingInputOutputOperation(
595595
HttpResponseHandler<AwsServiceException> errorResponseHandler = createErrorResponseHandler(protocolFactory,
596596
operationMetadata);
597597
MetricCollector apiCallMetricCollector = MetricCollector.create("ApiCall");
598-
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service");
599-
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "StreamingInputOutputOperation");
600598
try {
599+
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service");
600+
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "StreamingInputOutputOperation");
601601

602602
return clientHandler.execute(
603603
new ClientExecutionParams<StreamingInputOutputOperationRequest, StreamingInputOutputOperationResponse>()
@@ -656,9 +656,9 @@ public <ReturnT> ReturnT streamingOutputOperation(StreamingOutputOperationReques
656656
HttpResponseHandler<AwsServiceException> errorResponseHandler = createErrorResponseHandler(protocolFactory,
657657
operationMetadata);
658658
MetricCollector apiCallMetricCollector = MetricCollector.create("ApiCall");
659-
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service");
660-
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "StreamingOutputOperation");
661659
try {
660+
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service");
661+
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "StreamingOutputOperation");
662662

663663
return clientHandler.execute(
664664
new ClientExecutionParams<StreamingOutputOperationRequest, StreamingOutputOperationResponse>()

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ public APostOperationResponse aPostOperation(APostOperationRequest aPostOperatio
9090

9191
HttpResponseHandler<AwsServiceException> errorResponseHandler = protocolFactory.createErrorResponseHandler();
9292
MetricCollector apiCallMetricCollector = MetricCollector.create("ApiCall");
93-
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service");
94-
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "APostOperation");
9593
try {
94+
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service");
95+
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "APostOperation");
9696

9797
return clientHandler.execute(new ClientExecutionParams<APostOperationRequest, APostOperationResponse>()
9898
.withOperationName("APostOperation").withResponseHandler(responseHandler)
@@ -135,9 +135,9 @@ public APostOperationWithOutputResponse aPostOperationWithOutput(
135135

136136
HttpResponseHandler<AwsServiceException> errorResponseHandler = protocolFactory.createErrorResponseHandler();
137137
MetricCollector apiCallMetricCollector = MetricCollector.create("ApiCall");
138-
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service");
139-
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "APostOperationWithOutput");
140138
try {
139+
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service");
140+
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "APostOperationWithOutput");
141141

142142
return clientHandler
143143
.execute(new ClientExecutionParams<APostOperationWithOutputRequest, APostOperationWithOutputResponse>()
@@ -188,9 +188,9 @@ public StreamingInputOperationResponse streamingInputOperation(StreamingInputOpe
188188

189189
HttpResponseHandler<AwsServiceException> errorResponseHandler = protocolFactory.createErrorResponseHandler();
190190
MetricCollector apiCallMetricCollector = MetricCollector.create("ApiCall");
191-
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service");
192-
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "StreamingInputOperation");
193191
try {
192+
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service");
193+
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "StreamingInputOperation");
194194

195195
return clientHandler
196196
.execute(new ClientExecutionParams<StreamingInputOperationRequest, StreamingInputOperationResponse>()
@@ -244,9 +244,9 @@ public <ReturnT> ReturnT streamingOutputOperation(StreamingOutputOperationReques
244244

245245
HttpResponseHandler<AwsServiceException> errorResponseHandler = protocolFactory.createErrorResponseHandler();
246246
MetricCollector apiCallMetricCollector = MetricCollector.create("ApiCall");
247-
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service");
248-
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "StreamingOutputOperation");
249247
try {
248+
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service");
249+
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "StreamingOutputOperation");
250250

251251
return clientHandler.execute(
252252
new ClientExecutionParams<StreamingOutputOperationRequest, StreamingOutputOperationResponse>()
@@ -275,4 +275,3 @@ public void close() {
275275
clientHandler.close();
276276
}
277277
}
278-

core/sdk-core/src/main/java/software/amazon/awssdk/core/metrics/CoreMetric.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public final class CoreMetric {
2525
/**
2626
* The unique ID for the service. This is present for all API call metrics.
2727
*/
28-
public static final SdkMetric<String> SERVICE_ID = metric("ServiceName", String.class);
28+
public static final SdkMetric<String> SERVICE_ID = metric("ServiceId", String.class);
2929

3030
/**
3131
* The name of the service operation being invoked. This is present for all

test/codegen-generated-classes-test/src/test/java/software/amazon/awssdk/services/metrics/CoreMetricsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ public void testApiCall_serviceReturnsError_errorInfoIncludedInMetrics() throws
210210
// Note: for some reason we don't throw the same exact
211211
// instance as the one unmarshalled by the response
212212
// handler (seems we make a copy upstream) so an
213-
// isSamAs assertion fails here
213+
// isSameAs assertion fails here
214214
.isInstanceOf(EmptyModeledException.class);
215215

216216
// A service exception is still a successful HTTP execution so

0 commit comments

Comments
 (0)