Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
13d2aac
repro-the-version-issue
danieljbruce Jan 6, 2026
3f60800
Get the version number from the relative path
danieljbruce Jan 6, 2026
6b47a43
get rid of the experimental code
danieljbruce Jan 6, 2026
f602351
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Jan 6, 2026
2b92ff8
sample test for node version number
danieljbruce Jan 6, 2026
936d8e7
Don’t compare snapshot for this test
danieljbruce Jan 6, 2026
eef51a9
Try the readSnippets code
danieljbruce Jan 6, 2026
2d62430
Remove only
danieljbruce Jan 6, 2026
142b6dc
put all imports in one place
danieljbruce Jan 6, 2026
12c17c5
Remove TODO
danieljbruce Jan 6, 2026
6862358
remove comments
danieljbruce Jan 6, 2026
764dd1b
Better logging for the test
danieljbruce Jan 6, 2026
440cbcc
Merge branch '467064670-fix-csm-details-with-version-test' of https:/…
danieljbruce Jan 6, 2026
81c0ce4
Add a unit test that simulates customer code
danieljbruce Jan 7, 2026
7a3b4d0
Remove the readSnippets script
danieljbruce Jan 7, 2026
7a13296
Remove samples test
danieljbruce Jan 7, 2026
68d1a4a
Remove only
danieljbruce Jan 7, 2026
6a89733
Remove console log
danieljbruce Jan 7, 2026
83fdb81
Simplify source file change fetching version
danieljbruce Jan 7, 2026
2286df2
Add license headers
danieljbruce Jan 7, 2026
2699bdb
change header years
danieljbruce Jan 7, 2026
bcde448
clean environment
danieljbruce Jan 7, 2026
786f17d
Fix inline linting issues
danieljbruce Jan 7, 2026
ac90887
Add some logging
danieljbruce Jan 7, 2026
3ddf5a5
console logs for version tests
danieljbruce Jan 7, 2026
67f47c0
try commenting out the error throwing
danieljbruce Jan 7, 2026
342aec2
just run the version test
danieljbruce Jan 7, 2026
dff3112
skip more tests to get faster feedback
danieljbruce Jan 7, 2026
469175d
Add a comment
danieljbruce Jan 8, 2026
5688f36
remove skip
danieljbruce Jan 8, 2026
8a749e4
Revert "remove skip"
danieljbruce Jan 8, 2026
4c04108
Print the output buffer as a string
danieljbruce Jan 8, 2026
dac0807
inline the test metrics handler
danieljbruce Jan 8, 2026
713f132
Add requests handled property
danieljbruce Jan 8, 2026
bc04cb8
correct the console log statement
danieljbruce Jan 8, 2026
e9c8629
Logging messages for entering the methods
danieljbruce Jan 8, 2026
503353b
print the handlers
danieljbruce Jan 8, 2026
61c4bbb
metrics collector constructor code
danieljbruce Jan 8, 2026
29c2006
Add another log to the metrics collector
danieljbruce Jan 8, 2026
7a4726d
log the metrics handler actually being used
danieljbruce Jan 8, 2026
452b697
more specific logging
danieljbruce Jan 8, 2026
1a04a82
move class
danieljbruce Jan 8, 2026
06b4f37
Merge branch 'main' into 467064670-fix-csm-details-with-path-fix
danieljbruce Jan 8, 2026
a55b1a5
remove console logs
danieljbruce Jan 8, 2026
daa0032
Remove unnecessary message
danieljbruce Jan 8, 2026
f4a2a12
Remove additional investigation changes
danieljbruce Jan 8, 2026
1872716
Merge branch '467064670-fix-csm-details-with-path-fix' of https://git…
danieljbruce Jan 8, 2026
c556cb5
try fixing the linting issue
danieljbruce Jan 8, 2026
64ccf9a
Move these files into their own directory
danieljbruce Jan 8, 2026
a277b1b
Need to change version path
danieljbruce Jan 8, 2026
6e8fea3
Remove only and fix bugs
danieljbruce Jan 8, 2026
e262340
Eliminate TestMetricsHandlerKeepName class
danieljbruce Jan 8, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/client-side-metrics/operation-metrics-collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ export interface ITabularApiSurface {
};
}

const packageJSON = fs.readFileSync('package.json');
const version = JSON.parse(packageJSON.toString()).version;
const {version} = require('../../../package.json');

// MetricsCollectorState is a list of states that the metrics collector can be in.
// Tracking the OperationMetricsCollector state is done so that the
Expand Down
85 changes: 85 additions & 0 deletions test/metrics-collector/version/get-version-script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

const path = require('path');
const fs = require('fs');
const {
ClientSideMetricsConfigManager,
} = require('../../../build/src/client-side-metrics/metrics-config-manager.js'); // eslint-disable-line
const {Bigtable} = require('../../../build/src'); // eslint-disable-line

async function main() {
/**
* A test implementation of the IMetricsHandler interface. Used for testing purposes.
* It logs the metrics and attributes received by the onOperationComplete and onAttemptComplete methods.
* Doesn't replace the name of the client like the other testing class.
*/
class TestMetricsHandlerKeepName {
constructor() {
this.messages = {value: ''};
this.projectId = 'projectId';
this.requestsHandled = [];
}
/**
* Logs the metrics and attributes received for an operation completion.
* @param {OnOperationCompleteData} data Metrics related to the completed operation.
*/
onOperationComplete(data) {
const dataWithProject = Object.assign({projectId: this.projectId}, data);
this.requestsHandled.push(dataWithProject);
this.messages.value += 'Recording parameters for onOperationComplete:\n';
this.messages.value += `${JSON.stringify(dataWithProject)}\n`;
}

/**
* Logs the metrics and attributes received for an attempt completion.
* @param {OnOperationCompleteData} data Metrics related to the completed attempt.
*/
onAttemptComplete(data) {
const dataWithProject = Object.assign({projectId: this.projectId}, data);
this.requestsHandled.push(dataWithProject);
this.messages.value += 'Recording parameters for onAttemptComplete:\n';
this.messages.value += `${JSON.stringify(dataWithProject)}\n`;
}
}

const packagePath = path.join(__dirname, '../../../package.json');

// Read the file using the absolute path
const packageJSON = fs.readFileSync(packagePath);
const expectedVersion = JSON.parse(packageJSON.toString()).version;

const fakeBigtable = new Bigtable();
const testMetricsHandler = new TestMetricsHandlerKeepName();
fakeBigtable._metricsConfigManager = new ClientSideMetricsConfigManager([
testMetricsHandler,
]);

const instance = fakeBigtable.instance('fake-instance-id');
const table = instance.table('fake-table-id');
try {
await table.getRows();
} catch (e) {
// Suppress the error.
// We just made this call so that the test metrics handler would
// collect grpc response data.
}
if (
testMetricsHandler.requestsHandled[0].client_name !==
`nodejs-bigtable/${expectedVersion}`
) {
throw Error('The wrong version is being recorded');
}
}
main();
7 changes: 7 additions & 0 deletions test/metrics-collector/version/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"version": "fake-version-number",
"private": true,
"engines": {
"node": ">=18"
}
}
23 changes: 23 additions & 0 deletions test/metrics-collector/version/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// eslint-disable-next-line n/no-extraneous-import
import {describe} from 'mocha';
import {execSync} from 'node:child_process';

describe('Bigtable/CSMVersion', () => {
it('Fetches the right client side metrics version', async () => {
execSync('cd test/metrics-collector/version && node get-version-script');
});
});
Loading