Skip to content

Commit 44a12ef

Browse files
fix: revise health metrics inflightBytes to become inflightBytesMax (#14613)
1 parent eca60e7 commit 44a12ef

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

‎java-bigquerystorage/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/ConnectionWorker.java‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,9 @@ class HealthCheckMetrics {
326326
@GuardedBy("lock")
327327
private long windowedQueuedRetriesMax;
328328

329+
@GuardedBy("lock")
330+
private long windowedInflightBytesMax;
331+
329332
private long windowedConnectionAttemptCount;
330333
private long windowedConnectionClosedCount;
331334

@@ -338,6 +341,13 @@ void updateWindowedQueuedRequestsMax(long currentQueueLength, long currentRetryC
338341
}
339342
}
340343

344+
@GuardedBy("lock")
345+
void updateInflightBytesMax(long currentInflightBytes) {
346+
if (currentInflightBytes > windowedInflightBytesMax) {
347+
windowedInflightBytesMax = currentInflightBytes;
348+
}
349+
}
350+
341351
void updateResponseWait(Instant sendInstant) {
342352
long currentWaitTime = Duration.between(sendInstant, Instant.now()).toMillis();
343353
if (currentWaitTime > windowedMilliResponseWaitTimeMax) {
@@ -380,7 +390,7 @@ class HealthCheckFields {
380390
long responseCount;
381391
long queuedRequestCountMax;
382392
long queuedRetryCountMax; // How many active waiting or inflight requests are retries
383-
long inflightBytes;
393+
long inflightBytesMax;
384394
long connectionAttemptCount;
385395
long connectionClosedCount;
386396
boolean isConnected; // snapshot at instant metrics are gathered
@@ -399,7 +409,7 @@ private void gatherHealthCheckMetrics(HealthCheckFields healthCheckFields) {
399409
healthCheckFields.queuedRequestCountMax = windowedQueuedRequestsMax;
400410
healthCheckFields.queuedRetryCountMax = windowedQueuedRetriesMax;
401411
healthCheckFields.msecLongestResponseWaitTime = windowedMilliResponseWaitTimeMax;
402-
healthCheckFields.inflightBytes = inflightBytes.get();
412+
healthCheckFields.inflightBytesMax = windowedInflightBytesMax;
403413
healthCheckFields.requestsSentCount = windowedRequestsSent;
404414
healthCheckFields.responseCount = windowedResponsesAcked;
405415
if (HEALTH_CHECK_INTERVAL.toMillis() > 0) {
@@ -425,7 +435,7 @@ private void gatherHealthCheckMetrics(HealthCheckFields healthCheckFields) {
425435
*/
426436
private boolean checkThresholds(HealthCheckFields healthCheckFields) {
427437
if ((healthCheckFields.queuedRequestCountMax >= queuedRequestsThreshold)
428-
|| (healthCheckFields.inflightBytes >= queuedBytesThreshold)
438+
|| (healthCheckFields.inflightBytesMax >= queuedBytesThreshold)
429439
|| (healthCheckFields.msecLongestResponseWaitTime >= responseWaitTimeThreshold.toMillis())
430440
|| (healthCheckFields.msecMaxLatency >= latencyThreshold.toMillis())
431441
|| (healthCheckFields.connectionAttemptCount >= connectionAttemptThreshold)
@@ -479,6 +489,7 @@ private void resetWindowedMetrics() {
479489
windowedConnectionClosedCount = 0;
480490
windowedQueuedRequestsMax = 0;
481491
windowedQueuedRetriesMax = 0;
492+
windowedInflightBytesMax = 0;
482493
}
483494

484495
/*
@@ -785,6 +796,7 @@ private void addMessageToWaitingQueue(
785796
AppendRequestAndResponse requestWrapper, boolean addToFront) {
786797
this.inflightRequests.incrementAndGet();
787798
this.inflightBytes.addAndGet(requestWrapper.messageSize);
799+
healthCheckMetrics.updateInflightBytesMax(this.inflightBytes.get());
788800
hasMessageInWaitingQueue.signal();
789801
requestProfilerHook.startOperation(
790802
RequestProfiler.OperationName.WAIT_QUEUE, requestWrapper.requestUniqueId);
@@ -932,6 +944,7 @@ private ApiFuture<AppendRowsResponse> appendInternal(
932944
requestProfilerHook.startOperation(RequestProfiler.OperationName.WAIT_QUEUE, requestUniqueId);
933945
this.inflightRequests.incrementAndGet();
934946
this.inflightBytes.addAndGet(requestWrapper.messageSize);
947+
healthCheckMetrics.updateInflightBytesMax(this.inflightBytes.get());
935948
requestWrapper.placedInWaitingQueueTime = Instant.now();
936949
waitingRequestQueue.addLast(requestWrapper);
937950
healthCheckMetrics.updateWindowedQueuedRequestsMax(

‎java-bigquerystorage/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/ConnectionWorkerTest.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,7 @@ void testHealthCheck() throws Exception {
12961296
healthCheckFields.msecLongestResponseWaitTime > 1
12971297
&& healthCheckFields.msecLongestResponseWaitTime < msecResponseDelay);
12981298
assertEquals(appendCount, healthCheckFields.queuedRequestCountMax);
1299-
assertEquals(appendCount * sizePerRequest, healthCheckFields.inflightBytes);
1299+
assertEquals(appendCount * sizePerRequest, healthCheckFields.inflightBytesMax);
13001300
assertEquals("MULTIPLEXING", healthCheckFields.streamName);
13011301
assertEquals(connectionWorker.getWriterId(), healthCheckFields.writerId);
13021302

@@ -1363,7 +1363,7 @@ void testHealthCheckThresholds() throws Exception {
13631363
fields.responseCount = 0;
13641364
fields.queuedRequestCountMax = 0;
13651365
fields.queuedRetryCountMax = 0;
1366-
fields.inflightBytes = 0;
1366+
fields.inflightBytesMax = 0;
13671367
fields.connectionAttemptCount = 0;
13681368
fields.connectionClosedCount = 0;
13691369
fields.isConnected = false;
@@ -1415,9 +1415,9 @@ void testHealthCheckThresholds() throws Exception {
14151415
fields.queuedRetryCountMax = 0;
14161416

14171417
// inflightBytes >= queuedBytesThreshold (52428800)
1418-
fields.inflightBytes = 50 * 1024 * 1024;
1418+
fields.inflightBytesMax = 50 * 1024 * 1024;
14191419
assertEquals(true, connectionWorker.checkTestOnlyHealthCheckThresholds(fields));
1420-
fields.inflightBytes = 0;
1420+
fields.inflightBytesMax = 0;
14211421

14221422
// connectionAttemptCount >= connectionAttemptThreshold (1)
14231423
fields.connectionAttemptCount = 1;

0 commit comments

Comments
 (0)