Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.

Commit 9fb51dc

Browse files
committed
Pass in metrics collector
1 parent 0ce87af commit 9fb51dc

4 files changed

Lines changed: 61 additions & 35 deletions

File tree

src/row.ts

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ import {google} from '../protos/protos';
3232
import {RowDataUtils, RowProperties} from './row-data-utils';
3333
import {TabularApiSurface} from './tabular-api-surface';
3434
import {getRowsInternal} from './utils/getRowsInternal';
35+
import {
36+
MethodName,
37+
StreamingState,
38+
} from './client-side-metrics/client-side-metrics-attributes';
3539

3640
export interface Rule {
3741
column: string;
@@ -667,31 +671,42 @@ export class Row {
667671
filter,
668672
});
669673

670-
void getRowsInternal(this.table, true, getRowsOptions, (err, rows) => {
671-
if (err) {
672-
callback(err);
673-
return;
674-
}
674+
const metricsCollector =
675+
this.table.bigtable._metricsConfigManager.createOperation(
676+
MethodName.READ_ROW,
677+
StreamingState.UNARY,
678+
this.table,
679+
);
680+
void getRowsInternal(
681+
this.table,
682+
metricsCollector,
683+
getRowsOptions,
684+
(err, rows) => {
685+
if (err) {
686+
callback(err);
687+
return;
688+
}
675689

676-
const row = rows![0];
690+
const row = rows![0];
677691

678-
if (!row) {
679-
const e = new RowError(this.id);
680-
callback(e);
681-
return;
682-
}
692+
if (!row) {
693+
const e = new RowError(this.id);
694+
callback(e);
695+
return;
696+
}
683697

684-
this.data = row.data;
698+
this.data = row.data;
685699

686-
// If the user specifies column names, we'll return back the row data
687-
// we received. Otherwise, we'll return the row "this" in a typical
688-
// GrpcServiceObject#get fashion.
689-
if (columns.length > 0) {
690-
callback(null, row.data);
691-
} else {
692-
(callback as {} as GetRowCallback<Row>)(null, this);
693-
}
694-
});
700+
// If the user specifies column names, we'll return back the row data
701+
// we received. Otherwise, we'll return the row "this" in a typical
702+
// GrpcServiceObject#get fashion.
703+
if (columns.length > 0) {
704+
callback(null, row.data);
705+
} else {
706+
(callback as {} as GetRowCallback<Row>)(null, this);
707+
}
708+
},
709+
);
695710
}
696711

697712
getMetadata(options?: GetRowOptions): Promise<GetRowMetadataResponse>;

src/tabular-api-surface.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ import * as is from 'is';
3333
import {GoogleInnerError} from './table';
3434
import {createReadStreamInternal} from './utils/createReadStreamInternal';
3535
import {getRowsInternal} from './utils/getRowsInternal';
36+
import {
37+
MethodName,
38+
StreamingState,
39+
} from './client-side-metrics/client-side-metrics-attributes';
3640

3741
// See protos/google/rpc/code.proto
3842
// (4=DEADLINE_EXCEEDED, 8=RESOURCE_EXHAUSTED, 10=ABORTED, 14=UNAVAILABLE)
@@ -206,7 +210,13 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.`);
206210
* @param opts
207211
*/
208212
createReadStream(opts?: GetRowsOptions) {
209-
return createReadStreamInternal(this, false, opts);
213+
const metricsCollector =
214+
this.bigtable._metricsConfigManager.createOperation(
215+
MethodName.READ_ROWS,
216+
StreamingState.STREAMING,
217+
this,
218+
);
219+
return createReadStreamInternal(this, metricsCollector, opts);
210220
}
211221

212222
getRows(options?: GetRowsOptions): Promise<GetRowsResponse>;
@@ -234,7 +244,13 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.`);
234244
optionsOrCallback?: GetRowsOptions | GetRowsCallback,
235245
cb?: GetRowsCallback,
236246
): void | Promise<GetRowsResponse> {
237-
return getRowsInternal(this, false, optionsOrCallback, cb);
247+
const metricsCollector =
248+
this.bigtable._metricsConfigManager.createOperation(
249+
MethodName.READ_ROWS,
250+
StreamingState.STREAMING,
251+
this,
252+
);
253+
return getRowsInternal(this, metricsCollector, optionsOrCallback, cb);
238254
}
239255

