Skip to content
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(x-goog-spanner-request-id): add bases #2211

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

odeke-em
Copy link
Contributor

@odeke-em odeke-em commented Jan 7, 2025

This change brings in the bases for x-goog-spanner-request-id by commit AtomicCounter and the various utilities plus some unit tests.

Ripped out of PR #2205
Updates #2200

@odeke-em odeke-em requested review from a team as code owners January 7, 2025 08:49
@product-auto-label product-auto-label bot added size: l Pull request size is large. api: spanner Issues related to the googleapis/nodejs-spanner API. labels Jan 7, 2025
@odeke-em
Copy link
Contributor Author

odeke-em commented Jan 7, 2025

Kindly pinging @olavloite @surbhigarg92 to help bring this in as it is carved out of the larger PR #2205 and is isolated away from main code.

@olavloite olavloite added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jan 9, 2025
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jan 9, 2025
@@ -0,0 +1,327 @@
/*!
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
/*!
/**

const X_GOOG_SPANNER_REQUEST_ID_HEADER = 'x-goog-spanner-request-id';

class AtomicCounter {
private backingBuffer: Uint32Array;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
private backingBuffer: Uint32Array;
private readonly backingBuffer: Uint32Array;


constructor(initialValue?: number) {
this.backingBuffer = new Uint32Array(
new SharedArrayBuffer(Uint32Array.BYTES_PER_ELEMENT)
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not familiar with this in Node.js, but while looking into what this is, I ran into this: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer#security_requirements

Does this affect the usability of this in Node.js? Or is this an issue that is only relevant to code running in a browser?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that's for browsers.

nthRequest: number,
attempt: number
) {
return `1.${randIdForProcess}.${nthClientId}.${channelId}.${nthRequest}.${attempt}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Can we add a comment that explains why there is a '1' at the start of this string, e.g.:

// The first digit in this string is the version number of the header type that is used.


const X_GOOG_REQ_ID_REGEX = /(\d+\.){5}\d+/;

class XGoogRequestHeaderInterceptor {
Copy link
Contributor

Choose a reason for hiding this comment

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

If I understand this correctly, this is a server interceptor, meaning that it will be used for testing, right? Could we then move this to a test file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done and thankyou @olavloite, please take a look.

const prefixesToIgnore: string[] = that.prefixesToIgnore || [];
for (i = 0; i < prefixesToIgnore.length; i++) {
const prefix = prefixesToIgnore[i];
// console.log(`prefix: ${prefix}\nmethod: ${method}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: remove?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, thanks!


function injectRequestIDIntoHeaders(
headers: {[k: string]: string},
session: any,
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we make this typed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would create an import cycle because Session also then uses injectRequestIDIntoHeaders in the follow-up PR.

test/request_id_header.ts Outdated Show resolved Hide resolved
This change brings in the bases for x-goog-spanner-request-id
by commit AtomicCounter and the various utilities plus some
unit tests.

Ripped out of PR googleapis#2205
Updates  googleapis#2200
@odeke-em odeke-em force-pushed the x-goog-spanner-request-id-bases branch 2 times, most recently from 02faead to e82d493 Compare January 24, 2025 03:35
@odeke-em odeke-em force-pushed the x-goog-spanner-request-id-bases branch from e82d493 to 60204be Compare January 24, 2025 03:36
@odeke-em odeke-em requested a review from olavloite January 24, 2025 03:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the googleapis/nodejs-spanner API. size: l Pull request size is large.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants