Skip to content

Commit 23298fc

Browse files
committed
Undo transaction-runner changes plus test vestiges for src/transaction-runner.ts
1 parent 13bc9f5 commit 23298fc

File tree

2 files changed

+56
-61
lines changed

2 files changed

+56
-61
lines changed

observability-test/spanner.ts

Lines changed: 50 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ describe('EndToEnd', () => {
453453
const expectedSpanNames = [
454454
'CloudSpanner.Snapshot.runStream',
455455
'CloudSpanner.Snapshot.run',
456+
'CloudSpanner.Transaction.commit',
456457
'CloudSpanner.Database.runTransaction',
457458
];
458459
assert.deepStrictEqual(
@@ -464,17 +465,18 @@ describe('EndToEnd', () => {
464465
const expectedEventNames = [
465466
'Starting stream',
466467
'Transaction Creation Done',
468+
'Starting Commit',
469+
'Commit Done',
467470
'Acquiring session',
468471
'Cache hit: has usable session',
469472
'Acquired session',
470-
'Using Session',
471-
'Transaction Attempt Succeeded',
472473
];
473474
assert.deepStrictEqual(
474475
actualEventNames,
475476
expectedEventNames,
476477
`Unexpected events:\n\tGot: ${actualEventNames}\n\tWant: ${expectedEventNames}`
477478
);
479+
done();
478480
});
479481
});
480482

@@ -1516,37 +1518,8 @@ SELECT 1p
15161518
expectedSpanNames,
15171519
`span names mismatch:\n\tGot: ${actualSpanNames}\n\tWant: ${expectedSpanNames}`
15181520
);
1519-
1520-
// We need to ensure a strict relationship between the spans.
1521-
// |-Database.runTransactionAsync |-------------------------------------|
1522-
// |-Snapshot.run |------------------------|
1523-
// |-Snapshot.runStream |---------------------|
1524-
// |-Transaction.commit |--------|
1525-
// |-Snapshot.begin |------|
1526-
// |-Snapshot.commit |-----|
1527-
const spanDatabaseRunTransactionAsync = spans[spans.length - 1];
1528-
assert.deepStrictEqual(
1529-
spanDatabaseRunTransactionAsync.name,
1530-
'CloudSpanner.Database.runTransactionAsync',
1531-
`${actualSpanNames}`
1532-
);
1533-
const spanTransactionCommit0 = spans[spans.length - 2];
1534-
assert.strictEqual(
1535-
spanTransactionCommit0.name,
1536-
'CloudSpanner.Transaction.commit'
1537-
);
1538-
assert.deepStrictEqual(
1539-
spanTransactionCommit0.parentSpanId,
1540-
spanDatabaseRunTransactionAsync.spanContext().spanId,
1541-
'Expected that Database.runTransaction is the parent to Transaction.commmit'
1542-
);
15431521
const spanSnapshotRun = spans[2];
15441522
assert.strictEqual(spanSnapshotRun.name, 'CloudSpanner.Snapshot.run');
1545-
assert.deepStrictEqual(
1546-
spanSnapshotRun.parentSpanId,
1547-
spanDatabaseRunTransactionAsync.spanContext().spanId,
1548-
'Expected that Database.runTransaction is the parent to Snapshot.run'
1549-
);
15501523
const wantSpanErr = '6 ALREADY_EXISTS: ' + messageBadInsertAlreadyExistent;
15511524
assert.deepStrictEqual(
15521525
spanSnapshotRun.status.code,
@@ -1584,6 +1557,38 @@ SELECT 1p
15841557
'Expected that sessionPool.createSessions is the parent to db.batchCreassionSessions'
15851558
);
15861559

1560+
// TODO: Uncomment once we've merged Database.runTransactionAsync tracing.
1561+
// We need to ensure a strict relationship between the spans.
1562+
// |-Database.runTransactionAsync |-------------------------------------|
1563+
// |-Snapshot.run |------------------------|
1564+
// |-Snapshot.runStream |---------------------|
1565+
// |-Transaction.commit |--------|
1566+
// |-Snapshot.begin |------|
1567+
// |-Snapshot.commit |-----|
1568+
/*
1569+
const spanDatabaseRunTransactionAsync = spans[spans.length - 1];
1570+
assert.deepStrictEqual(
1571+
spanDatabaseRunTransactionAsync.name,
1572+
'CloudSpanner.Database.runTransactionAsync',
1573+
`${actualSpanNames}`
1574+
);
1575+
const spanTransactionCommit0 = spans[spans.length - 1];
1576+
assert.strictEqual(
1577+
spanTransactionCommit0.name,
1578+
'CloudSpanner.Transaction.commit'
1579+
);
1580+
assert.deepStrictEqual(
1581+
spanTransactionCommit0.parentSpanId,
1582+
spanDatabaseRunTransactionAsync.spanContext().spanId,
1583+
'Expected that Database.runTransaction is the parent to Transaction.commmit'
1584+
);
1585+
1586+
assert.deepStrictEqual(
1587+
spanSnapshotRun.parentSpanId,
1588+
spanDatabaseRunTransactionAsync.spanContext().spanId,
1589+
'Expected that Database.runTransaction is the parent to Snapshot.run'
1590+
);
1591+
15871592
// Assert that despite all being exported, SessionPool.createSessions
15881593
// is not in the same trace as runStream, createSessions is invoked at
15891594
// Spanner Client instantiation, thus before database.run is invoked.
@@ -1592,6 +1597,8 @@ SELECT 1p
15921597
spanDatabaseRunTransactionAsync.spanContext().traceId,
15931598
'Did not expect the same traceId'
15941599
);
1600+
*/
1601+
15951602
// Finally check for the collective expected event names.
15961603
const expectedEventNames = [
15971604
'Requesting 25 sessions',
@@ -1605,6 +1612,9 @@ SELECT 1p
16051612
'Transaction Creation Done',
16061613
'Starting Commit',
16071614
'Commit Done',
1615+
1616+
// TODO: Uncomment once we've merged Database.runTransactionAsync tracing.
1617+
/*
16081618
'Acquiring session',
16091619
'Waiting for a session to become available',
16101620
'Acquired session',
@@ -1613,6 +1623,7 @@ SELECT 1p
16131623
'Transaction Attempt Aborted',
16141624
'exception',
16151625
'exception',
1626+
*/
16161627
];
16171628
assert.deepStrictEqual(
16181629
actualEventNames,
@@ -2144,11 +2155,15 @@ describe('Traces for ExecuteStream broken stream retries', () => {
21442155
'Transaction Creation Done',
21452156
'Starting Commit',
21462157
'Commit Done',
2158+
2159+
// TODO: Uncomment once we've merged Database.runTransactionAsync tracing.
2160+
/*
21472161
'Acquiring session',
21482162
'Waiting for a session to become available',
21492163
'Acquired session',
21502164
'Using Session',
21512165
'Transaction Attempt Succeeded',
2166+
*/
21522167
];
21532168
assert.deepStrictEqual(
21542169
actualEventNames,
@@ -2218,11 +2233,15 @@ describe('Traces for ExecuteStream broken stream retries', () => {
22182233
'Requesting 25 sessions',
22192234
'Creating 25 sessions',
22202235
'Requested for 25 sessions returned 25',
2236+
2237+
// TODO: Uncomment once we've merged Database.runTransactionAsync tracing.
2238+
/*
22212239
'Acquiring session',
22222240
'Waiting for a session to become available',
22232241
'Acquired session',
22242242
'Using Session',
22252243
'Transaction Attempt Succeeded',
2244+
*/
22262245
];
22272246
assert.deepStrictEqual(
22282247
actualEventNames,

src/transaction-runner.ts

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import {isSessionNotFoundError} from './session-pool';
2626
import {Database} from './database';
2727
import {google} from '../protos/protos';
2828
import IRequestOptions = google.spanner.v1.IRequestOptions;
29-
import {getActiveOrNoopSpan, setSpanErrorAndException} from './instrument';
3029

3130
// eslint-disable-next-line @typescript-eslint/no-var-requires
3231
const jsonProtos = require('../protos/protos.json');
@@ -225,7 +224,6 @@ export abstract class Runner<T> {
225224
async run(): Promise<T> {
226225
const start = Date.now();
227226
const timeout = this.options.timeout!;
228-
const span = getActiveOrNoopSpan();
229227

230228
let lastError: grpc.ServiceError;
231229

@@ -234,21 +232,9 @@ export abstract class Runner<T> {
234232
while (this.attempts === 0 || Date.now() - start < timeout) {
235233
const transaction = await this.getTransaction();
236234

237-
// this.attempts refers to the number of retries, not while loop iterations
238-
// hence without a +1, reading a span entry that says attempt=0 makes no
239-
// sence to a user.
240-
const countableAttempts = this.attempts + 1;
241-
242235
try {
243-
const result = await this._run(transaction);
244-
span.addEvent('Transaction Attempt Succeeded', {
245-
attempt: countableAttempts,
246-
});
247-
return result;
236+
return await this._run(transaction);
248237
} catch (e) {
249-
span.addEvent('Transaction Attempt Failed', {
250-
attempt: countableAttempts,
251-
});
252238
this.session.lastError = e as grpc.ServiceError;
253239
lastError = e as grpc.ServiceError;
254240
}
@@ -257,29 +243,19 @@ export abstract class Runner<T> {
257243
// thrown here. We do this to bubble this error up to the caller who is
258244
// responsible for retrying the transaction on a different session.
259245
if (
260-
!RETRYABLE.includes(lastError!.code!) &&
261-
!isRetryableInternalError(lastError!)
246+
!RETRYABLE.includes(lastError.code!) &&
247+
!isRetryableInternalError(lastError)
262248
) {
263-
span.addEvent('Transaction Attempt Aborted', {
264-
attempt: this.attempts + 1,
265-
});
266-
setSpanErrorAndException(span, lastError!);
267-
throw lastError!;
249+
throw lastError;
268250
}
269251

270252
this.attempts += 1;
271253

272-
const delay = this.getNextDelay(lastError!);
273-
span.addEvent('Backing off', {delay: delay, attempt: countableAttempts});
254+
const delay = this.getNextDelay(lastError);
274255
await new Promise(resolve => setTimeout(resolve, delay));
275256
}
276257

277-
span.addEvent('Transaction Attempt Aborted due to Deadline Error', {
278-
total_attempts: this.attempts + 1,
279-
});
280-
const err = new DeadlineError(lastError!);
281-
setSpanErrorAndException(span, err);
282-
throw err;
258+
throw new DeadlineError(lastError!);
283259
}
284260
}
285261

0 commit comments

Comments
 (0)