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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: retreive log entries from logging bucket #1482

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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