From 90255ea7a1cc70ba4f4ab48551c509f503981540 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Knut=20Olav=20L=C3=B8ite?= Date: Thu, 14 Jan 2021 23:19:29 +0100 Subject: [PATCH] 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 --- .../main/java/com/google/cloud/spanner/SessionPool.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionPool.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionPool.java index fcb87304f6..cc431b52a5 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionPool.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionPool.java @@ -2370,6 +2370,7 @@ private void initMetricsCollection(MetricRegistry metricRegistry, List 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 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 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 labelValuesWithWriteType = new ArrayList<>(labelValues); labelValuesWithWriteType.add(NUM_WRITE_SESSIONS); + numSessionsInPoolMetric.removeTimeSeries(labelValuesWithWriteType); numSessionsInPoolMetric.createTimeSeries( labelValuesWithWriteType, this,