-
Notifications
You must be signed in to change notification settings - Fork 61
fix: Client side metrics should record the version number of @google-cloud/bigtable not the customer package version #1752
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: Client side metrics should record the version number of @google-cloud/bigtable not the customer package version #1752
Conversation
…/github.com/googleapis/nodejs-bigtable into 467064670-fix-csm-details-with-path-fix
No region tags are edited in this PR.This comment is generated by snippet-bot.
|
I'm a bit confused by this. Region-tagged samples are meant to be pulled into the docs, to show users how to interact with the library. This description, and the sample itself seems more like it's meant to be a unit test? |
|
|
||
| // Read the file using the absolute path | ||
| const packageJSON = fs.readFileSync(packagePath); | ||
| const version = JSON.parse(packageJSON.toString()).version; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gemini says you can do const { version } = require('../../../package.json'); or import { version } from '../../../package.json';
I don't know enough about node to know if that's good advice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. I think this is good so I made the change. It eliminates the fs dependency and it is shorter.
You're intuition is right. The test that was added is meant to be a unit test. We are not adding a new sample here and have no intention of adding a sample to the docs. The main problem with adding a new system-test or unit test is that as you can see in Lines 41 to 44 in 2a96092
That said, maybe the test will fail properly as a unit test if I spawn a subprocess using execSync like the samples tests so I'll give that a try. |
…hub.com/googleapis/nodejs-bigtable into 467064670-fix-csm-details-with-path-fix
Alright. I tried creating a unit test and got it to fail when it should after wrestling with some linting issues and other errors. PTAL @daniel-sanche |
daniel-sanche
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Description
A bug was discovered where the client side metrics being recorded on the backend service had the wrong version number. The version number being recorded actually matched the version number on the customer's package.json file instead of the version number of the Node Bigtable package being used.
To correct this, the line of code at
nodejs-bigtable/src/client-side-metrics/operation-metrics-collector.ts
Line 52 in 2a96092
Impact
Corrects the bug and ensures that the right version number is always recorded for client side metrics.
Files affected
samples/readSnippets: A code snippet that will run in the samples test and fail if the metrics handler receives the wrong version of the client library
samples/test/reads.js: The new samples test that runs the code snippet in readSnippets and fails if the metrics handler receives the wrong version of the client library
src/client-side-metrics/operation-metrics-collector.ts: The source code changes that ensure the version number recorded will always match the Bigtable client library version number
test-common/test-metrics-handler.ts: A new class, similar to the existing class for testing data sent to the metrics handler that also preserves the version name when it reaches the metrics handler
Testing
A new system test or unit test will not catch this bug since their working directories all reference the package.json file in the nodejs-bigtable project. So instead, I created a fake customer project with the script from https://gist.github.com/danieljbruce/bba73fa5d9919866d82b8968ceb45cc3 which gets the wrong version number at
nodejs-bigtable/src/client-side-metrics/operation-metrics-collector.ts
Line 52 in 2a96092
I also found a way to create a samples test which will fail without the source code changes from this PR. It should ensure going forward that the right version gets recorded for client side metrics.