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

feat(observability): fix bugs found from product review + negative cases#2158

Merged
surbhigarg92 merged 18 commits intogoogleapis:mainfrom
odeke-em:trace-fix-bugs-from-product-review+negative-cases
Oct 24, 2024
Merged

feat(observability): fix bugs found from product review + negative cases#2158
surbhigarg92 merged 18 commits intogoogleapis:mainfrom
odeke-em:trace-fix-bugs-from-product-review+negative-cases

Conversation

@odeke-em
Copy link
Copy Markdown
Contributor

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.

@odeke-em odeke-em requested review from a team October 12, 2024 09:25
@product-auto-label product-auto-label Bot added size: m Pull request size is medium. api: spanner Issues related to the googleapis/nodejs-spanner API. labels Oct 12, 2024
@odeke-em odeke-em force-pushed the trace-fix-bugs-from-product-review+negative-cases branch from 62bf905 to 1b7d8b6 Compare October 12, 2024 09:26
@product-auto-label product-auto-label Bot added size: l Pull request size is large. size: xl Pull request size is extra large. and removed size: m Pull request size is medium. size: l Pull request size is large. labels Oct 12, 2024
Comment thread src/transaction.ts Outdated
Comment thread src/database.ts Outdated
if (err) {
setSpanError(span, err!);
}
await runner.run().then(release, async err => {
Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Contributor

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

Comment thread src/database.ts Outdated
Comment thread src/transaction.ts Outdated
(err as grpc.ServiceError).code === grpc.status.ABORTED
)
) {
span.addEvent('Transaction Aborted, retrying begin', {
Copy link
Copy Markdown
Contributor

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

Comment thread src/database.ts Outdated
'session.id': session?.id,
});
this.runTransaction(options, runFn!);
await this.runTransaction(options, runFn!);
Copy link
Copy Markdown
Contributor

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.

Comment thread src/database.ts Outdated
}

if (err) {
await runFn!(err as grpc.ServiceError);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here ?

Comment thread src/database.ts Outdated
});
release();
this.runTransaction(options, runFn!);
await this.runTransaction(options, runFn!);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again why async here?

Comment thread src/database.ts Outdated

