Skip to content

Commit f3b8cde

Browse files
committed
fix: retreive log entries from logging bucket
1 parent 9934022 commit f3b8cde

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

src/index.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -593,9 +593,13 @@ class Logging {
593593
reqOpts.resourceNames = arrify(reqOpts.resourceNames!);
594594
this.projectId = await this.auth.getProjectId();
595595
const resourceName = 'projects/' + this.projectId;
596-
if (reqOpts.resourceNames.indexOf(resourceName) === -1) {
597-
reqOpts.resourceNames.push(resourceName);
598-
}
596+
const isReadFromBucket = reqOpts.resourceNames.some(resourceName =>
597+
resourceName.startsWith(resourceName)
598+
);
599+
if (
600+
reqOpts.resourceNames.indexOf(resourceName) === -1 &&
601+
!isReadFromBucket
602+
) {
599603
delete reqOpts.autoPaginate;
600604
delete reqOpts.gaxOptions;
601605
let gaxOptions = extend(

test/index.ts

+24
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,30 @@ describe('Logging', () => {
616616
await logging.getEntries(options);
617617
});
618618

619+
it('should not push project id if include logging bucket view', async () => {
620+
const options = {
621+
resourceNames: [
622+
'projects/' +
623+
logging.projectId +
624+
'/locations/global/buckets/test-bucket/views/test-view',
625+
],
626+
};
627+
628+
logging.loggingService.listLogEntries = async (
629+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
630+
reqOpts: any
631+
) => {
632+
assert.deepStrictEqual(reqOpts.resourceNames, [
633+
'projects/' +
634+
logging.projectId +
635+
'/locations/global/buckets/test-bucket/views/test-view',
636+
]);
637+
return [[]];
638+
};
639+
640+
await logging.getEntries(options);
641+
});
642+
619643
describe('error', () => {
620644
const error = new Error('Error.');
621645

0 commit comments

Comments
 (0)