-
Notifications
You must be signed in to change notification settings - Fork 105
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: add resource header prefix #1196
Conversation
dccd125
to
a9b5b65
Compare
Codecov Report
@@ Coverage Diff @@
## master #1196 +/- ##
==========================================
+ Coverage 98.24% 98.58% +0.34%
==========================================
Files 23 23
Lines 21191 21275 +84
Branches 1199 1233 +34
==========================================
+ Hits 20820 20975 +155
+ Misses 368 297 -71
Partials 3 3
Continue to review full report at Codecov.
|
@skuruppu please verify the correctness of header to method |
a9b5b65
to
33ba958
Compare
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.
Thanks very much for making this change, especially with having to switch between the various values that could be set for this header.
src/index.ts
Outdated
delete reqOpts.gaxOptions; | ||
const gaxOpts = addResourcePrefixHeader( | ||
options.gaxOptions!, | ||
'projects/' + this.projectId |
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.
Should we just add a this.formattedName_ field to this class?
test/batch-transaction.ts
Outdated
(batchTransaction.session.parent as Database).formattedName_ | ||
) | ||
); | ||
console.log(gaxOpts); |
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.
nit: remove
Would it work to do this all in the Line 856 in d835ba2
To handle the different values that are used for the header, the value could be passed to the function call, e.g.: this.request({
client: 'InstanceAdminClient',
method: 'listInstanceConfigs',
reqOpts,
gaxOpts,
resourcePrefixHeader: 'projects/' + this.projectId,
}); Or even: this.request({
client: 'InstanceAdminClient',
method: 'listInstanceConfigs',
reqOpts,
gaxOpts,
headers: {
'google-cloud-resource-prefix': 'projects/' + this.projectId,
},
}); Reducing it to this format should save a lot of code, and be a bit more future proof should some other requirement come along to set a property on the gaxOptions, like: gaxOpts: addTrackingIdHeader(addResourcePrefixHeader({}, this.formattedName_)), |
Different methods require a different level of granularity, project, instance, database. |
I'm sorry if I'm not catching on quickly enough, but how does that invalidate my suggestion for code simplification? I'm just looking at replacing all of the calls to
|
@stephenplusplus PTAL |
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.
👍 Thank you! I had some small tweaks to suggest in this review, but I appreciate you taking the time to make the changes.
@AVaksman thank you for all of the changes! I think the resource header is set very nicely. There are a lot of seemingly unrelated changes to how reqOpts combines with gaxOpts. I wouldn't mind a separate PR for those, unless they are actually tied to this change? |
Not tied to this change. |
test/database.ts
Outdated
@@ -999,7 +1010,7 @@ describe('Database', () => { | |||
it('should accept gaxOptions', done => { | |||
const gaxOptions = {}; | |||
database.request = config => { | |||
assert.strictEqual(config.gaxOpts, gaxOptions); | |||
assert.deepStrictEqual(config.gaxOpts, gaxOptions); |
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.
In the cases where our src/ code directly passes the gaxOptions object that the user gives, I think "strictEqual" is the right case. When the src/ code modifies the object, we should add some properties to the test's "gaxOptions" and "deepStrictEqual" that they're still there.
@stephenplusplus PTAL |
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.
Thank you! Just these few gaxOptions lingering issues.
test/database.ts
Outdated
@@ -993,7 +1006,7 @@ describe('Database', () => { | |||
it('should accept gaxOptions', done => { | |||
const gaxOptions = {}; | |||
database.request = config => { | |||
assert.strictEqual(config.gaxOpts, gaxOptions); | |||
assert.deepStrictEqual(config.gaxOpts, gaxOptions); |
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 is a test that would be a false positive, unless we put in fake properties or revert to comparing that the input object is strictly equal.
test/database.ts
Outdated
@@ -1648,7 +1665,7 @@ describe('Database', () => { | |||
it('should accept gaxOptions', done => { | |||
const gaxOptions = {}; | |||
database.request = config => { | |||
assert.strictEqual(config.gaxOpts, gaxOptions); | |||
assert.deepStrictEqual(config.gaxOpts, gaxOptions); |
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 is a test that would be a false positive, unless we put in fake properties or revert to comparing that the input object is strictly equal.
Done, thank you! |
src/session.ts
Outdated
@@ -36,7 +36,9 @@ import { | |||
CreateSessionOptions, | |||
} from './database'; | |||
import {ServiceObjectConfig} from '@google-cloud/common'; | |||
import {NormalCallback} from './common'; | |||
import {NormalCallback, CLOUD_RESOURCE_HEADER} from './common'; | |||
// import {ServiceObjectConfig} from '@google-cloud/common'; |
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.
// import {ServiceObjectConfig} from '@google-cloud/common'; | |
// import {ServiceObjectConfig} from '@google-cloud/common'; |
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 think these comments can be removed. (This and the next line)
src/session.ts
Outdated
import {NormalCallback} from './common'; | ||
import {NormalCallback, CLOUD_RESOURCE_HEADER} from './common'; | ||
// import {ServiceObjectConfig} from '@google-cloud/common'; | ||
// import {NormalCallback} from './common'; |
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.
// import {NormalCallback} from './common'; | |
// import {NormalCallback} from './common'; |
test/batch-transaction.ts
Outdated
@@ -181,7 +190,7 @@ describe('BatchTransaction', () => { | |||
const RESPONSE = {partitions: PARTITIONS}; | |||
|
|||
const QUERY = {a: 'b'}; | |||
const CONFIG = {reqOpts: QUERY}; | |||
const CONFIG = {reqOpts: QUERY, gaxOpts: {timeout: 1000}}; |
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.
const CONFIG = {reqOpts: QUERY, gaxOpts: {timeout: 1000}}; | |
const CONFIG = {reqOpts: QUERY}; |
It doesn't look like this function is doing anything with gaxOpts
, or that we're testing it anywhere, so having this defined here could be confusing.
test/database.ts
Outdated
@@ -1017,7 +1032,7 @@ describe('Database', () => { | |||
it('should accept gaxOptions', done => { | |||
const gaxOptions = {}; | |||
database.request = config => { | |||
assert.strictEqual(config.gaxOpts, gaxOptions); | |||
assert.deepStrictEqual(config.gaxOpts, gaxOptions); |
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.
assert.deepStrictEqual(config.gaxOpts, gaxOptions); | |
assert.strictEqual(config.gaxOpts, gaxOptions); |
If after making that change, the test fails, then we would want to keep deepStrictEqual
, but also set a property on gaxOptions
.
test/instance.ts
Outdated
@@ -258,7 +269,7 @@ describe('Instance', () => { | |||
it('should accept gaxOptions', done => { | |||
const options = Object.assign({}, OPTIONS, {gaxOptions: {}}); | |||
instance.request = config => { | |||
assert.strictEqual(config.gaxOpts, options.gaxOptions); | |||
assert.deepStrictEqual(config.gaxOpts, options.gaxOptions); |
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.
assert.deepStrictEqual(config.gaxOpts, options.gaxOptions); | |
assert.strictEqual(config.gaxOpts, options.gaxOptions); |
If after making that change, the test fails, then we would want to keep deepStrictEqual
, but also set a property on options.gaxOptions
.
test/transaction.ts
Outdated
@@ -558,7 +575,7 @@ describe('Transaction', () => { | |||
const {gaxOpts, reqOpts} = REQUEST_STREAM.lastCall.args[0]; | |||
|
|||
assert.strictEqual(reqOpts.gaxOptions, undefined); | |||
assert.strictEqual(gaxOpts, fakeQuery.gaxOptions); | |||
assert.deepStrictEqual(gaxOpts, fakeQuery.gaxOptions); |
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.
assert.deepStrictEqual(gaxOpts, fakeQuery.gaxOptions); | |
assert.strictEqual(gaxOpts, fakeQuery.gaxOptions); |
If after making that change, the test fails, then we would want to keep deepStrictEqual
, but also set a property on fakeQuery.gaxOptions
.
test/transaction.ts
Outdated
@@ -1022,7 +1039,7 @@ describe('Transaction', () => { | |||
it('should accept gaxOptions', done => { | |||
const gaxOptions = {}; | |||
transaction.request = config => { | |||
assert.strictEqual(config.gaxOpts, gaxOptions); | |||
assert.deepStrictEqual(config.gaxOpts, gaxOptions); |
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.
assert.deepStrictEqual(config.gaxOpts, gaxOptions); | |
assert.strictEqual(config.gaxOpts, gaxOptions); |
If after making that change, the test fails, then we would want to keep deepStrictEqual
, but also set a property on gaxOptions
.
test/transaction.ts
Outdated
}); | ||
|
||
it('should accept gaxOptions', done => { | ||
const gaxOptions = {}; | ||
transaction.request = config => { | ||
assert.strictEqual(config.gaxOpts, gaxOptions); | ||
assert.deepStrictEqual(config.gaxOpts, gaxOptions); |
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.
assert.deepStrictEqual(config.gaxOpts, gaxOptions); | |
assert.strictEqual(config.gaxOpts, gaxOptions); |
If after making that change, the test fails, then we would want to keep deepStrictEqual
, but also set a property on gaxOptions
.
test/transaction.ts
Outdated
}); | ||
|
||
it('should accept gaxOptions', done => { | ||
const gaxOptions = {}; | ||
transaction.request = config => { | ||
assert.strictEqual(config.gaxOpts, gaxOptions); | ||
assert.deepStrictEqual(config.gaxOpts, gaxOptions); |
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.
assert.deepStrictEqual(config.gaxOpts, gaxOptions); | |
assert.strictEqual(config.gaxOpts, gaxOptions); |
If after making that change, the test fails, then we would want to keep deepStrictEqual
, but also set a property on gaxOptions
.
test/transaction.ts
Outdated
}); | ||
|
||
it('should accept gaxOptions', done => { | ||
const gaxOptions = {}; | ||
transaction.request = config => { | ||
assert.strictEqual(config.gaxOpts, gaxOptions); | ||
assert.deepStrictEqual(config.gaxOpts, gaxOptions); |
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.
assert.deepStrictEqual(config.gaxOpts, gaxOptions); | |
assert.strictEqual(config.gaxOpts, gaxOptions); |
If after making that change, the test fails, then we would want to keep deepStrictEqual
, but also set a property on gaxOptions
.
I believe I addressed all latest comments PTAL @stephenplusplus |
src/session.ts
Outdated
@@ -36,7 +36,9 @@ import { | |||
CreateSessionOptions, | |||
} from './database'; | |||
import {ServiceObjectConfig} from '@google-cloud/common'; | |||
import {NormalCallback} from './common'; | |||
import {NormalCallback, CLOUD_RESOURCE_HEADER} from './common'; | |||
// import {ServiceObjectConfig} from '@google-cloud/common'; |
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 think these comments can be removed. (This and the next line)
Fixes #1186