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

fix: remove time series before adding it #766

Merged
merged 1 commit into from Jan 14, 2021

Conversation

olavloite
Copy link
Collaborator

@olavloite olavloite commented Dec 31, 2020

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.

This works for OpenCensusImpl 0.26 but not for 0.24, but that seems to be the case both with and without this change. With this change the problem is solved for 0.26. In version 0.24 OpenCensusImpl will always throw an error if you try to add a metric with the same name twice.

Fixes #202

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
@olavloite olavloite requested a review from a team as a code owner December 31, 2020 09:01
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Dec 31, 2020
@olavloite olavloite added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Dec 31, 2020
@olavloite olavloite added kokoro:force-run Add this label to force Kokoro to re-run the tests. and removed do not merge Indicates a pull request not ready for merge, due to either quality or timing. labels Dec 31, 2020
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 31, 2020
@olavloite olavloite added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 31, 2020
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 31, 2020
@codecov
Copy link

codecov bot commented Dec 31, 2020

Codecov Report

Merging #766 (5dc62bc) into master (3d9689c) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #766   +/-   ##
=========================================
  Coverage     85.00%   85.00%           
  Complexity     2562     2562           
=========================================
  Files           143      143           
  Lines         14007    14016    +9     
  Branches       1338     1338           
=========================================
+ Hits          11906    11915    +9     
  Misses         1538     1538           
  Partials        563      563           
Impacted Files Coverage Δ Complexity Δ
...ain/java/com/google/cloud/spanner/SessionPool.java 88.92% <100.00%> (+0.09%) 71.00 <0.00> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3d9689c...5dc62bc. Read the comment docs.

@product-auto-label product-auto-label bot added the api: spanner Issues related to the googleapis/java-spanner API. label Jan 1, 2021
@sebright
Copy link
Contributor

sebright commented Jan 4, 2021

@olavloite Thanks for fixing issue #202! I tested this PR with my application, and it worked with OpenCensus 0.26.0 as well as 0.28.0.

Copy link
Contributor

@sebright sebright left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly, the issue with increasing client IDs could still occur if a different exception were thrown from

. It might help to also make a separate change to the error handling in SpannerImpl.getDatabaseClient.

@olavloite
Copy link
Collaborator Author

If I understand correctly, the issue with increasing client IDs could still occur if a different exception were thrown from

That is correct.

. It might help to also make a separate change to the error handling in SpannerImpl.getDatabaseClient.

I'm somewhat reluctant to do that. As I see it, the real problem here is not that the client IDs are increasing, but the fact that createPool was throwing an exception. It is a method that should normally not throw any exceptions, and adding additional error handling in SpannerImpl#getDatabaseClient(DatabaseId) might mask other unexpected errors. Note that if the user has specified for example an invalid database name, createPool will not throw an exception. Instead, that error will be delayed until the user tries to get a session from the pool. Such errors that are caused by invalid input arguments will not cause the problem with ever-increasing client IDs.

@sebright
Copy link
Contributor

sebright commented Jan 4, 2021

That makes sense. I didn't realize that createPool was designed to not throw exceptions.

@thiagotnunes
Copy link
Contributor

@olavloite Just for my understanding, won't this remove historical data (time series data) if the user redeploys their application?

@olavloite
Copy link
Collaborator Author

@olavloite Just for my understanding, won't this remove historical data (time series data) if the user redeploys their application?

Good question. It won't be a problem after a redeploy, as these time-series are all in-memory on the local client, so these data structures will be all empty after a redeploy. But I'll take an extra look to check that it won't be a problem if a SessionPool is used for a while, then invalidated because of for example a deleted database, and then a new one with the same name is created.

@skuruppu skuruppu requested review from thiagotnunes and removed request for skuruppu January 6, 2021 02:48
@olavloite
Copy link
Collaborator Author

@olavloite Just for my understanding, won't this remove historical data (time series data) if the user redeploys their application?

I've been stepping through the OpenCensus implementation, and my conclusion based on that is:

  1. Removing a TimeSeries or other metric that has not already been added in the current local deployment is a no-op. This means that in the normal case where a new SessionPool is created, the removeTimeSeries(..) calls are no-ops.
  2. Removing a TimeSeries that has been previously added in the current JVM, will remove the local data structure from memory. This means that any data that has not yet been pushed to the server, will be lost. It will not remove any data on the server.
  3. How much metrics that might be lost, depends on the exporter and how often this exports data to the server.

