Skip to content

Commit f1a6daf

Browse files
committed
add check before invocation
1 parent 2039dd3 commit f1a6daf

4 files changed

Lines changed: 8 additions & 10 deletions

File tree

core/sdk-core/src/main/java/software/amazon/awssdk/core/internal/http/pipeline/stages/AsyncApiCallAttemptMetricCollectionStage.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ private void reportWriteThroughput(RequestExecutionContext context) {
123123
long firstByteTime = metrics.firstByteWrittenNanoTime().get();
124124
if (bytesWritten > 0 && firstByteTime > 0) {
125125
long lastByteTime = metrics.lastByteWrittenNanoTime().get();
126+
// Skip reporting if duration is zero
127+
if (firstByteTime == lastByteTime) {
128+
return;
129+
}
126130
double writeThroughput = MetricUtils.bytesPerSec(bytesWritten, firstByteTime, lastByteTime);
127131
context.attemptMetricCollector().reportMetric(CoreMetric.WRITE_THROUGHPUT, writeThroughput);
128132
}

core/sdk-core/src/main/java/software/amazon/awssdk/core/internal/http/pipeline/stages/HandleResponseStage.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ private void reportWriteThroughput(RequestExecutionContext context, MetricCollec
8585
long firstByteTime = metrics.firstByteWrittenNanoTime().get();
8686
if (bytesWritten > 0 && firstByteTime > 0) {
8787
long lastByteTime = metrics.lastByteWrittenNanoTime().get();
88+
// Skip reporting if duration is zero
89+
if (firstByteTime == lastByteTime) {
90+
return;
91+
}
8892
double writeThroughput = MetricUtils.bytesPerSec(bytesWritten, firstByteTime, lastByteTime);
8993
attemptMetricCollector.reportMetric(CoreMetric.WRITE_THROUGHPUT, writeThroughput);
9094
}

core/sdk-core/src/main/java/software/amazon/awssdk/core/internal/util/MetricUtils.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,6 @@ public static OptionalLong responseHeadersReadEndNanoTime(RequestExecutionContex
182182

183183
public static double bytesPerSec(long totalBytes, long nanoStart, long nanoEnd) {
184184
long duration = nanoEnd - nanoStart;
185-
if (duration <= 0) {
186-
return 0.0;
187-
}
188185
double bytesPerNs = (double) totalBytes / duration;
189186
return bytesPerNs * ONE_SEC_IN_NS;
190187
}

core/sdk-core/src/test/java/software/amazon/awssdk/core/internal/util/MetricUtilsTest.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,6 @@ public void reportDuration_completableFuture_doesNotWrapException() {
170170
}
171171
}
172172

173-
@Test
174-
public void bytesPerSec_zeroDuration_returnsZero() {
175-
long sameTime = System.nanoTime();
176-
double result = MetricUtils.bytesPerSec(50, sameTime, sameTime);
177-
assertThat(result).isEqualTo(0.0);
178-
}
179-
180173
@Test
181174
public void collectHttpMetrics_collectsAllExpectedMetrics() {
182175
MetricCollector mockCollector = mock(MetricCollector.class);

0 commit comments

Comments
 (0)