Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 7 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@
* Internal only.
*/
BigtableTableAdminClient?: gax.ClientOptions;

universeDomain?: string;
}

/**
Expand All @@ -111,8 +113,8 @@
* @param {gax.ClientOptions} [opts] The gax client options
* @returns {string} The universe domain.
*/
function getDomain(prefix: string, opts?: gax.ClientOptions) {
function getDomain(prefix: string, options: BigtableOptions, opts?: gax.ClientOptions) {
// From https://github.com/googleapis/nodejs-bigtable/blob/589540475b0b2a055018a1cb6e475800fdd46a37/src/v2/bigtable_client.ts#L120-L128.

Check failure on line 117 in src/index.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `prefix:·string,·options:·BigtableOptions,·opts?:·gax.ClientOptions` with `⏎··prefix:·string,⏎··options:·BigtableOptions,⏎··opts?:·gax.ClientOptions,⏎`
// This code for universe domain was taken from the Gapic Layer.
// It is reused here to build the service path.
const universeDomainEnvVar =
Expand All @@ -120,6 +122,7 @@
? process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']
: undefined;
return `${prefix}.${
options?.universeDomain ??
opts?.universeDomain ??
opts?.universe_domain ??
universeDomainEnvVar ??
Expand Down Expand Up @@ -469,7 +472,7 @@
{
servicePath:
customEndpointBaseUrl ||
getDomain('bigtable', options.BigtableClient),
getDomain('bigtable', options, options.BigtableClient),
'grpc.callInvocationTransformer': grpcGcp.gcpCallInvocationTransformer,
'grpc.channelFactoryOverride': grpcGcp.gcpChannelFactoryOverride,
'grpc.gcpApiConfig': grpcGcp.createGcpApiConfig({
Expand All @@ -490,7 +493,7 @@
{
servicePath:
customEndpointBaseUrl ||
getDomain('bigtableadmin', options.BigtableClient),
getDomain('bigtableadmin', options, options.BigtableClient),
},
options
);
Expand All @@ -500,7 +503,7 @@
{
servicePath:
customEndpointBaseUrl ||
getDomain('bigtableadmin', options.BigtableClient),
getDomain('bigtableadmin', options, options.BigtableClient),
},
options
);
Expand Down
2 changes: 1 addition & 1 deletion src/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1310,7 +1310,7 @@ Please use the format 'my-instance' or '${bigtable.projectName}/instances/my-ins
: callback!;

if (policy.etag !== null && policy.etag !== undefined) {
(policy.etag as {} as Buffer) = Buffer.from(policy.etag);
(policy.etag as {} as Buffer) = Buffer.from(policy.etag as string);
}
const reqOpts = {
resource: this.name,
Expand Down
2 changes: 1 addition & 1 deletion src/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@ export class Table extends TabularApiSurface {
: callback!;

if (policy.etag !== null && policy.etag !== undefined) {
(policy.etag as {} as Buffer) = Buffer.from(policy.etag);
(policy.etag as {} as Buffer) = Buffer.from(policy.etag as string);
}
const reqOpts = {
resource: this.name,
Expand Down
55 changes: 55 additions & 0 deletions system-test/service-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,58 @@ describe('Service Path', () => {
delete process.env.GOOGLE_CLOUD_UNIVERSE_DOMAIN;
});
});

describe('Service Path2', () => {
it('Experiment with setting the service path', async () => {
const instanceId = 'instanceId';
const tableId = 'tableId';
const columnFamilyId = 'cf1';
async function mockBigtable() {
const instance = bigtable.instance(instanceId);
console.log('get instance info');
const [instanceInfo] = await instance.exists();
console.log('after instance info');
if (!instanceInfo) {
console.log('create instance');
const [, operation] = await instance.create({
clusters: [
{
id: 'fake-cluster3',
location: 'us-west1-c',
nodes: 1,
},
],
});
console.log('create instance done');
await operation.promise();
}

const table = instance.table(tableId);
const [tableExists] = await table.exists();
if (!tableExists) {
await table.create({families: [columnFamilyId]}); // Create column family
} else {
// Check if column family exists and create it if not.
const [families] = await table.getFamilies();
if (
!families.some((family: {id: string}) => family.id === columnFamilyId)
) {
await table.createFamily(columnFamilyId);
}
}
}
// Do the universe domain test
const universeDomain = 'apis-tpczero.goog'; // or your universe domain if not using emulator
/*
const options = {
universeDomain,
};
*/
const options = {};
const bigtable = new Bigtable();
const instance = bigtable.instance(instanceId);
const table = instance.table(tableId);
await mockBigtable();
await table.getRows();
});
});
94 changes: 94 additions & 0 deletions system-test/universe-domain-tests-working.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// Copyright 2025 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
//
// http://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.

import {describe, it, before, after} from 'mocha';
import {Bigtable} from '../src';
import * as proxyquire from 'proxyquire';
import * as mocha from 'mocha';

describe.only('Bigtable/ClientSideMetricsToMetricsHandler', () => {

Check failure on line 20 in system-test/universe-domain-tests-working.ts

View workflow job for this annotation

GitHub Actions / lint

'describe.only' is restricted from being used
async function mockBigtable() {
const instance = bigtable.instance(instanceId);
const [instanceInfo] = await instance.exists();
console.log('after exists');
if (!instanceInfo) {
const [, operation] = await instance.create({
clusters: {
id: 'fake-cluster3',
location: 'u-us-prp1-a',
nodes: 1,
},
});
await operation.promise();
}

const table = instance.table(tableId);
const [tableExists] = await table.exists();
if (!tableExists) {
await table.create({families: [columnFamilyId]}); // Create column family
} else {
// Check if column family exists and create it if not.
const [families] = await table.getFamilies();

if (
!families.some((family: {id: string}) => family.id === columnFamilyId)
) {
await table.createFamily(columnFamilyId);
}
}
}

const instanceId = 'emulator-test-instance';
const tableId = 'my-table';
const columnFamilyId = 'cf1';
let bigtable: Bigtable;

before(async () => {
// This line is added just to make sure the bigtable variable is assigned.
// It is needed to solve a compile time error in the after hook.
const universeDomain = 'apis-tpczero.goog'; // or your universe domain if not using emulator
const options = {
universeDomain,
};
process.env.GOOGLE_APPLICATION_CREDENTIALS =
'/Users/djbruce/Documents/Programming/keys/tpc_sa_key.json';
bigtable = new Bigtable(options);
});

after(async () => {
try {
// If the instance has been deleted already by another source, we don't
// want this after hook to block the continuous integration pipeline.
const instance = bigtable.instance(instanceId);
await instance.delete({});
} catch (e) {
console.warn('The instance has been deleted already');
}
});

it('should send the metrics to the metrics handler for a ReadRows call', done => {
(async () => {

Check failure on line 81 in system-test/universe-domain-tests-working.ts

View workflow job for this annotation

GitHub Actions / lint

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
try {
const instance = bigtable.instance(instanceId);
const table = instance.table(tableId);
await mockBigtable();
await table.getRows();
console.log('done');
done();
} catch (e) {
done(e);
}
})();
});
});
50 changes: 50 additions & 0 deletions system-test/universe-domain-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import {describe, it} from 'mocha';
import {Bigtable} from '../src';

describe('Service Path2', () => {
it('Experiment with setting the service path', async () => {
const instanceId = 'instanceId';
const tableId = 'tableId';
const columnFamilyId = 'cf1';
async function mockBigtable() {
const instance = bigtable.instance(instanceId);
console.log('get instance info');
const [instanceInfo] = await instance.exists();
console.log('after instance info');
if (!instanceInfo) {
console.log('create instance');
const [, operation] = await instance.create({
clusters: [
{
id: 'fake-cluster3',
location: 'us-west1-c',
nodes: 1,
},
],
});
console.log('create instance done');
await operation.promise();
}

const table = instance.table(tableId);
const [tableExists] = await table.exists();
if (!tableExists) {
await table.create({families: [columnFamilyId]}); // Create column family
} else {
// Check if column family exists and create it if not.
const [families] = await table.getFamilies();
if (
!families.some((family: {id: string}) => family.id === columnFamilyId)
) {
await table.createFamily(columnFamilyId);
}
}
}
// Do the universe domain test
const bigtable = new Bigtable();
const instance = bigtable.instance(instanceId);
const table = instance.table(tableId);
await mockBigtable();
await table.getRows();
});
});
Loading