It is however important to realize that any in-mem sampling data will only be lost in the case that:

  1. A SessionPool is created and can operate normally.
  2. The SessionPool is invalidated because the underlying database or instance is deleted.
  3. A new SessionPool is created in the same JVM for the same database that was deleted in step 2.

@thiagotnunes
Copy link
Contributor

Thanks for the analysis @olavloite. LGTM

@thiagotnunes thiagotnunes merged commit 90255ea into master Jan 14, 2021
@thiagotnunes thiagotnunes deleted the remove-time-series-before-add branch January 14, 2021 22:19
thiagotnunes pushed a commit that referenced this pull request May 6, 2021
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
ansh0l pushed a commit to ansh0l/java-spanner that referenced this pull request Nov 10, 2022
This is an auto-generated regeneration of the .pb.go files by
cloud.google.com/go/internal/gapicgen. Once this PR is submitted, genbot will
update the corresponding PR to depend on the newer version of go-genproto, and
assign reviewers. Whilst this or any regen PR is open in go-genproto, genbot
will not create any more regeneration PRs. If all regen PRs are closed,
gapicgen will create a new set of regeneration PRs once per night.

If you have been assigned to review this PR, please:

- Ensure that CI is passing. If it's failing, it requires your manual attention.
- Approve and submit this PR if you believe it's ready to ship. That will prompt
genbot to assign reviewers to the google-cloud-go PR.

Corresponding google-cloud-go PR: googleapis/google-cloud-go#5699

Changes:

chore: use gapic-generator-python 0.63.4
  chore: fix snippet region tag format
  chore: fix docstring code block formatting
  PiperOrigin-RevId: 430730865
  Source-Link: googleapis/googleapis@ea58002

feat(gkehub): added support for k8s_version field docs: k8s_version field is not part of resource_options struct
  Clients now generate the V1 or V1beta1 CRD based on Kubernetes server version.

  PiperOrigin-RevId: 430569173
  Source-Link: googleapis/googleapis@3c17193

chore: new versions of Ruby and PHP generators with rebuilt runtimes
  PiperOrigin-RevId: 430539125
  Source-Link: googleapis/googleapis@9e18f9c

feat: added support for k8s_version field docs: k8s_version field is not part of resource_options struct
  Clients now generate the V1 or V1beta1 CRD based on Kubernetes server version.

  PiperOrigin-RevId: 430496281
  Source-Link: googleapis/googleapis@97cf70e

chore: regenerate API index

  Source-Link: googleapis/googleapis@5a1add9

refactor: use updated protos for DeliveryService
  PiperOrigin-RevId: 430330814
  Source-Link: googleapis/googleapis@948c8fd

Synchronize new proto/yaml changes.
  PiperOrigin-RevId: 430323776
  Source-Link: googleapis/googleapis@88075ae

chore(bigquery/migration): move gRPC service config for BigQuery Migration API to the proper place
  PiperOrigin-RevId: 430291802
  Source-Link: googleapis/googleapis@026165e

feat(aiplatform): add TPU_V2 & TPU_V3 values to AcceleratorType in aiplatform v1/v1beta1 accelerator_type.proto
  PiperOrigin-RevId: 430259767
  Source-Link: googleapis/googleapis@f873e7f

build: update artifact name for npm
  PiperOrigin-RevId: 430257044
  Source-Link: googleapis/googleapis@3e5d2ea

chore: regenerate API index

  Source-Link: googleapis/googleapis@7af9c68

feat(logging): KMS configuration in settings chore: formatting changes
  PiperOrigin-RevId: 430243637
  Source-Link: googleapis/googleapis@95da686

chore: regenerate API index

  Source-Link: googleapis/googleapis@fec96b7

fix(dataflow): Use http binding with location field as primary http bindings
  Changing HTTP bindings and/or their order might be a breaking change for libraries.

  PiperOrigin-RevId: 430239565
  Source-Link: googleapis/googleapis@71fe7ff
