Skip to content

Commit

Permalink
skip setProjectId() for getEntries() and getEntriesStream()
Browse files Browse the repository at this point in the history
  • Loading branch information
AVaksman committed Mar 28, 2019
1 parent 2ad927b commit 4d05e81
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 164 deletions.
68 changes: 37 additions & 31 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,13 +514,13 @@ class Logging {
},
options);
reqOpts.resourceNames = arrify(reqOpts.resourceNames);
this.projectId = await this.auth.getProjectId();
const resourceName = 'projects/' + this.projectId;
if (reqOpts.resourceNames.indexOf(resourceName) === -1) {
reqOpts.resourceNames.push(resourceName);
}
delete reqOpts.autoPaginate;
delete reqOpts.gaxOptions;
this.setProjectId(reqOpts);
const gaxOptions = extend(
{
autoPaginate: options!.autoPaginate,
Expand Down Expand Up @@ -578,32 +578,38 @@ class Logging {
next(null, Entry.fromApiResponse_(entry));
});
userStream.once('reading', () => {
const reqOpts = extend(
{
orderBy: 'timestamp desc',
},
options);
reqOpts.resourceNames = arrify(reqOpts.resourceNames);
reqOpts.resourceNames.push(`projects/${this.projectId}`);
delete reqOpts.autoPaginate;
delete reqOpts.gaxOptions;
const gaxOptions = extend(
{
autoPaginate: options.autoPaginate,
},
options.gaxOptions);

let gaxStream: ClientReadableStream<LogEntry>;
requestStream = streamEvents<Duplex>(through.obj());
(requestStream as AbortableDuplex).abort = () => {
if (gaxStream && gaxStream.cancel) {
gaxStream.cancel();
this.auth.getProjectId().then(projectId => {
this.projectId = projectId;
if (options.logName_) {
options.filter =
`logName="${Log.formatName_(this.projectId, options.logName_)}"`;
delete options.logName_;
}
};
// tslint:disable-next-line no-any
if (!(global as any).GCLOUD_SANDBOX_ENV) {
requestStream.once('reading', () => {
this.setProjectId(reqOpts).then(() => {
const reqOpts = extend(
{
orderBy: 'timestamp desc',
},
options);
reqOpts.resourceNames = arrify(reqOpts.resourceNames);
reqOpts.resourceNames.push(`projects/${this.projectId}`);
delete reqOpts.autoPaginate;
delete reqOpts.gaxOptions;
const gaxOptions = extend(
{
autoPaginate: options.autoPaginate,
},
options.gaxOptions);

let gaxStream: ClientReadableStream<LogEntry>;
requestStream = streamEvents<Duplex>(through.obj());
(requestStream as AbortableDuplex).abort = () => {
if (gaxStream && gaxStream.cancel) {
gaxStream.cancel();
}
};
// tslint:disable-next-line no-any
if (!(global as any).GCLOUD_SANDBOX_ENV) {
requestStream.once('reading', () => {
try {
gaxStream =
this.loggingService.listLogEntriesStream(reqOpts, gaxOptions);
Expand All @@ -617,12 +623,12 @@ class Logging {
requestStream.destroy(err);
})
.pipe(requestStream);
return;
});
return;
});
}
// tslint:disable-next-line no-any
(userStream as any).setPipeline(requestStream, toEntryStream);
}
// tslint:disable-next-line no-any
(userStream as any).setPipeline(requestStream, toEntryStream);
});
});
return userStream;
}
Expand Down
Loading

0 comments on commit 4d05e81

Please sign in to comment.