googleapis / googleapis/google-cloud-node

Setting Quota Project Id via Client Options appears to be ignored, while setting it via gaxOptions.otherArgs.header works

Open
#7,580 1 comment 0 reactions 0 assignees View on GitHub
api: logging priority: p2 type: bug
Dominant language
TypeScript
Stars
3.2k
Forks
712
Avg merge
2d 3h
Merged PRs (30d)
99

Description

Thanks for stopping by to let us know something could be better!

#### Environment details

- OS:
- Node.js version: v22.12.0
- npm version: 10.9.0
- `@google-cloud/logging` version: 11.1.0

#### Steps to reproduce

I have two projects: **Project A** and **Project B**. I want to obtain logs from **Project B** while using its Quota. The call is performed using SA linked to **Project A**. Based on the documentation [here](https://cloud.google.com/docs/quotas/set-quota-project#set-project-credentials), it will use the Quota from **Project A**, as that's the Project of the SA.

In order to address that, I leverage `quotaProjectId` & `quota_project_id`. Sadly, it's not clear to me which property is the correct one, hence I set both.

The call below will count towards the Quota of Project A, although based on clientOptions, it should count towards **Project B**.

```
// SA comes from Environment and belongs to Project A

const client = new Logging({ clientOptions: { quota_project_id: projectB, quotaProjectId: projectB } });
client.getEntries({
filter: `logName = projects/${projectB}/logs/run.googleapis.com%2Fstdout
AND resource.labels.service_name=${servicename}`,
orderBy: pagingOptions.orderAsc ?? false ? 'timestamp asc' : 'timestamp desc',
resourceNames: `projects/${projectB}`,
pageSize: pagingOptions.pageSize,
pageToken: undefined,
```

When I now update the code to leverage `gaxOptions.otherArgs.headers` and explicitly set `x-goog-user-project` which is mentioned [here](https://cloud.google.com/docs/quotas/set-quota-project#rest_request), it suddenly counts the Quota to **Project B**.

```
// SA comes from Environment and belongs to Project A

const client = new Logging();
client.getEntries({
filter: `logName = projects/${projectB}/logs/run.googleapis.com%2Fstdout
AND resource.labels.service_name=${servicename}`,
orderBy: pagingOptions.orderAsc ?? false ? 'timestamp asc' : 'timestamp desc',
resourceNames: `projects/${projectB}`,
pageSize: pagingOptions.pageSize,
pageToken: undefined,
gaxOptions: {
otherArgs: { headers: { 'x-goog-user-project': projectB } },
},
```
Hence I assume there is an issue where setting Quota Project in the clientOptions does not actually result in the correct header being generated/set.

Thanks!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.