-
Notifications
You must be signed in to change notification settings - Fork 135
fix: multiplexed session metrics were not included in refactor move #3088
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,7 +68,6 @@ | |
import com.google.common.base.Function; | ||
import com.google.common.base.MoreObjects; | ||
import com.google.common.base.Preconditions; | ||
import com.google.common.base.Supplier; | ||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.util.concurrent.ForwardingListenableFuture; | ||
import com.google.common.util.concurrent.ForwardingListenableFuture.SimpleForwardingListenableFuture; | ||
|
@@ -156,7 +155,8 @@ void maybeWaitOnMinSessions() { | |
} | ||
} | ||
|
||
private abstract static class CachedResultSetSupplier implements Supplier<ResultSet> { | ||
private abstract static class CachedResultSetSupplier | ||
implements com.google.common.base.Supplier<ResultSet> { | ||
|
||
private ResultSet cached; | ||
|
||
|
@@ -2265,7 +2265,6 @@ public String getName() { | |
@Override | ||
public void close() { | ||
synchronized (lock) { | ||
numMultiplexedSessionsReleased++; | ||
if (lastException != null && isDatabaseOrInstanceNotFound(lastException)) { | ||
SessionPool.this.resourceNotFoundException = | ||
MoreObjects.firstNonNull( | ||
|
@@ -2771,15 +2770,9 @@ enum Position { | |
@GuardedBy("lock") | ||
private long numSessionsAcquired = 0; | ||
|
||
@GuardedBy("lock") | ||
private long numMultiplexedSessionsAcquired = 0; | ||
|
||
@GuardedBy("lock") | ||
private long numSessionsReleased = 0; | ||
|
||
@GuardedBy("lock") | ||
private long numMultiplexedSessionsReleased = 0; | ||
|
||
@GuardedBy("lock") | ||
private long numIdleSessionsRemoved = 0; | ||
|
||
|
@@ -2830,7 +2823,9 @@ static SessionPool createPool( | |
SessionClient sessionClient, | ||
TraceWrapper tracer, | ||
List<LabelValue> labelValues, | ||
Attributes attributes) { | ||
Attributes attributes, | ||
AtomicLong numMultiplexedSessionsAcquired, | ||
AtomicLong numMultiplexedSessionsReleased) { | ||
final SessionPoolOptions sessionPoolOptions = spannerOptions.getSessionPoolOptions(); | ||
|
||
// A clock instance is passed in {@code SessionPoolOptions} in order to allow mocking via tests. | ||
|
@@ -2846,7 +2841,9 @@ static SessionPool createPool( | |
tracer, | ||
labelValues, | ||
spannerOptions.getOpenTelemetry(), | ||
attributes); | ||
attributes, | ||
numMultiplexedSessionsAcquired, | ||
numMultiplexedSessionsReleased); | ||
} | ||
|
||
static SessionPool createPool( | ||
|
@@ -2884,7 +2881,9 @@ static SessionPool createPool( | |
tracer, | ||
SPANNER_DEFAULT_LABEL_VALUES, | ||
openTelemetry, | ||
null); | ||
null, | ||
new AtomicLong(), | ||
new AtomicLong()); | ||
} | ||
|
||
static SessionPool createPool( | ||
|
@@ -2898,7 +2897,9 @@ static SessionPool createPool( | |
TraceWrapper tracer, | ||
List<LabelValue> labelValues, | ||
OpenTelemetry openTelemetry, | ||
Attributes attributes) { | ||
Attributes attributes, | ||
AtomicLong numMultiplexedSessionsAcquired, | ||
AtomicLong numMultiplexedSessionsReleased) { | ||
SessionPool pool = | ||
new SessionPool( | ||
poolOptions, | ||
|
@@ -2912,7 +2913,9 @@ static SessionPool createPool( | |
tracer, | ||
labelValues, | ||
openTelemetry, | ||
attributes); | ||
attributes, | ||
numMultiplexedSessionsAcquired, | ||
numMultiplexedSessionsReleased); | ||
pool.initPool(); | ||
return pool; | ||
} | ||
|
@@ -2929,7 +2932,9 @@ private SessionPool( | |
TraceWrapper tracer, | ||
List<LabelValue> labelValues, | ||
OpenTelemetry openTelemetry, | ||
Attributes attributes) { | ||
Attributes attributes, | ||
AtomicLong numMultiplexedSessionsAcquired, | ||
AtomicLong numMultiplexedSessionsReleased) { | ||
this.options = options; | ||
this.databaseRole = databaseRole; | ||
this.executorFactory = executorFactory; | ||
|
@@ -2940,8 +2945,13 @@ private SessionPool( | |
this.initialReleasePosition = initialReleasePosition; | ||
this.poolMaintainer = new PoolMaintainer(); | ||
this.tracer = tracer; | ||
this.initOpenCensusMetricsCollection(metricRegistry, labelValues); | ||
this.initOpenTelemetryMetricsCollection(openTelemetry, attributes); | ||
this.initOpenCensusMetricsCollection( | ||
metricRegistry, | ||
labelValues, | ||
numMultiplexedSessionsAcquired, | ||
numMultiplexedSessionsReleased); | ||
this.initOpenTelemetryMetricsCollection( | ||
openTelemetry, attributes, numMultiplexedSessionsAcquired, numMultiplexedSessionsReleased); | ||
this.waitOnMinSessionsLatch = | ||
options.getMinSessions() > 0 ? new CountDownLatch(1) : new CountDownLatch(0); | ||
this.waitOnMultiplexedSessionsLatch = new CountDownLatch(1); | ||
|
@@ -3143,7 +3153,7 @@ boolean isValid() { | |
|
||
/** | ||
* Returns a multiplexed session. The method fallbacks to a regular session if {@link | ||
* SessionPoolOptions#useMultiplexedSession} is not set. | ||
* SessionPoolOptions#getUseMultiplexedSession} is not set. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This reference was wrong, and showed up as a warning in IntelliJ |
||
*/ | ||
SessionFutureWrapper getMultiplexedSessionWithFallback() throws SpannerException { | ||
if (useMultiplexedSessions()) { | ||
|
@@ -3250,8 +3260,6 @@ private void incrementNumSessionsInUse(boolean isMultiplexed) { | |
maxSessionsInUse = numSessionsInUse; | ||
} | ||
numSessionsAcquired++; | ||
} else { | ||
numMultiplexedSessionsAcquired++; | ||
} | ||
} | ||
} | ||
|
@@ -3775,7 +3783,10 @@ public void onSessionCreateFailure(Throwable t, int createFailureForSessionCount | |
* exporter, it allows users to monitor client behavior. | ||
*/ | ||
private void initOpenCensusMetricsCollection( | ||
MetricRegistry metricRegistry, List<LabelValue> labelValues) { | ||
MetricRegistry metricRegistry, | ||
List<LabelValue> labelValues, | ||
AtomicLong numMultiplexedSessionsAcquired, | ||
AtomicLong numMultiplexedSessionsReleased) { | ||
if (!SpannerOptions.isEnabledOpenCensusMetrics()) { | ||
return; | ||
} | ||
|
@@ -3860,18 +3871,14 @@ private void initOpenCensusMetricsCollection( | |
labelValuesWithRegularSessions, this, sessionPool -> sessionPool.numSessionsAcquired); | ||
numAcquiredSessionsMetric.removeTimeSeries(labelValuesWithMultiplexedSessions); | ||
numAcquiredSessionsMetric.createTimeSeries( | ||
labelValuesWithMultiplexedSessions, | ||
this, | ||
sessionPool -> sessionPool.numMultiplexedSessionsAcquired); | ||
labelValuesWithMultiplexedSessions, this, unused -> numMultiplexedSessionsAcquired.get()); | ||
|
||
numReleasedSessionsMetric.removeTimeSeries(labelValuesWithRegularSessions); | ||
numReleasedSessionsMetric.createTimeSeries( | ||
labelValuesWithRegularSessions, this, sessionPool -> sessionPool.numSessionsReleased); | ||
numReleasedSessionsMetric.removeTimeSeries(labelValuesWithMultiplexedSessions); | ||
numReleasedSessionsMetric.createTimeSeries( | ||
labelValuesWithMultiplexedSessions, | ||
this, | ||
sessionPool -> sessionPool.numMultiplexedSessionsReleased); | ||
labelValuesWithMultiplexedSessions, this, unused -> numMultiplexedSessionsReleased.get()); | ||
|
||
List<LabelValue> labelValuesWithBeingPreparedType = new ArrayList<>(labelValues); | ||
labelValuesWithBeingPreparedType.add(NUM_SESSIONS_BEING_PREPARED); | ||
|
@@ -3909,7 +3916,10 @@ private void initOpenCensusMetricsCollection( | |
* an exporter, it allows users to monitor client behavior. | ||
*/ | ||
private void initOpenTelemetryMetricsCollection( | ||
OpenTelemetry openTelemetry, Attributes attributes) { | ||
OpenTelemetry openTelemetry, | ||
Attributes attributes, | ||
AtomicLong numMultiplexedSessionsAcquired, | ||
AtomicLong numMultiplexedSessionsReleased) { | ||
if (openTelemetry == null || !SpannerOptions.isEnabledOpenTelemetryMetrics()) { | ||
return; | ||
} | ||
|
@@ -3981,7 +3991,8 @@ private void initOpenTelemetryMetricsCollection( | |
.buildWithCallback( | ||
measurement -> { | ||
measurement.record(this.numSessionsAcquired, attributesRegularSession); | ||
measurement.record(this.numMultiplexedSessionsAcquired, attributesMultiplexedSession); | ||
measurement.record( | ||
numMultiplexedSessionsAcquired.get(), attributesMultiplexedSession); | ||
}); | ||
|
||
meter | ||
|
@@ -3991,7 +4002,8 @@ private void initOpenTelemetryMetricsCollection( | |
.buildWithCallback( | ||
measurement -> { | ||
measurement.record(this.numSessionsReleased, attributesRegularSession); | ||
measurement.record(this.numMultiplexedSessionsReleased, attributesMultiplexedSession); | ||
measurement.record( | ||
numMultiplexedSessionsReleased.get(), attributesMultiplexedSession); | ||
}); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not directly related to this change, but we should start to replace the use of
com.google.common.base.Supplier
withjava.util.function.Supplier
.