Spanner Client Multiple Databases & Session Pools Support #2176
Labels
api: spanner
Issues related to the googleapis/java-spanner API.
priority: p3
Desirable enhancement or fix. May not be included in next release.
type: feature request
‘Nice-to-have’ improvement, new feature or different behavior or design.
Is your feature request related to a problem? Please describe.
Yes, Recently in my project I've tried to configure spanner java client to connect to multiple databases from different spanner instances using the Spring Data Framework with multiple SpannerTemplate Beans.
This worked flawlessly but the problem started when we instrumented the app to export Opencensus metrics to Stackdriver using the Opencensus Implementation & exporter. Then we started to notice below blocking error that makes the second database inoperable to write or read data from.
StackTrace:
java.lang.IllegalArgumentException: A different metric with the same name already registered.
at io.opencensus.implcore.metrics.MetricRegistryImpl$RegisteredMeters.registerMeter(MetricRegistryImpl.java:172)
at io.opencensus.implcore.metrics.MetricRegistryImpl$RegisteredMeters.access$200(MetricRegistryImpl.java:161)
at io.opencensus.implcore.metrics.MetricRegistryImpl.addDerivedLongGauge(MetricRegistryImpl.java:88)
at com.google.cloud.spanner.SessionPool.initMetricsCollection(SessionPool.java:2309)
at com.google.cloud.spanner.SessionPool.(SessionPool.java:1845)
at com.google.cloud.spanner.SessionPool.createPool(SessionPool.java:1822)
at com.google.cloud.spanner.SessionPool.createPool(SessionPool.java:1781)
at com.google.cloud.spanner.SpannerImpl.getDatabaseClient(SpannerImpl.java:225)
at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660)
at org.springframework.cloud.gcp.data.spanner.core.admin.CachingComposingSupplier.get(CachingComposingSupplier.java:52)
... 114 frames truncated
Describe the solution you'd like
I would like to see support to at least specify the metrics prefix when creating Database Client Bean using com.google.cloud.spanner.SpannerImpl#getDatabaseClient. That would resolve multiple databases issue and make the library support without sacrificing the metrics completely.
Describe alternatives you've considered
Temporary solution is to completely remove the Opencensus Impl library from maven dependencies in the runtime
or
Disable configuring multiple databases in spanner client and connect to only one database at a time.
Any Feedback on the above issue or improving this feature request is appreciated.
The text was updated successfully, but these errors were encountered: