Skip to content

Commit 9333aae

Browse files
feat: add duration to health metrics
1 parent 4c5fe0c commit 9333aae

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,13 +383,14 @@ class HealthCheckFields {
383383
String streamName;
384384
String writerId;
385385
String windowStartTime;
386+
String windowDuration;
386387
}
387388

388389
/*
389390
* Compute current values of all health check metrics.
390391
*/
391392
private void gatherHealthCheckMetrics(HealthCheckFields healthCheckFields) {
392-
healthCheckFields.streamName = streamName;
393+
healthCheckFields.streamName = isMultiplexing ? "MULTIPLEXING" : streamName;
393394
healthCheckFields.writerId = writerId;
394395
healthCheckFields.queuedRequestCountMax = windowedQueuedRequestsMax;
395396
healthCheckFields.queuedRetryCountMax = windowedQueuedRetriesMax;
@@ -412,6 +413,7 @@ private void gatherHealthCheckMetrics(HealthCheckFields healthCheckFields) {
412413
healthCheckFields.connectionClosedCount = windowedConnectionClosedCount;
413414
healthCheckFields.isConnected = streamConnectionIsConnected;
414415
healthCheckFields.windowStartTime = healthCheckTimeStamp.toString();
416+
healthCheckFields.windowDuration = HEALTH_CHECK_INTERVAL.toString();
415417
}
416418

417419
/*

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1206,7 +1206,7 @@ void testHealthCheck() throws Exception {
12061206
&& healthCheckFields.msecLongestResponseWaitTime < msecResponseDelay);
12071207
assertEquals(appendCount, healthCheckFields.queuedRequestCountMax);
12081208
assertEquals(appendCount * sizePerRequest, healthCheckFields.inflightBytes);
1209-
assertEquals("projects/p1/datasets/d1/tables/t1/streams/s1", healthCheckFields.streamName);
1209+
assertEquals("MULTIPLEXING", healthCheckFields.streamName);
12101210
assertEquals(connectionWorker.getWriterId(), healthCheckFields.writerId);
12111211

12121212
// Wait for responses to arrive
@@ -1362,6 +1362,7 @@ void testInflightRetryCountHealthMetric() throws Exception {
13621362
/* enableRequestProfiler= */ false,
13631363
/* enableOpenTelemetry= */ false,
13641364
/* isMultiplexing= */ true);
1365+
connectionWorker.setTestOnlyHealthCheckInterval(Duration.ofSeconds(10));
13651366

13661367
// Simulate a retriable error
13671368
int msecResponseDelay = 1000;
@@ -1388,6 +1389,8 @@ void testInflightRetryCountHealthMetric() throws Exception {
13881389
assertTrue(healthCheckFields.responseCodes.containsKey(Code.INTERNAL.value()));
13891390
assertEquals(1, healthCheckFields.responseCodes.get(Code.INTERNAL.value()));
13901391
assertFalse(healthCheckFields.responseCodes.containsKey(Status.Code.OK.value()));
1392+
assertEquals("MULTIPLEXING", healthCheckFields.streamName);
1393+
assertEquals(Duration.ofSeconds(10).toString(), healthCheckFields.windowDuration);
13911394

13921395
// Allow the retries to complete successfully
13931396
future.get();
@@ -1499,5 +1502,6 @@ void testInflightRetryCountHealthMetricExactlyOnce() throws Exception {
14991502
assertEquals(1, healthCheckFields.responseCodes.get(Code.INTERNAL.value()));
15001503
assertTrue(healthCheckFields.responseCodes.containsKey(Status.Code.OK.value()));
15011504
assertEquals(3, healthCheckFields.responseCodes.get(Status.Code.OK.value()));
1505+
assertEquals("projects/p1/datasets/d1/tables/t1/streams/s1", healthCheckFields.streamName);
15021506
}
15031507
}

0 commit comments

Comments
 (0)