240256
insert(

src/utils/createReadStreamInternal.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import {
4141
RETRYABLE_STATUS_CODES,
4242
TabularApiSurface,
4343
} from '../tabular-api-surface';
44+
import {OperationMetricsCollector} from '../client-side-metrics/operation-metrics-collector';
4445

4546
/**
4647
* Creates a readable stream of rows from a Bigtable table or authorized view.
@@ -50,7 +51,7 @@ import {
5051
* be used to create a stream for either a whole table or an authorized view.
5152
*
5253
* @param {Table} table The Table instance to read rows from.
53-
* @param {boolean} singleRow boolean to check if the request is for a single row.
54+
* @param metricsCollector
5455
* @param {GetRowsOptions} [opts] Optional configuration for the read operation.
5556
* @param {boolean} [opts.decode=true] If set to `false` it will not decode
5657
* Buffer values returned from Bigtable.
@@ -68,13 +69,12 @@ import {
6869
* match.
6970
* @param {object[]} [opts.ranges] A list of key ranges.
7071
* @param {string} [opts.start] Start value for key range.
71-
* @param {string} [viewName] The name of the authorized view, if applicable.
7272
* @returns {stream} A readable stream of {@link Row} objects.
7373
*
7474
*/
7575
export function createReadStreamInternal(
7676
table: TabularApiSurface,
77-
singleRow: boolean,
77+
metricsCollector: OperationMetricsCollector,
7878
opts?: GetRowsOptions,
7979
) {
8080
const options = opts || {};
@@ -201,11 +201,6 @@ export function createReadStreamInternal(
201201
}
202202
return originalEnd(chunk, encoding, cb);
203203
};
204-
const metricsCollector = table.bigtable._metricsConfigManager.createOperation(
205-
singleRow ? MethodName.READ_ROW : MethodName.READ_ROWS,
206-
singleRow ? StreamingState.UNARY : StreamingState.STREAMING,
207-
table,
208-
);
209204
metricsCollector.onOperationStart();
210205
const makeNewRequest = () => {
211206
metricsCollector.onAttemptStart();

src/utils/getRowsInternal.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
} from '../tabular-api-surface';
2121
import {createReadStreamInternal} from './createReadStreamInternal';
2222
import {Row} from '../row';
23+
import {OperationMetricsCollector} from '../client-side-metrics/operation-metrics-collector';
2324
// eslint-disable-next-line @typescript-eslint/no-var-requires
2425
const concat = require('concat-stream');
2526

@@ -31,8 +32,7 @@ const concat = require('concat-stream');
3132
* via {@link Table#createReadStream}.
3233
*
3334
* @param {TabularApiSurface} table The table instance to get rows from.
34-
* @param {boolean} singleRow Boolean to check if the request is for a single row.
35-
* @param {string} [viewName] The name of the authorized view, if applicable.
35+
* @param metricsCollector
3636
* @param {object} [optionsOrCallback] Configuration object. See
3737
* {@link Table#createReadStream} for a complete list of options.
3838
* @param {object} [optionsOrCallback.gaxOptions] Request configuration options, outlined
@@ -48,15 +48,15 @@ const concat = require('concat-stream');
4848
*/
4949
export function getRowsInternal(
5050
table: TabularApiSurface,
51-
singleRow: boolean,
51+
metricsCollector: OperationMetricsCollector,
5252
optionsOrCallback?: GetRowsOptions | GetRowsCallback,
5353
cb?: GetRowsCallback,
5454
): void | Promise<GetRowsResponse> {
5555
const callback =
5656
typeof optionsOrCallback === 'function' ? optionsOrCallback : cb!;
5757
const options =
5858
typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
59-
createReadStreamInternal(table, singleRow, options)
59+
createReadStreamInternal(table, metricsCollector, options)
6060
.on('error', callback)
6161
.pipe(
6262
concat((rows: Row[]) => {

0 commit comments

Comments
 (0)