Skip to content

Commit d61b4f3

Browse files
committed
fix: max_in_use_session metric time
1 parent ac1ddbc commit d61b4f3

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionPool.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2060,7 +2060,15 @@ void maintainPool() {
20602060
}
20612061
this.prevNumSessionsAcquired = SessionPool.this.numSessionsAcquired;
20622062
}
2063+
2064+
// Reset the start time for recording the maximum number of sessions
2065+
// in the pool.
20632066
Instant currTime = clock.instant();
2067+
if (currTime.isAfter(SessionPool.this.lastResetTime.plus(Duration.ofMinutes(10)))) {
2068+
SessionPool.this.maxSessionsInUse = SessionPool.this.numSessionsInUse;
2069+
SessionPool.this.lastResetTime = currTime;
2070+
}
2071+
20642072
removeIdleSessions(currTime);
20652073
// Now go over all the remaining sessions and see if they need to be kept alive explicitly.
20662074
keepAliveSessions(currTime);
@@ -2309,6 +2317,9 @@ enum Position {
23092317
@GuardedBy("lock")
23102318
private int maxSessionsInUse = 0;
23112319

2320+
@GuardedBy("lock")
2321+
private Instant lastResetTime = Clock.INSTANCE.instant();
2322+
23122323
@GuardedBy("lock")
23132324
private long numSessionsAcquired = 0;
23142325

0 commit comments

Comments
 (0)