Skip to content

Commit

Permalink
fix: retreive log entries from logging bucket
Browse files Browse the repository at this point in the history
  • Loading branch information
Colt45s committed Jan 17, 2024
1 parent 1f94504 commit 638905d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -593,9 +593,13 @@ class Logging {
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);
}
const isReadFromBucket = reqOpts.resourceNames.some(resourceName =>
resourceName.startsWith(resourceName)
);
if (
reqOpts.resourceNames.indexOf(resourceName) === -1 &&
!isReadFromBucket
) {
delete reqOpts.autoPaginate;
delete reqOpts.gaxOptions;
let gaxOptions = extend(
Expand Down
24 changes: 24 additions & 0 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,30 @@ describe('Logging', () => {
await logging.getEntries(options);
});

it('should not push project id if include logging bucket view', async () => {
const options = {
resourceNames: [
'projects/' +
logging.projectId +
'/locations/global/buckets/test-bucket/views/test-view',
],
};

logging.loggingService.listLogEntries = async (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
reqOpts: any
) => {
assert.deepStrictEqual(reqOpts.resourceNames, [
'projects/' +
logging.projectId +
'/locations/global/buckets/test-bucket/views/test-view',
]);
return [[]];
};

await logging.getEntries(options);
});

describe('error', () => {
const error = new Error('Error.');

Expand Down

0 comments on commit 638905d

Please sign in to comment.