-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(observability): fix bugs found from product review + negative cases #2158
base: main
Are you sure you want to change the base?
feat(observability): fix bugs found from product review + negative cases #2158
Conversation
62bf905
to
1b7d8b6
Compare
src/database.ts
Outdated
if (err) { | ||
setSpanError(span, err!); | ||
} | ||
await runner.run().then(release, async err => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we are already doing .then() on runner.run(), why do we then need to await here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@odeke-em it will work even if we don't await on runner.run(). please check and remove the await
src/database.ts
Outdated
this.pool_.release(session!); | ||
}; | ||
|
||
const runner = new TransactionRunner( | ||
session!, | ||
transaction!, | ||
(err, resp) => { | ||
async (err, resp) => { | ||
if (err) { | ||
setSpanError(span, err!); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setSpanError(span, err!); | |
setSpanError(span, err); |
we already are using if condition
src/transaction.ts
Outdated
@@ -754,9 +755,11 @@ export class Snapshot extends EventEmitter { | |||
(err as grpc.ServiceError).code === grpc.status.ABORTED | |||
) | |||
) { | |||
span.addEvent('Transaction Aborted, retrying begin', { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code block is for the non Aborted errors. Change Transaction threw error, retrying with explicit begin
src/database.ts
Outdated
@@ -3222,14 +3223,14 @@ class Database extends common.GrpcServiceObject { | |||
span.addEvent('No session available', { | |||
'session.id': session?.id, | |||
}); | |||
this.runTransaction(options, runFn!); | |||
await this.runTransaction(options, runFn!); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why have we added await on this.runTransaction
. This does not return a promise nor its a async method.
src/database.ts
Outdated
span.end(); | ||
return; | ||
} | ||
|
||
if (err) { | ||
await runFn!(err as grpc.ServiceError); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here ?
src/database.ts
Outdated
|
||
if (isSessionNotFoundError(err)) { | ||
span.addEvent('No session available', { | ||
'session.id': session?.id, | ||
}); | ||
release(); | ||
this.runTransaction(options, runFn!); | ||
await this.runTransaction(options, runFn!); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
again why async here?
src/database.ts
Outdated
|
||
try { | ||
const result = await runner.run(); | ||
span.end(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
span.end() should be done in finally block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really, on an exception this code retries in the while loop above so that's not correct to end it in the finally block. It should be ended only on success.
const traceConfig = { | ||
tableName: table, | ||
opts: this._observabilityOptions, | ||
dbName: this._dbName!, | ||
}; | ||
return startTrace('Snapshot.createReadStream', traceConfig, span => { | ||
let attempt = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove the attempt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@surbhigarg92 why? The feature docs ask that we record the attempt number for streams.
src/transaction.ts
Outdated
@@ -754,9 +764,16 @@ export class Snapshot extends EventEmitter { | |||
(err as grpc.ServiceError).code === grpc.status.ABORTED | |||
) | |||
) { | |||
this.begin(); | |||
span.addEvent('Stream broken. Safe to retry', { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove these two spans for stream broken. We are not retrying broken stream here , that is happening in partial-result-stream
class. https:/googleapis/nodejs-spanner/blob/main/src/partial-result-stream.ts#L558-L586
Maybe lets skip these two spans for now and move on.
if (!resumeToken) { | ||
if (attempt === 0) { | ||
span.addEvent('Starting stream'); | ||
} else { | ||
span.addEvent('Re-attempting start stream', {attempt: attempt}); | ||
} | ||
} else { | ||
span.addEvent('Resuming stream', { | ||
resume_token: resumeToken!.toString(), | ||
attempt: attempt, | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep a simple span like we have done in other method without attempt
if (resumeToken) {
span.addEvent('Resuming stream', {
resume_token: resumeToken!.toString(),\
});
}
```
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't follow what you mean here @surbhigarg92. When do we record the beginning attempt or the re-attempts?
src/transaction.ts
Outdated
@@ -1330,8 +1364,16 @@ export class Snapshot extends EventEmitter { | |||
(err as grpc.ServiceError).code === grpc.status.ABORTED | |||
) | |||
) { | |||
this.begin(); | |||
span.addEvent('Stream broken. Safe to retry', { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here. remove these events
callback(err, resp); | ||
}); | ||
}, callback); | ||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no change is required here. As we are doing ".then" on begin call.
91c5281
to
508243f
Compare
7bdc173
to
a3589e5
Compare
Extracted out of PR googleapis#2158, this change traces Database.runTransactionAsync. However, testing isn't effective because of bugs such as googleapis#2166.
Extracted out of PR googleapis#2158, this change traces Database.runTransactionAsync. However, testing isn't effective because of bugs such as googleapis#2166.
Extracted out of PR googleapis#2158, this change traces Database.runTransactionAsync. Updates googleapis#2079
This change adds recording of retry span annotations, catching cases in which exceptions where thrown but spans were not ended while testing out and visually confirming the results.
…ontext.active only in Spanner constructor
…turn before span.end()
e0e31f5
to
13bc9f5
Compare
This change adds recording of retry span annotations, catching cases in which exceptions where thrown but spans were not ended while testing out and visually confirming the results.