-
Notifications
You must be signed in to change notification settings - Fork 66
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
refactor: index.ts to async-first #412
Conversation
Codecov Report
@@ Coverage Diff @@
## master #412 +/- ##
==========================================
+ Coverage 91.33% 91.76% +0.42%
==========================================
Files 14 14
Lines 681 692 +11
Branches 34 38 +4
==========================================
+ Hits 622 635 +13
+ Misses 41 39 -2
Partials 18 18
Continue to review full report at Codecov.
|
sink.metadata = resp; | ||
callback!(null, sink, resp); | ||
}); | ||
await this.setProjectId(reqOpts); |
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.
It's awesome seeing this pattern, where we can get the project ID in an un-obtrusive way with await 👍 I think we have a chance to ditch the {{projectId}}
placeholder token here altogether. If we just get the project ID before we build the reqOpts
object (L#360), then we know this.projectId
is the right value-- no need to use the token for later replacement, since if we can't get it now, we can't get it later, either.
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.
Tagging related issue which seeks to destroy the placeholder: googleapis/nodejs-common#10
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 method is dependent on objects from other libraries storage.bucket
, bigQuery.dataset
or pubsub.topic
which could still have {{projectId}}
placeholder. I would have to still run replaceProjectIdToken
after building the reqOpts
object. So I placed it after, to have it in one place for both.
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.
Good catch, that is reasonable. I believe this specific method is unique, so I might have picked a bad one to make this suggestion on. For the others, could we skip the setProjectId()
call, and instead just put the real projectId right where we need it in the reqOpts?
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.
@stephenplusplus
It looks like I can skip setProjectId()
getSinks
and getSinksStream
since these methods do not depend on the Sink
constructor.
I am leaving getEntries
and getEntriesStream
as is since these guys do depend on the Log
constructor and I would still need to to replaceProjectIdToken
for options.filter
Lines 525 to 530 in 81138d6
options = extend( | |
{ | |
filter: 'logName="' + this.formattedName_ + '"', | |
}, | |
options); | |
return this.logging.getEntries(options as GetEntriesRequest, callback!); |
from
Lines 108 to 110 in 81138d6
constructor(logging: Logging, name: string, options?: LogOptions) { | |
options = options || {}; | |
this.formattedName_ = Log.formatName_(logging.projectId, name); |
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.
For getEntries
/getEntriesStream
, I think we can do the refresh right there:
this.projectId = await this.auth.getProjectId()
this.formattedName_ = Log.formatName(this.projectId, this.name)
options = extend({ filter: `logName="${this.formattedName_}"` })
// for getEntriesStream
this.auth.getProjectId().then(projectId => {
this.projectId = projectId
this.formattedName_ = Log.formatName(this.projectId, this.name)
options = extend({ filter: `logName="${this.formattedName_}"` })
})
The mission for a while has been to eliminate that token altogether, but it was the absence of async/await that has prevented it. But now that we have it, anywhere this.formattedName_
is used, it should be replaced with code similar to the above, in this file and others where possible. Just a thought, but maybe formatName()
should be repurposed to do the project ID fetching as well.
@AVaksman apologies for the merge conflicts on this one... |
8beb5e8
to
9032d46
Compare
Stepping back so @stephenplusplus can do the review on this one :) |
@AVaksman @stephenplusplus can we pick this back up? The PR has been sitting around for a while. |
@stephenplusplus PTAL. |
Thanks! I'm okay with that given the tradeoff for simplicity. Instead of making it a pseudo-private option, though, let's just own it and make it a feature of the method and call it |
Thanks. Done |
8d94e03
to
bf88c40
Compare
in getEntries(Stream) functions
Proposing to construct an advanced filter using |
I agree with that suggestion 👍 |
@stephenplusplus Is anything else needed for this PR? P.S. |
@AVaksman just doing some triage, it looks like system tests are failing with the following error:
Have you had a chance to look into this at all? |
@bcoe Investigating. Update: Note: this issue goes away with Node 11 obviously. |
I think if going file by file is easier, that's fine. Thanks for getting all of those changes in! |
Fixes #390
logging.request
usescallback
to differentiate between makingcallbackRequest
andstreamRequest'. But now presence of callback will be a flag for
callbackify`As such
gax
client methods directly.