Skip to content
Permalink
Browse files
fix: remove time series before adding it (#766)
Adding the same time series multiple times will cause an error in OpenCensus. A time
series could be added multiple times for the same Database client id if a database
client was invalidated, for example because if was created for a database that did
not exist.

Fixes #202
  • Loading branch information
olavloite committed Jan 14, 2021
1 parent 1a71e50 commit 90255ea7a1cc70ba4f4ab48551c509f503981540
Showing with 9 additions and 0 deletions.
  1. +9 −0 google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionPool.java
@@ -2370,6 +2370,7 @@ private void initMetricsCollection(MetricRegistry metricRegistry, List<LabelValu

// The value of a maxSessionsInUse is observed from a callback function. This function is
// invoked whenever metrics are collected.
maxInUseSessionsMetric.removeTimeSeries(labelValues);
maxInUseSessionsMetric.createTimeSeries(
labelValues,
this,
@@ -2382,6 +2383,7 @@ public long applyAsLong(SessionPool sessionPool) {

// The value of a maxSessions is observed from a callback function. This function is invoked
// whenever metrics are collected.
maxAllowedSessionsMetric.removeTimeSeries(labelValues);
maxAllowedSessionsMetric.createTimeSeries(
labelValues,
options,
@@ -2394,6 +2396,7 @@ public long applyAsLong(SessionPoolOptions options) {

// The value of a numWaiterTimeouts is observed from a callback function. This function is
// invoked whenever metrics are collected.
sessionsTimeouts.removeTimeSeries(labelValues);
sessionsTimeouts.createTimeSeries(
labelValues,
this,
@@ -2404,6 +2407,7 @@ public long applyAsLong(SessionPool sessionPool) {
}
});

numAcquiredSessionsMetric.removeTimeSeries(labelValues);
numAcquiredSessionsMetric.createTimeSeries(
labelValues,
this,
@@ -2414,6 +2418,7 @@ public long applyAsLong(SessionPool sessionPool) {
}
});

numReleasedSessionsMetric.removeTimeSeries(labelValues);
numReleasedSessionsMetric.createTimeSeries(
labelValues,
this,
@@ -2426,6 +2431,7 @@ public long applyAsLong(SessionPool sessionPool) {

List<LabelValue> labelValuesWithBeingPreparedType = new ArrayList<>(labelValues);
labelValuesWithBeingPreparedType.add(NUM_SESSIONS_BEING_PREPARED);
numSessionsInPoolMetric.removeTimeSeries(labelValuesWithBeingPreparedType);
numSessionsInPoolMetric.createTimeSeries(
labelValuesWithBeingPreparedType,
this,
@@ -2439,6 +2445,7 @@ public long applyAsLong(SessionPool sessionPool) {

List<LabelValue> labelValuesWithInUseType = new ArrayList<>(labelValues);
labelValuesWithInUseType.add(NUM_IN_USE_SESSIONS);
numSessionsInPoolMetric.removeTimeSeries(labelValuesWithInUseType);
numSessionsInPoolMetric.createTimeSeries(
labelValuesWithInUseType,
this,
@@ -2451,6 +2458,7 @@ public long applyAsLong(SessionPool sessionPool) {

List<LabelValue> labelValuesWithReadType = new ArrayList<>(labelValues);
labelValuesWithReadType.add(NUM_READ_SESSIONS);
numSessionsInPoolMetric.removeTimeSeries(labelValuesWithReadType);
numSessionsInPoolMetric.createTimeSeries(
labelValuesWithReadType,
this,
@@ -2463,6 +2471,7 @@ public long applyAsLong(SessionPool sessionPool) {

List<LabelValue> labelValuesWithWriteType = new ArrayList<>(labelValues);
labelValuesWithWriteType.add(NUM_WRITE_SESSIONS);
numSessionsInPoolMetric.removeTimeSeries(labelValuesWithWriteType);
numSessionsInPoolMetric.createTimeSeries(
labelValuesWithWriteType,
this,

0 comments on commit 90255ea

Please sign in to comment.