use of software.amazon.awssdk.metrics.MetricCollector in project aws-sdk-java-v2 by aws.
the class MakeHttpRequestStage method executeHttpRequest.
private HttpExecuteResponse executeHttpRequest(SdkHttpFullRequest request, RequestExecutionContext context) throws Exception {
MetricCollector attemptMetricCollector = context.attemptMetricCollector();
MetricCollector httpMetricCollector = MetricUtils.createHttpMetricsCollector(context);
ExecutableHttpRequest requestCallable = sdkHttpClient.prepareRequest(HttpExecuteRequest.builder().request(request).metricCollector(httpMetricCollector).contentStreamProvider(request.contentStreamProvider().orElse(null)).build());
context.apiCallTimeoutTracker().abortable(requestCallable);
context.apiCallAttemptTimeoutTracker().abortable(requestCallable);
Pair<HttpExecuteResponse, Duration> measuredExecute = MetricUtils.measureDurationUnsafe(requestCallable);
attemptMetricCollector.reportMetric(CoreMetric.SERVICE_CALL_DURATION, measuredExecute.right());
return measuredExecute.left();
}
use of software.amazon.awssdk.metrics.MetricCollector in project aws-sdk-java-v2 by aws.
the class HttpOrHttp2ChannelPoolTest method incompleteProtocolFutureDelaysMetricsDelegationAndForwardsSuccessForProtocol.
public void incompleteProtocolFutureDelaysMetricsDelegationAndForwardsSuccessForProtocol(Protocol protocol) throws Exception {
Promise<Channel> acquirePromise = eventLoopGroup.next().newPromise();
Promise<Void> releasePromise = eventLoopGroup.next().newPromise();
when(mockDelegatePool.acquire()).thenReturn(acquirePromise);
when(mockDelegatePool.release(any(Channel.class))).thenReturn(releasePromise);
// startConnection
httpOrHttp2ChannelPool.acquire();
// query for metrics before the config can complete (we haven't completed acquirePromise yet)
MetricCollector metricCollector = MetricCollector.create("foo");
CompletableFuture<Void> metricsFuture = httpOrHttp2ChannelPool.collectChannelPoolMetrics(metricCollector);
Thread.sleep(500);
assertThat(metricsFuture.isDone()).isFalse();
Channel channel = new MockChannel();
eventLoopGroup.register(channel);
channel.attr(PROTOCOL_FUTURE).set(CompletableFuture.completedFuture(protocol));
acquirePromise.setSuccess(channel);
releasePromise.setSuccess(null);
metricsFuture.join();
MetricCollection metrics = metricCollector.collect();
assertThat(metrics.metricValues(HttpMetric.PENDING_CONCURRENCY_ACQUIRES).get(0)).isEqualTo(0);
assertThat(metrics.metricValues(HttpMetric.MAX_CONCURRENCY).get(0)).isEqualTo(4);
assertThat(metrics.metricValues(HttpMetric.AVAILABLE_CONCURRENCY).get(0)).isBetween(0, 1);
assertThat(metrics.metricValues(HttpMetric.LEASED_CONCURRENCY).get(0)).isBetween(0, 1);
}
use of software.amazon.awssdk.metrics.MetricCollector in project aws-sdk-java-v2 by aws.
the class CloudWatchMetricPublisherTest method defaultDimensionsIsCorrect.
@Test
public void defaultDimensionsIsCorrect() {
try (CloudWatchMetricPublisher publisher = CloudWatchMetricPublisher.builder().cloudWatchClient(cloudWatch).build()) {
MetricCollector collector = newCollector();
collector.reportMetric(CoreMetric.SERVICE_ID, "ServiceId");
collector.reportMetric(CoreMetric.OPERATION_NAME, "OperationName");
collector.reportMetric(HttpMetric.AVAILABLE_CONCURRENCY, 5);
publisher.publish(new FixedTimeMetricCollection(collector.collect()));
}
PutMetricDataRequest call = getPutMetricCall();
assertThat(call.metricData().get(0).dimensions()).containsExactlyInAnyOrder(Dimension.builder().name(CoreMetric.SERVICE_ID.name()).value("ServiceId").build(), Dimension.builder().name(CoreMetric.OPERATION_NAME.name()).value("OperationName").build());
}
use of software.amazon.awssdk.metrics.MetricCollector in project aws-sdk-java-v2 by aws.
the class CloudWatchMetricPublisherTest method dimensionsSettingIsHonored.
@Test
public void dimensionsSettingIsHonored() {
try (CloudWatchMetricPublisher publisher = publisherBuilder.dimensions(CoreMetric.SERVICE_ID).build()) {
MetricCollector collector = newCollector();
collector.reportMetric(CoreMetric.SERVICE_ID, "ServiceId");
collector.reportMetric(CoreMetric.OPERATION_NAME, "OperationName");
collector.reportMetric(HttpMetric.AVAILABLE_CONCURRENCY, 5);
publisher.publish(new FixedTimeMetricCollection(collector.collect()));
}
PutMetricDataRequest call = getPutMetricCall();
assertThat(call.metricData().get(0).dimensions()).containsExactly(Dimension.builder().name(CoreMetric.SERVICE_ID.name()).value("ServiceId").build());
}
use of software.amazon.awssdk.metrics.MetricCollector in project aws-sdk-java-v2 by aws.
the class CloudWatchMetricPublisherTest method namespaceSettingIsHonored.
@Test
public void namespaceSettingIsHonored() {
try (CloudWatchMetricPublisher publisher = publisherBuilder.namespace("namespace").build()) {
MetricCollector collector = newCollector();
collector.reportMetric(HttpMetric.AVAILABLE_CONCURRENCY, 5);
publisher.publish(new FixedTimeMetricCollection(collector.collect()));
}
assertThat(getPutMetricCall().namespace()).isEqualTo("namespace");
}
Aggregations