Skip to content

Implement Service Endpoint Metric #3470

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

Closed
wants to merge 3 commits into from
Closed
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/feature-AWSSDKforJavav2-31b5a0c.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"category": "AWS SDK for Java v2",
"contributor": "",
"type": "feature",
"description": "Implement SERVICE_ENDPOINT core metric"
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package software.amazon.awssdk.core.internal.handler;

import java.net.URI;
import java.net.URISyntaxException;
import java.time.Duration;
import java.util.Optional;
import java.util.function.BiFunction;
Expand Down Expand Up @@ -78,6 +79,13 @@ static <InputT extends SdkRequest, OutputT> InterceptorContext finalizeSdkHttpFu

request = modifyEndpointHostIfNeeded(request, clientConfiguration, executionParams);

try {
URI endpoint = new URI(request.protocol(), request.host(), null, null);
executionContext.metricCollector().reportMetric(CoreMetric.SERVICE_ENDPOINT, endpoint);
} catch (URISyntaxException e) {
throw new IllegalArgumentException(e);
}
Comment on lines +82 to +87
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Catching and rethrowing exception to not change method signature.
URI.create does not throw exception, but requires parsing a string.


addHttpRequest(executionContext, request);
runAfterMarshallingInterceptors(executionContext);
return runModifyHttpRequestAndHttpContentInterceptors(executionContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

package software.amazon.awssdk.core.metrics;

import java.net.URI;
import java.time.Duration;
import software.amazon.awssdk.annotations.SdkPublicApi;
import software.amazon.awssdk.core.retry.RetryPolicy;
Expand Down Expand Up @@ -50,6 +51,12 @@ public final class CoreMetric {
public static final SdkMetric<Integer> RETRY_COUNT =
metric("RetryCount", Integer.class, MetricLevel.ERROR);

/**
* The endpoint for the service.
*/
public static final SdkMetric<URI> SERVICE_ENDPOINT =
metric("ServiceEndpoint", URI.class, MetricLevel.ERROR);

/**
* The duration of the API call. This includes all call attempts made.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.URI;
import java.time.Duration;
import java.util.List;
import java.util.stream.Collectors;
Expand All @@ -48,6 +49,7 @@
import software.amazon.awssdk.http.SdkHttpFullResponse;
import software.amazon.awssdk.metrics.MetricCollection;
import software.amazon.awssdk.metrics.MetricPublisher;
import software.amazon.awssdk.metrics.SdkMetric;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonClient;
import software.amazon.awssdk.services.protocolrestjson.model.EmptyModeledException;
Expand Down Expand Up @@ -181,6 +183,8 @@ public void testApiCall_operationSuccessful_addsMetrics() {
assertThat(capturedCollection.metricValues(CoreMetric.MARSHALLING_DURATION).get(0))
.isGreaterThanOrEqualTo(Duration.ZERO);
assertThat(capturedCollection.metricValues(CoreMetric.RETRY_COUNT)).containsExactly(0);
assertThat(capturedCollection.metricValues(CoreMetric.SERVICE_ENDPOINT).get(0)).isEqualTo(URI.create(
"https://customresponsemetadata.us-west-2.amazonaws.com"));

assertThat(capturedCollection.children()).hasSize(1);
MetricCollection attemptCollection = capturedCollection.children().get(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import com.github.tomakehurst.wiremock.http.Fault;
import com.github.tomakehurst.wiremock.stubbing.Scenario;
import java.net.URI;
import java.time.Duration;
import java.util.concurrent.CompletableFuture;
import java.util.function.Supplier;
Expand Down Expand Up @@ -201,6 +202,8 @@ private void verifyApiCallCollection(MetricCollection capturedCollection) {
.isGreaterThanOrEqualTo(Duration.ZERO);
assertThat(capturedCollection.metricValues(CoreMetric.API_CALL_DURATION).get(0))
.isGreaterThan(FIXED_DELAY);
assertThat(capturedCollection.metricValues(CoreMetric.SERVICE_ENDPOINT).get(0))
.isEqualTo(URI.create("http://localhost"));
}

void stubSuccessfulResponse() {
Expand Down