简体   繁体   English

谷歌 Stackdriver API 权限被拒绝

[英]Google Stackdriver API permission denied

I am trying to get metrics using Stackdriver API, using a service account.我正在尝试使用服务帐户使用 Stackdriver API 获取指标。 The account has "Owner" rights on the project.该帐户对项目具有“所有者”权限。 I am getting the below error for all the Stackdriver API calls.我收到以下所有 Stackdriver API 调用的错误。 Other APIs like Spanner etc I am able to use the same service account.其他 API,如 Spanner 等,我可以使用相同的服务帐户。

com.google.api.gax.rpc.PermissionDeniedException: io.grpc.StatusRuntimeException: PERMISSION_DENIED: User is not authorized to access the project monitoring records.
        at com.google.api.gax.rpc.ApiExceptionFactory.createException(ApiExceptionFactory.java:55) ~[gax-1.16.0.jar:1.16.0]
        at com.google.api.gax.grpc.GrpcExceptionCallable$ExceptionTransformingFuture.setException(GrpcExceptionCallable.java:118) ~[gax-grpc-1.16.0.jar:1.16.0]
        at com.google.api.gax.grpc.GrpcExceptionCallable$ExceptionTransformingFuture.onFailure(GrpcExceptionCallable.java:101) ~[gax-grpc-1.16.0.jar:1.16.0]
        at com.google.api.core.ApiFutures$1.onFailure(ApiFutures.java:61) ~[api-common-1.2.0.jar:na]
        at com.google.common.util.concurrent.Futures$4.run(Futures.java:1123) ~[guava-20.0.jar:na]
        at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:435) ~[guava-20.0.jar:na]
        at com.google.common.util.concurrent.AbstractFuture.executeListener(AbstractFuture.java:900) ~[guava-20.0.jar:na]
        at com.google.common.util.concurrent.AbstractFuture.complete(AbstractFuture.java:811) ~[guava-20.0.jar:na]
        at com.google.common.util.concurrent.AbstractFuture.setException(AbstractFuture.java:675) ~[guava-20.0.jar:na]
        at io.grpc.stub.ClientCalls$GrpcFuture.setException(ClientCalls.java:492) ~[grpc-stub-1.9.0.jar:1.9.0]
        at io.grpc.stub.ClientCalls$UnaryStreamToFuture.onClose(ClientCalls.java:467) ~[grpc-stub-1.9.0.jar:1.9.0]
        at io.grpc.ForwardingClientCallListener.onClose(ForwardingClientCallListener.java:41) ~[grpc-core-1.9.0.jar:1.9.0]
        at io.grpc.internal.CensusStatsModule$StatsClientInterceptor$1$1.onClose(CensusStatsModule.java:684) ~[grpc-core-1.9.0.jar:1.9.0]
        at io.grpc.ForwardingClientCallListener.onClose(ForwardingClientCallListener.java:41) ~[grpc-core-1.9.0.jar:1.9.0]
        at io.grpc.internal.CensusTracingModule$TracingClientInterceptor$1$1.onClose(CensusTracingModule.java:392) ~[grpc-core-1.9.0.jar:1.9.0]
        at io.grpc.internal.ClientCallImpl.closeObserver(ClientCallImpl.java:475) ~[grpc-core-1.9.0.jar:1.9.0]
        at io.grpc.internal.ClientCallImpl.access$300(ClientCallImpl.java:63) ~[grpc-core-1.9.0.jar:1.9.0]
        at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.close(ClientCallImpl.java:557) ~[grpc-core-1.9.0.jar:1.9.0]
        at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.access$600(ClientCallImpl.java:478) ~[grpc-core-1.9.0.jar:1.9.0]
        at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInContext(ClientCallImpl.java:590) ~[grpc-core-1.9.0.jar:1.9.0]
        at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37) ~[grpc-core-1.9.0.jar:1.9.0]
        at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:123) ~[grpc-core-1.9.0.jar:1.9.0]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[na:1.8.0_161]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_161]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) ~[na:1.8.0_161]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) ~[na:1.8.0_161]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[na:1.8.0_161]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[na:1.8.0_161]
        at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_161]
    Caused by: io.grpc.StatusRuntimeException: PERMISSION_DENIED: User is not authorized to access the project monitoring records.
        at io.grpc.Status.asRuntimeException(Status.java:526) ~[grpc-core-1.9.0.jar:1.9.0]
        ... 19 common frames omitted

I have set the environment variable GOOGLE_APPLICATION_CREDENTIALS to point to the the service account private key json.我已将环境变量 GOOGLE_APPLICATION_CREDENTIALS 设置为指向服务帐户私钥 json。

export GOOGLE_APPLICATION_CREDENTIALS="/home/subhro/workspace/7193_spanner.json"

The metrics I am trying to retrieve are我要检索的指标是

  • spanner.googleapis.com/api/request_count spanner.googleapis.com/api/request_count
  • spanner.googleapis.com/instance/storage/used_byte spanner.googleapis.com/instance/storage/used_byte
  • spanner.googleapis.com/instance/cpu/utilization spanner.googleapis.com/instance/cpu/utilization
  • spanner.googleapis.com/instance/node_count spanner.googleapis.com/instance/node_count

My gradle build has the following deps:我的 gradle 版本具有以下部门:

compile('com.google.guava:guava:20.0')
compile('com.google.cloud:google-cloud-spanner:0.33.0-beta'){
    exclude group: 'com.google.guava', module: 'guava'
}
compile('com.google.cloud:google-cloud-monitoring:0.33.0-beta'){
    exclude group: 'com.google.guava', module: 'guava'
}
compile('com.google.api-client:google-api-client:1.23.0'){
    exclude group: 'com.google.guava', module: 'guava'
}

Has some also faced this same issue?有些人也面临同样的问题吗? Please help.请帮忙。

Check that the configured projectId matches your GCP project id.检查配置的 projectId 是否与您的 GCP 项目 ID 匹配。

On the GCP console, near top-left there is a drop-down to select your project.在 GCP 控制台上,靠近左上角有一个下拉菜单,指向您的项目 select。 Then Cloud overview > dashboard > Project ID然后 Cloud overview > dashboard > Project ID

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM