Skip to content

Commit

Permalink
fix: remove time series before adding it (#766)
Browse files Browse the repository at this point in the history
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 90255ea
Showing 1 changed file with 9 additions and 0 deletions.
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -2404,6 +2407,7 @@ public long applyAsLong(SessionPool sessionPool) {
}
});

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

numReleasedSessionsMetric.removeTimeSeries(labelValues);
numReleasedSessionsMetric.createTimeSeries(
labelValues,
this,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 90255ea

Please sign in to comment.