Skip to content

Conversation

@danieljbruce
Copy link
Contributor

@danieljbruce danieljbruce commented Jan 6, 2026

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

const packageJSON = fs.readFileSync('package.json');
which is currently reading the package.json file relative to the working directory of the node process should instead read the package.json file location relative to the location of operation-metrics-collector.ts so that the version number of the Node Bigtable dependency is always recorded instead of the version number from the customer's package.json file.

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

const packageJSON = fs.readFileSync('package.json');
, but gets the right version number when this line of code is corrected with the changes in this PR.

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.

@danieljbruce danieljbruce requested review from a team as code owners January 6, 2026 16:40
@product-auto-label product-auto-label bot added size: xs Pull request size is extra small. api: bigtable Issues related to the googleapis/nodejs-bigtable API. labels Jan 6, 2026
@product-auto-label product-auto-label bot added size: s Pull request size is small. and removed size: xs Pull request size is extra small. labels Jan 6, 2026
@snippet-bot
Copy link

snippet-bot bot commented Jan 6, 2026

No region tags are edited in this PR.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@product-auto-label product-auto-label bot added size: m Pull request size is medium. and removed size: s Pull request size is small. labels Jan 6, 2026
@daniel-sanche
Copy link

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

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;

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

Copy link
Contributor Author

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.

@danieljbruce
Copy link
Contributor Author

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

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?

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

"system-test": "mocha build/system-test --timeout 600000",
"pretest": "npm run compile",
"test": "c8 mocha build/test",
"test:snap": "SNAPSHOT_UPDATE=1 npm test",
, these processes spawn from the root directory of nodejs-bigtable. So this means that even with code before this PR, a system test or unit test will always read the package.json version from package.json file in nodejs-bigtable root and incorrectly produce a passing result when the test should actually fail if simulating customer code correctly.

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.

@danieljbruce
Copy link
Contributor Author

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

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?

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

"system-test": "mocha build/system-test --timeout 600000",
"pretest": "npm run compile",
"test": "c8 mocha build/test",
"test:snap": "SNAPSHOT_UPDATE=1 npm test",

, these processes spawn from the root directory of nodejs-bigtable. So this means that even with code before this PR, a system test or unit test will always read the package.json version from package.json file in nodejs-bigtable root and incorrectly produce a passing result when the test should actually fail if simulating customer code correctly.
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.

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

Copy link

@daniel-sanche daniel-sanche left a comment

Choose a reason for hiding this comment

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

LGTM

@danieljbruce danieljbruce added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jan 9, 2026
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jan 9, 2026
@danieljbruce danieljbruce added the automerge Merge the pull request once unit tests and other checks pass. label Jan 9, 2026
@gcf-merge-on-green gcf-merge-on-green bot merged commit 3e532ab into main Jan 9, 2026
24 checks passed
@gcf-merge-on-green gcf-merge-on-green bot removed the automerge Merge the pull request once unit tests and other checks pass. label Jan 9, 2026
@gcf-merge-on-green gcf-merge-on-green bot deleted the 467064670-fix-csm-details-with-path-fix branch January 9, 2026 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: bigtable Issues related to the googleapis/nodejs-bigtable API. size: m Pull request size is medium.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants