question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

quota_project_id not propagated

See original GitHub issue

What version of gRPC-Java are you using?

24.0.0

What is your environment?

jdk17

What did you expect to see?

A call being made with header x-goog-user-project header when service account has quota_project_id set so that calls are properly counted against chosen quota.

What did you see instead?

No header set.

Steps to reproduce the bug

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;

import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.cloud.monitoring.v3.MetricServiceClient;
import com.google.cloud.monitoring.v3.MetricServiceSettings;
import com.google.monitoring.v3.ListMetricDescriptorsRequest;

class GcpSample {
    public static void main(String[] args) throws IOException {
        // content of the service account key in json format with quota_project_id field set
        String serviceKey="[SERVICE_ACCOUNT_KEY_IN_JSON_FORMAT]"; 
        String projectId="[YOUR_PROJECT_NAME]";
        InputStream tokenStream = new ByteArrayInputStream(serviceKey.getBytes(StandardCharsets.UTF_8));
        GoogleCredentials creds = GoogleCredentials.fromStream(tokenStream);

        MetricServiceSettings.Builder builder = MetricServiceSettings.newBuilder();
        builder.setCredentialsProvider(FixedCredentialsProvider.create(creds));
        MetricServiceClient stackDriverClient = MetricServiceClient.create(builder.build());


        ListMetricDescriptorsRequest request = ListMetricDescriptorsRequest.newBuilder()
                .setName("projects/" + projectId)
                .setFilter("metric.type=\"compute.googleapis.com/instance/cpu/utilization\"")
                .build();

        stackDriverClient.listMetricDescriptors(request);
    }
}

After some debugging I found out that at some point ServiceAccountCredentials will be converted to ServiceAccountJwtAccessCredentials and it loses the quota_project_id during that conversion. Conversion is done in GoogleAuthLibraryCallCredentials#JwtHelper and the field is just not set.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
ejona86commented, Sep 15, 2022

This was released in 1.49.0.

0reactions
akonarskacommented, Aug 24, 2022

@ejona86 Could you let me know when this is released?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How does the UI calculate the resource quota set for ... - GitHub
Updating an existing namespace default limit for a quota at the project level will not result in that value being propagated to existing ......
Read more >
gcloud auth application-default set-quota-project
API-first integration to connect existing data and applications. ... Solution to bridge existing care systems and apps on Google Cloud. ... No-code development ......
Read more >
How Resource Quotas Work in Rancher Projects
In Rancher, you apply a resource quota to the project, and then the quota propagates to each namespace, whereafter Kubernetes enforces your ...
Read more >
Plan Error: Cloud Resource Manager API has not been used
json introduced by command the login cmd. try to remove "quota project id" from the application_default_credentials.json and instead do. gcloud ...
Read more >
Quotas and Limit Ranges | OpenShift Container Platform 3.11
Quotas. A resource quota, defined by a ResourceQuota object, provides constraints that limit aggregate resource consumption per project. It can limit the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found