Skip to content
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

Spanner Client Multiple Databases & Session Pools Support #2176

Open
spicydev opened this issue Nov 28, 2022 · 6 comments
Open

Spanner Client Multiple Databases & Session Pools Support #2176

spicydev opened this issue Nov 28, 2022 · 6 comments
Assignees
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.

Comments

@spicydev
Copy link

spicydev commented Nov 28, 2022

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.

@product-auto-label product-auto-label bot added the api: spanner Issues related to the googleapis/java-spanner API. label Nov 28, 2022
@spicydev
Copy link
Author

spicydev commented Dec 1, 2022

@olavloite and @rahul2393 . What are your thoughts on the above issue.

@ansh0l ansh0l added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. priority: p3 Desirable enhancement or fix. May not be included in next release. labels Dec 1, 2022
@ansh0l
Copy link
Member

ansh0l commented Dec 1, 2022

@spicydev : Could you reach out to us through a support ticket? we would like to better understand your use case.

@gauravpurohit06
Copy link
Contributor

@spicydev, Have you logged a support ticket for it?

@spicydev
Copy link
Author

Yes. I did log a support ticket for this issue.

@olavloite
Copy link
Collaborator

@spicydev Sorry, I missed this the last time I was tagged. Do you know what version of the Java client Spring Data pulls in in your case?

@spicydev
Copy link
Author

Hi @olavloite , To your question, we are currently using the v3.1.1 Spanner java client based on spring boot 2.3.12.RELEASE

But the above bug is still replicable with latest version of the Spanner java client. Then problem is that when we are trying to create multiple spanner database-clients with Opencensus metrics instrumented. The second database-client fails to create the session pool at the following method: SessionPool.initMetricsCollection().

Possible fix would be allowing the consumers of library to add metrics name prefix or adding the database name to metrics by default so that two database-clients can use different metric names and we can monitor both session pools separately in GCP Metrics Explorer.

Let me know if more information is needed. Thanks

@gauravpurohit06 gauravpurohit06 removed their assignment May 18, 2023
@arpan14 arpan14 self-assigned this Jul 3, 2023
@arpan14 arpan14 assigned rahul2393 and unassigned arpan14 Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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.
Projects
None yet
Development

No branches or pull requests

6 participants