Skip to content
Merged
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
95 changes: 50 additions & 45 deletions system-test/client-side-metrics-all-methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,14 @@ import {ClientOptions} from 'google-gax';
import {ClientSideMetricsConfigManager} from '../src/client-side-metrics/metrics-config-manager';
import {MetricServiceClient} from '@google-cloud/monitoring';
import {MethodName} from '../src/client-side-metrics/client-side-metrics-attributes';
import {generateId} from './common';

const SECOND_PROJECT_ID = 'cfdb-sdk-node-tests';
const instanceId1 = generateId('instance');
const instanceId2 = generateId('instance');
const tableId1 = 'my-table';
const tableId2 = 'my-table2';
const columnFamilyId = 'cf1';

function getFakeBigtable(
projectId: string,
Expand Down Expand Up @@ -107,7 +113,7 @@ function readRowsAssertionCheck(
status: '0',
client_name: 'nodejs-bigtable',
metricsCollectorData: {
instanceId: 'emulator-test-instance',
instanceId: instanceId1,
table: 'my-table',
cluster: 'fake-cluster3',
zone: 'us-west1-c',
Expand All @@ -129,7 +135,7 @@ function readRowsAssertionCheck(
streaming,
client_name: 'nodejs-bigtable',
metricsCollectorData: {
instanceId: 'emulator-test-instance',
instanceId: instanceId1,
cluster: 'fake-cluster3',
zone: 'us-west1-c',
method,
Expand All @@ -152,7 +158,7 @@ function readRowsAssertionCheck(
status: '0',
client_name: 'nodejs-bigtable',
metricsCollectorData: {
instanceId: 'emulator-test-instance',
instanceId: instanceId1,
table: 'my-table2',
cluster: 'fake-cluster3',
zone: 'us-west1-c',
Expand All @@ -174,7 +180,7 @@ function readRowsAssertionCheck(
streaming,
client_name: 'nodejs-bigtable',
metricsCollectorData: {
instanceId: 'emulator-test-instance',
instanceId: instanceId1,
cluster: 'fake-cluster3',
zone: 'us-west1-c',
method,
Expand Down Expand Up @@ -311,54 +317,53 @@ async function checkForPublishedMetrics(projectId: string) {
}
}

describe('Bigtable/ClientSideMetrics', () => {
const instanceId1 = 'emulator-test-instance';
const instanceId2 = 'emulator-test-instance2';
const tableId1 = 'my-table';
const tableId2 = 'my-table2';
const columnFamilyId = 'cf1';
describe('Bigtable/ClientSideMetricsAllMethods', () => {
let defaultProjectId: string;

before(async () => {
const bigtable = new Bigtable();
// For easier debugging, don't include metrics handlers in the config
// manager. This helps us step through the metrics handler for an individual
// test more easily.
bigtable._metricsConfigManager = new ClientSideMetricsConfigManager([]);
for (const instanceId of [instanceId1, instanceId2]) {
await setupBigtableWithInsert(bigtable, columnFamilyId, instanceId, [
tableId1,
tableId2,
]);
}
defaultProjectId = await new Promise((resolve, reject) => {
bigtable.getProjectId_((err: Error | null, projectId?: string) => {
if (err) {
reject(err);
} else {
resolve(projectId as string);
}
for (const bigtable of [
new Bigtable(),
new Bigtable({projectId: SECOND_PROJECT_ID}),
]) {
for (const instanceId of [instanceId1, instanceId2]) {
await setupBigtableWithInsert(bigtable, columnFamilyId, instanceId, [
tableId1,
tableId2,
]);
}
defaultProjectId = await new Promise((resolve, reject) => {
bigtable.getProjectId_((err: Error | null, projectId?: string) => {
if (err) {
reject(err);
} else {
resolve(projectId as string);
}
});
});
});
}
});

after(async () => {
const bigtable = new Bigtable();
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(instanceId1);
await instance.delete({});
} catch (e) {
console.warn('The instance has been deleted already');
}
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(instanceId2);
await instance.delete({});
} catch (e) {
console.warn('The instance has been deleted already');
for (const bigtable of [
new Bigtable(),
new Bigtable({projectId: SECOND_PROJECT_ID}),
]) {
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(instanceId1);
await instance.delete({});
} catch (e) {
console.warn('The instance has been deleted already');
}
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(instanceId2);
await instance.delete({});
} catch (e) {
console.warn('The instance has been deleted already');
}
}
});

Expand Down
114 changes: 61 additions & 53 deletions system-test/client-side-metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,14 @@ import {PassThrough} from 'stream';
import {generateChunksFromRequest} from '../test-common/utils/readRowsImpl';
import {TabularApiSurface} from '../src/tabular-api-surface';
import {MetricServiceClient} from '@google-cloud/monitoring';
import {ClientSideMetricsConfigManager} from '../src/client-side-metrics/metrics-config-manager';
import {generateId} from './common';

const SECOND_PROJECT_ID = 'cfdb-sdk-node-tests';
const instanceId1 = generateId('instance');
const instanceId2 = generateId('instance');
const tableId1 = 'my-table';
const tableId2 = 'my-table2';
const columnFamilyId = 'cf1';

class FakeHRTime {
startTime = BigInt(0);
Expand Down Expand Up @@ -174,7 +179,7 @@ function readRowsAssertionCheck(
status: '0',
client_name: 'nodejs-bigtable',
metricsCollectorData: {
instanceId: 'emulator-test-instance',
instanceId: instanceId1,
table: 'my-table',
cluster: 'fake-cluster3',
zone: 'us-west1-c',
Expand All @@ -197,7 +202,7 @@ function readRowsAssertionCheck(
streaming,
client_name: 'nodejs-bigtable',
metricsCollectorData: {
instanceId: 'emulator-test-instance',
instanceId: instanceId1,
cluster: 'fake-cluster3',
zone: 'us-west1-c',
method,
Expand All @@ -220,7 +225,7 @@ function readRowsAssertionCheck(
status: '0',
client_name: 'nodejs-bigtable',
metricsCollectorData: {
instanceId: 'emulator-test-instance',
instanceId: instanceId1,
table: 'my-table2',
cluster: 'fake-cluster3',
zone: 'us-west1-c',
Expand All @@ -243,7 +248,7 @@ function readRowsAssertionCheck(
streaming,
client_name: 'nodejs-bigtable',
metricsCollectorData: {
instanceId: 'emulator-test-instance',
instanceId: instanceId1,
cluster: 'fake-cluster3',
zone: 'us-west1-c',
method,
Expand Down Expand Up @@ -326,49 +331,52 @@ async function checkForPublishedMetrics(projectId: string) {
}

describe('Bigtable/ClientSideMetrics', () => {
const instanceId1 = 'emulator-test-instance';
const instanceId2 = 'emulator-test-instance2';
const tableId1 = 'my-table';
const tableId2 = 'my-table2';
const columnFamilyId = 'cf1';
let defaultProjectId: string;

before(async () => {
const bigtable = new Bigtable();
for (const instanceId of [instanceId1, instanceId2]) {
await setupBigtableWithInsert(bigtable, columnFamilyId, instanceId, [
tableId1,
tableId2,
]);
}
defaultProjectId = await new Promise((resolve, reject) => {
bigtable.getProjectId_((err: Error | null, projectId?: string) => {
if (err) {
reject(err);
} else {
resolve(projectId as string);
}
for (const bigtable of [
new Bigtable(),
new Bigtable({projectId: SECOND_PROJECT_ID}),
]) {
for (const instanceId of [instanceId1, instanceId2]) {
await setupBigtableWithInsert(bigtable, columnFamilyId, instanceId, [
tableId1,
tableId2,
]);
}
defaultProjectId = await new Promise((resolve, reject) => {
bigtable.getProjectId_((err: Error | null, projectId?: string) => {
if (err) {
reject(err);
} else {
resolve(projectId as string);
}
});
});
});
}
});

after(async () => {
const bigtable = new Bigtable();
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(instanceId1);
await instance.delete({});
} catch (e) {
console.warn('The instance has been deleted already');
}
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(instanceId2);
await instance.delete({});
} catch (e) {
console.warn('The instance has been deleted already');
for (const bigtable of [
new Bigtable(),
new Bigtable({projectId: SECOND_PROJECT_ID}),
]) {
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(instanceId1);
await instance.delete({});
} catch (e) {
console.warn('The instance has been deleted already');
}
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(instanceId2);
await instance.delete({});
} catch (e) {
console.warn('The instance has been deleted already');
}
}
});

Expand Down Expand Up @@ -706,7 +714,7 @@ describe('Bigtable/ClientSideMetrics', () => {
status: '0',
client_name: 'nodejs-bigtable',
metricsCollectorData: {
instanceId: 'emulator-test-instance',
instanceId: instanceId1,
table: 'my-table',
cluster: 'fake-cluster3',
zone: 'us-west1-c',
Expand All @@ -729,7 +737,7 @@ describe('Bigtable/ClientSideMetrics', () => {
streaming: 'true',
client_name: 'nodejs-bigtable',
metricsCollectorData: {
instanceId: 'emulator-test-instance',
instanceId: instanceId1,
cluster: 'fake-cluster3',
zone: 'us-west1-c',
method: 'Bigtable.ReadRows',
Expand All @@ -752,7 +760,7 @@ describe('Bigtable/ClientSideMetrics', () => {
status: '0',
client_name: 'nodejs-bigtable',
metricsCollectorData: {
instanceId: 'emulator-test-instance',
instanceId: instanceId1,
table: 'my-table2',
cluster: 'fake-cluster3',
zone: 'us-west1-c',
Expand All @@ -775,7 +783,7 @@ describe('Bigtable/ClientSideMetrics', () => {
streaming: 'true',
client_name: 'nodejs-bigtable',
metricsCollectorData: {
instanceId: 'emulator-test-instance',
instanceId: instanceId1,
cluster: 'fake-cluster3',
zone: 'us-west1-c',
method: 'Bigtable.ReadRows',
Expand Down Expand Up @@ -808,7 +816,7 @@ describe('Bigtable/ClientSideMetrics', () => {
status: '0',
client_name: 'nodejs-bigtable',
metricsCollectorData: {
instanceId: 'emulator-test-instance',
instanceId: instanceId1,
table: 'my-table',
cluster: '<unspecified>',
zone: 'global',
Expand All @@ -820,7 +828,7 @@ describe('Bigtable/ClientSideMetrics', () => {
status: '0',
streaming: 'true',
metricsCollectorData: {
instanceId: 'emulator-test-instance',
instanceId: instanceId1,
table: 'my-table',
cluster: '<unspecified>',
zone: 'global',
Expand All @@ -841,7 +849,7 @@ describe('Bigtable/ClientSideMetrics', () => {
status: '0',
client_name: 'nodejs-bigtable',
metricsCollectorData: {
instanceId: 'emulator-test-instance',
instanceId: instanceId1,
table: 'my-table2',
cluster: '<unspecified>',
zone: 'global',
Expand All @@ -853,7 +861,7 @@ describe('Bigtable/ClientSideMetrics', () => {
status: '0',
streaming: 'true',
metricsCollectorData: {
instanceId: 'emulator-test-instance',
instanceId: instanceId1,
table: 'my-table2',
cluster: '<unspecified>',
zone: 'global',
Expand Down Expand Up @@ -891,7 +899,7 @@ describe('Bigtable/ClientSideMetrics', () => {
status: '0',
client_name: 'nodejs-bigtable',
metricsCollectorData: {
instanceId: 'emulator-test-instance',
instanceId: instanceId1,
table: 'my-table',
cluster: '<unspecified>',
zone: 'global',
Expand All @@ -903,7 +911,7 @@ describe('Bigtable/ClientSideMetrics', () => {
status: '0',
streaming: 'true',
metricsCollectorData: {
instanceId: 'emulator-test-instance',
instanceId: instanceId1,
table: 'my-table',
cluster: '<unspecified>',
zone: 'global',
Expand All @@ -924,7 +932,7 @@ describe('Bigtable/ClientSideMetrics', () => {
status: '0',
client_name: 'nodejs-bigtable',
metricsCollectorData: {
instanceId: 'emulator-test-instance',
instanceId: instanceId1,
table: 'my-table2',
cluster: '<unspecified>',
zone: 'global',
Expand All @@ -936,7 +944,7 @@ describe('Bigtable/ClientSideMetrics', () => {
status: '0',
streaming: 'true',
metricsCollectorData: {
instanceId: 'emulator-test-instance',
instanceId: instanceId1,
table: 'my-table2',
cluster: '<unspecified>',
zone: 'global',
Expand Down
Loading