rajatbhatta pushed a commit to rajatbhatta/java-spanner that referenced this pull request Nov 17, 2022
…jdbc to v2.6.0 (googleapis#766)

[![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [com.google.cloud:google-cloud-spanner-jdbc](https://togithub.com/googleapis/java-spanner-jdbc) | `2.5.11` -> `2.6.0` | [![age](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-spanner-jdbc/2.6.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-spanner-jdbc/2.6.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-spanner-jdbc/2.6.0/compatibility-slim/2.5.11)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-spanner-jdbc/2.6.0/confidence-slim/2.5.11)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>googleapis/java-spanner-jdbc</summary>

### [`v2.6.0`](https://togithub.com/googleapis/java-spanner-jdbc/blob/HEAD/CHANGELOG.md#&#8203;260-httpsgithubcomgoogleapisjava-spanner-jdbccomparev2511v260-2022-02-24)

[Compare Source](https://togithub.com/googleapis/java-spanner-jdbc/compare/v2.5.11...v2.6.0)

##### Features

-   add support for PostgreSQL dialect ([#&#8203;739](https://togithub.com/googleapis/java-spanner-jdbc/issues/739)) ([f9daa19](https://togithub.com/googleapis/java-spanner-jdbc/commit/f9daa19453b33252bf61160ff9cde1c37284ca2b))

##### Bug Fixes

-   create specific metadata queries for PG ([#&#8203;759](https://togithub.com/googleapis/java-spanner-jdbc/issues/759)) ([caffda0](https://togithub.com/googleapis/java-spanner-jdbc/commit/caffda03e528da6a3c2c17b7058eb5d29f5086f9))

##### Dependencies

-   update dependency com.google.cloud:google-cloud-spanner-bom to v6.20.0 ([#&#8203;758](https://togithub.com/googleapis/java-spanner-jdbc/issues/758)) ([311d1ca](https://togithub.com/googleapis/java-spanner-jdbc/commit/311d1cabff7e7e2f5cf2cdcdda90ba536eadfa68))

##### [2.5.11](https://togithub.com/googleapis/java-spanner-jdbc/compare/v2.5.10...v2.5.11) (2022-02-11)

##### Dependencies

-   update actions/github-script action to v6 ([#&#8203;745](https://togithub.com/googleapis/java-spanner-jdbc/issues/745)) ([2ccd5b8](https://togithub.com/googleapis/java-spanner-jdbc/commit/2ccd5b8ac878c81535c14e404aeaf67e6e41a464))

##### [2.5.10](https://togithub.com/googleapis/java-spanner-jdbc/compare/v2.5.9...v2.5.10) (2022-02-09)

##### Dependencies

-   update dependency com.google.cloud:google-cloud-spanner-bom to v6.18.0 ([#&#8203;734](https://togithub.com/googleapis/java-spanner-jdbc/issues/734)) ([52f407a](https://togithub.com/googleapis/java-spanner-jdbc/commit/52f407a5e73d13fdeb9b5438d6e5cbd026cb3942))

##### [2.5.9](https://togithub.com/googleapis/java-spanner-jdbc/compare/v2.5.8...v2.5.9) (2022-02-03)

##### Bug Fixes

-   **java:** replace excludedGroup with exclude ([#&#8203;720](https://togithub.com/googleapis/java-spanner-jdbc/issues/720)) ([7f13c88](https://togithub.com/googleapis/java-spanner-jdbc/commit/7f13c88f8c9e509de8c82cb788ab9b4964806381))

##### Dependencies

-   **java:** update actions/github-script action to v5 ([#&#8203;1339](https://togithub.com/googleapis/java-spanner-jdbc/issues/1339)) ([#&#8203;725](https://togithub.com/googleapis/java-spanner-jdbc/issues/725)) ([4f96ec1](https://togithub.com/googleapis/java-spanner-jdbc/commit/4f96ec1c864b176564ac3200565b5ea524d8adfb))
-   update actions/github-script action to v5 ([#&#8203;724](https://togithub.com/googleapis/java-spanner-jdbc/issues/724)) ([5c1d6ff](https://togithub.com/googleapis/java-spanner-jdbc/commit/5c1d6ff72ba81dac101904f1ebd63e4a09b47c64))
-   update dependency com.google.cloud:google-cloud-shared-dependencies to v2.7.0 ([#&#8203;728](https://togithub.com/googleapis/java-spanner-jdbc/issues/728)) ([b0a32d8](https://togithub.com/googleapis/java-spanner-jdbc/commit/b0a32d807cdf2458b60437ade38fa46511254701))
-   update opencensus.version to v0.31.0 ([#&#8203;727](https://togithub.com/googleapis/java-spanner-jdbc/issues/727)) ([fce0770](https://togithub.com/googleapis/java-spanner-jdbc/commit/fce077056fbf55395a736dc1f58f8ecbc89eb10d))

##### [2.5.8](https://www.github.com/googleapis/java-spanner-jdbc/compare/v2.5.7...v2.5.8) (2022-01-07)

##### Dependencies

-   update dependency com.google.cloud:google-cloud-spanner-bom to v6.17.4 ([#&#8203;709](https://www.togithub.com/googleapis/java-spanner-jdbc/issues/709)) ([bd12d7c](https://www.github.com/googleapis/java-spanner-jdbc/commit/bd12d7c33b18ceb1df417df8e275ffa745b195b2))

##### [2.5.7](https://www.github.com/googleapis/java-spanner-jdbc/compare/v2.5.6...v2.5.7) (2022-01-07)

##### Dependencies

-   update dependency com.google.cloud:google-cloud-shared-dependencies to v2.6.0 ([#&#8203;704](https://www.togithub.com/googleapis/java-spanner-jdbc/issues/704)) ([bae659c](https://www.github.com/googleapis/java-spanner-jdbc/commit/bae659cac5a010c17767cdf4b3569e654efb605c))

##### [2.5.6](https://www.github.com/googleapis/java-spanner-jdbc/compare/v2.5.5...v2.5.6) (2021-12-17)

##### Bug Fixes

-   **java:** add -ntp flag to native image testing command ([#&#8203;1299](https://www.togithub.com/googleapis/java-spanner-jdbc/issues/1299)) ([#&#8203;688](https://www.togithub.com/googleapis/java-spanner-jdbc/issues/688)) ([4438aca](https://www.github.com/googleapis/java-spanner-jdbc/commit/4438aca73b9c8b33fa1edd23f823d87a093a6d59))

##### Dependencies

-   update OpenCensus API to 0.30.0 ([#&#8203;694](https://www.togithub.com/googleapis/java-spanner-jdbc/issues/694)) ([345f136](https://www.github.com/googleapis/java-spanner-jdbc/commit/345f1366a7dd96f3b28afd353c5c23ebeff60c6b))

##### [2.5.5](https://www.github.com/googleapis/java-spanner-jdbc/compare/v2.5.4...v2.5.5) (2021-12-03)

##### Dependencies

-   update dependency com.google.cloud:google-cloud-shared-dependencies to v2.5.1 ([#&#8203;684](https://www.togithub.com/googleapis/java-spanner-jdbc/issues/684)) ([a2582d3](https://www.github.com/googleapis/java-spanner-jdbc/commit/a2582d3fbd3f0ea093477914e3a09af235e76595))

##### [2.5.4](https://www.github.com/googleapis/java-spanner-jdbc/compare/v2.5.3...v2.5.4) (2021-11-17)

##### Dependencies

-   update dependency com.google.cloud:google-cloud-spanner-bom to v6.16.0 ([#&#8203;673](https://www.togithub.com/googleapis/java-spanner-jdbc/issues/673)) ([b4cc056](https://www.github.com/googleapis/java-spanner-jdbc/commit/b4cc0568e440b6a377cb4d8224c46057cd3ce1ee))

##### [2.5.3](https://www.github.com/googleapis/java-spanner-jdbc/compare/v2.5.2...v2.5.3) (2021-11-15)

##### Dependencies

-   update dependency com.google.cloud:google-cloud-shared-dependencies to v2.5.0 ([#&#8203;668](https://www.togithub.com/googleapis/java-spanner-jdbc/issues/668)) ([d453234](https://www.github.com/googleapis/java-spanner-jdbc/commit/d45323445d3e4a0753bed6cfe858fa891bca468e))

##### [2.5.2](https://www.github.com/googleapis/java-spanner-jdbc/compare/v2.5.1...v2.5.2) (2021-11-11)

##### Dependencies

-   update dependency com.google.cloud:google-cloud-spanner-bom to v6.15.2 ([#&#8203;664](https://www.togithub.com/googleapis/java-spanner-jdbc/issues/664)) ([9f22c33](https://www.github.com/googleapis/java-spanner-jdbc/commit/9f22c331ee4c7340ed6f1b9f91a44ce1e4c5b792))

##### [2.5.1](https://www.github.com/googleapis/java-spanner-jdbc/compare/v2.5.0...v2.5.1) (2021-10-27)

##### Dependencies

-   update dependency com.google.cloud:google-cloud-spanner-bom to v6.15.1 ([#&#8203;652](https://www.togithub.com/googleapis/java-spanner-jdbc/issues/652)) ([37d42d9](https://www.github.com/googleapis/java-spanner-jdbc/commit/37d42d91e49da9d30ca0d06b6a01bbe918fc3ab6))

</details>

---

### Configuration

📅 **Schedule**: At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox.

---

This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/java-spanner-jdbc).
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. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Attempting to read from a non-existent database can create many distinct client IDs in the session metrics
4 participants