try {
const result = await runner.run();
span.end();
Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor Author

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.

Comment thread src/transaction.ts
Comment thread src/transaction.ts Outdated
)
) {
this.begin();
span.addEvent('Stream broken. Safe to retry', {
Copy link
Copy Markdown
Contributor

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://github.com/googleapis/nodejs-spanner/blob/main/src/partial-result-stream.ts#L558-L586
Maybe lets skip these two spans for now and move on.

Comment thread src/transaction.ts
Comment thread src/transaction.ts Outdated
)
) {
this.begin();
span.addEvent('Stream broken. Safe to retry', {
Copy link
Copy Markdown
Contributor

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

Comment thread src/transaction.ts Outdated
callback(err, resp);
});
}, callback);
try {
Copy link
Copy Markdown
Contributor

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.

@odeke-em odeke-em force-pushed the trace-fix-bugs-from-product-review+negative-cases branch from 91c5281 to 508243f Compare October 18, 2024 06:06
@alkatrivedi alkatrivedi added kokoro:force-run Add this label to force Kokoro to re-run the tests. owlbot:run Add this label to trigger the Owlbot post processor. labels Oct 18, 2024
@gcf-owl-bot gcf-owl-bot Bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Oct 18, 2024
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 18, 2024
@alkatrivedi alkatrivedi added kokoro:force-run Add this label to force Kokoro to re-run the tests. owlbot:run Add this label to trigger the Owlbot post processor. labels Oct 18, 2024
@gcf-owl-bot gcf-owl-bot Bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Oct 18, 2024
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 18, 2024
@odeke-em odeke-em force-pushed the trace-fix-bugs-from-product-review+negative-cases branch from 7bdc173 to a3589e5 Compare October 20, 2024 03:28
odeke-em added a commit to odeke-em/nodejs-spanner that referenced this pull request Oct 21, 2024
Extracted out of PR googleapis#2158, this change traces
Database.runTransactionAsync. However, testing isn't effective
because of bugs such as googleapis#2166.
odeke-em added a commit to odeke-em/nodejs-spanner that referenced this pull request Oct 21, 2024
Extracted out of PR googleapis#2158, this change traces
Database.runTransactionAsync. However, testing isn't effective
because of bugs such as googleapis#2166.
odeke-em added a commit to odeke-em/nodejs-spanner that referenced this pull request Oct 21, 2024
Extracted out of PR googleapis#2158, this change traces
Database.runTransactionAsync.

Updates googleapis#2079
@odeke-em odeke-em force-pushed the trace-fix-bugs-from-product-review+negative-cases branch from e0e31f5 to 13bc9f5 Compare October 21, 2024 10:52
gcf-merge-on-green Bot pushed a commit that referenced this pull request Oct 21, 2024
Extracted out of PR #2158, this change traces
Database.runTransactionAsync.

Updates #207
@odeke-em odeke-em force-pushed the trace-fix-bugs-from-product-review+negative-cases branch from 3fb5164 to 03a6298 Compare October 21, 2024 13:15
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 23, 2024
@odeke-em
Copy link
Copy Markdown
Contributor Author

@alkatrivedi kindly help me run the bots.

@alkatrivedi alkatrivedi added kokoro:force-run Add this label to force Kokoro to re-run the tests. owlbot:run Add this label to trigger the Owlbot post processor. labels Oct 23, 2024
@gcf-owl-bot gcf-owl-bot Bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Oct 23, 2024
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 23, 2024
@odeke-em
Copy link
Copy Markdown
Contributor Author

Kind ping @alkatrivedi to run the bots.

@odeke-em
Copy link
Copy Markdown
Contributor Author

Kind ping @harshachinta @alkatrivedi @surbhigarg92 to run the bots as I need rapid debugging but the time in-between is too long.

Comment thread src/database.ts Outdated
setSpanErrorAndException(span, e as Error);
this.emit('error', e);
} finally {
if (span.isRecording()) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove span. isRecording

Comment thread src/database.ts Outdated
span.end();
callback!(err, snapshot);
});
this.getSnapshot(options, callback!);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move span.end() above the callback. We will not see the traces hierarchy in this case which is ok for sessionnotfounderror.

Comment thread src/database.ts Outdated
callback!(err, snapshot);
});
this.getSnapshot(options, callback!);
// Explicitly requested in code review that this span.end() be
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove these comments from code

Comment thread src/database.ts
Comment thread src/database.ts Outdated
Comment on lines +3088 to +3092
dataStream = this.runStream(query, options);
dataStream.pipe(proxyStream);
// Explicitly invoking span.end() here,
// instead of inside dataStream.on('error').
span.end();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move span.end() to before we create new datastream

Comment thread src/database.ts Outdated
}
setImmediate(runFn!, err);
release();
span.end();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove span.end() once we add it in release method

Comment thread src/database.ts Outdated
options
);
dataStream.pipe(proxyStream);
span.end();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this span.end() before creating new stream

Comment thread src/database.ts Outdated
Comment on lines +3665 to +3672
// Retry this method.
this.writeAtLeastOnce(mutations, options, (err, resp) => {
if (err) {
setSpanError(span, err);
}
span.end();
cb!(err, resp);
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove this change and add span.end() before retry

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks!

Comment thread src/transaction.ts Outdated
Comment on lines +765 to +767
// TODO: re-examine if this.begin() should still exist and if
// an await is needed: with await the generated begin span
// will look wonky and out of order. Please ses
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a short comment, bug has details

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks!

Comment thread src/transaction.ts Outdated
Comment on lines +1360 to +1362
// TODO: Examine the consequence of not awaiting this method,
// as the span might appear out of order.
// Please see https://github.com/googleapis/nodejs-spanner/issues/2170
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Comment thread src/database.ts Outdated
Comment on lines +3272 to +3275
.catch(e => {
setSpanErrorAndException(span, e as Error);
throw e;
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.catch(e => {
setSpanErrorAndException(span, e as Error);
throw e;
});
.catch(e => {
setSpanErrorAndException(span, e as Error);
span.end();
throw e;
});

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

api: spanner Issues related to the googleapis/nodejs-spanner API. size: xl Pull request size is extra large.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants