Skip to content

Conversation

@bhshkh
Copy link
Contributor

@bhshkh bhshkh commented Aug 29, 2025

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #1593 🦕

This PR addresses an issue where users were unable to fetch logs from a logging bucket located in a different Google Cloud project.

Issue
if projects/${BUCKET_CONTAINING_PROJECT}/locations/global/buckets/my-repro-bucket-01/views/_AllLogs has log entry "log-01"
and projects/${BUCKET_CONTAINING_PROJECT}/locations/global/buckets/my-repro-bucket-02/views/_AllLogs has log entry "log-02",
and projects/${BUCKET_CONTAINING_PROJECT}/locations/global/buckets/_Default/views/_AllLogs has log entry "log-01", "log-02", "log-03", "log-04". Then, providing resourceNames: my-repro-bucket-01 and my-repro-bucket-02
should retrieve only "log-01" and "log-02" but in the current library, it returns "log-01", "log-02", "log-03", "log-04"

Fix
The fix refines the logic for handling default resource names. The library now checks if the resourceNames array is empty before adding the default project ID.

  • If getEntries() is called with no resourceNames, the library adds the current project ID to ensure the API call is valid (preserving the behavior from PR fix: Unique-ify getEntries resourceNames #92).
  • If getEntries() is called with a resourceNames array, the library now respects the user's input and does not modify it.

This change ensures that developers can correctly query logs from any bucket they have access to, including those outside of the client's default project. A unit test has been added to verify this behavior and prevent future regressions.

When `getEntries` is called with a `resourceNames` array that specifies a logging bucket (particularly one in a
    different project), the library was incorrectly appending the current project's ID to the array.

This resulted in an invalid request, causing the Logging API to reject it with an `INVALID_ARGUMENT` error.

The fix adjusts the logic to only inject the default project ID if the `resourceNames` array is explicitly empty. This
    preserves the expected default behavior of searching within the current project, while respecting user-provided
    resource names for cross-project queries.

Fixes: googleapis#1593
@bhshkh bhshkh requested review from a team as code owners August 29, 2025 01:43
@bhshkh bhshkh requested a review from gkevinzheng August 29, 2025 01:43
@product-auto-label product-auto-label bot added the size: s Pull request size is small. label Aug 29, 2025
@product-auto-label product-auto-label bot added the api: logging Issues related to the googleapis/nodejs-logging API. label Aug 29, 2025
@bhshkh bhshkh marked this pull request as draft August 29, 2025 02:05
this.projectId = await this.auth.getProjectId();
const resourceName = 'projects/' + this.projectId;
if (reqOpts.resourceNames.indexOf(resourceName) === -1) {
if (reqOpts.resourceNames.length === 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would definitely add a comment just inside this if statement explaining the reason why we only add the resourceName when the resourceNames array is empty.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

}

reqOpts.resourceNames = arrify(reqOpts.resourceNames!);
this.projectId = await this.auth.getProjectId();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know enough about this code to know that if we only set the projectid of this object inside the if statement now how that might affect other code in this class. We would have to do a search on this class for the projectId of this property.

I might consider just keeping this line of code where it is?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right

Moved

});

it('should accept GAX options', async () => {
const config = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to do this now, but I think it would be good to have a system test to capture the intended behaviour. Something like main...fix/resource-name-other-projects-dan. I'm not sure how hard this is though. Maybe it requires setting up another project which is a lot of work.

I don't want this to block the merge, but maybe adding a TODO or internal issue would be good.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want a test to ensure the request returns entries because that is a reproduction of the issue.

@danieljbruce
Copy link
Contributor

I don't have permission to approve, but I would if I could. I think just keeping the this.projectId assignment where it is and adding a comment would be a little better though.

@bhshkh bhshkh marked this pull request as ready for review August 29, 2025 21:57
@bhshkh bhshkh changed the title fix(logging): Allow fetching logs from buckets in other projects fix(logging): Specifying resourceNames should fetch logs only from those resources Aug 29, 2025
@cindy-peng
Copy link
Contributor

Hi @danieljbruce, The PR looks good to me. However CI testing failed due to node version. Do you know if there is a way that we can bypass these checks?

@danieljbruce
Copy link
Contributor

Try removing 14 from the array at

node: [14, 16, 18, 20]
if this is the only problematic check. Then create an issue to add it back to the array later.

@cindy-peng
Copy link
Contributor

Closing PR as we have merged the forked PR with testing configurations: #1597

@cindy-peng cindy-peng closed this Sep 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: logging Issues related to the googleapis/nodejs-logging API. size: s Pull request size is small.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot fetch logs from another bucket because resourceNames are being enforced

3 participants