首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Http代替默认的gRPC用于google监视API

如何使用Http代替默认的gRPC用于google监视API
EN

Stack Overflow用户
提问于 2019-09-25 16:12:50
回答 2查看 783关注 0票数 4

我试图通过使用java客户端库来使用google监视API来获得堆栈驱动程序度量。我的代码如下:

代码语言:javascript
复制
MetricServiceSettings{executorProvider=I> ProjectName name = ProjectName.of(projectId)

// Restrict time to last 'cpuCheckRange' minutes
long startMillis = System.currentTimeMillis() - MS_IN_MIN * cpuCheckRange - 1
TimeInterval interval = TimeInterval.newBuilder()
        .setStartTime(Timestamps.fromMillis(startMillis))
        .setEndTime(Timestamps.fromMillis(System.currentTimeMillis()))
        .build()

Aggregation aggregation = Aggregation.newBuilder()
        .setAlignmentPeriod(Duration.newBuilder().setSeconds(SEC_IN_MIN * cpuCheckRange).build())
        .setPerSeriesAligner(Aggregation.Aligner.ALIGN_MEAN)
        .build()

ListTimeSeriesRequest.Builder requestBuilder = ListTimeSeriesRequest.newBuilder()
        .setName(name.toString())
        .setFilter("metric.type=\"spanner.googleapis.com/instance/cpu/utilization\" resource.type=\"spanner_instance\" resource.label.\"instance_id\"=\"$instanceId\"")
        .setInterval(interval)
        .setAggregation(aggregation)

ListTimeSeriesRequest request = requestBuilder.build()

TimeSeries timeSeries = null
MetricServiceClient metricServiceClient = null
try {

    metricServiceClient = MetricServiceClient.create()
    ListTimeSeriesPagedResponse response = metricServiceClient.listTimeSeries(request)

    for (TimeSeries ts : response.iterateAll()) {
        MonitoredResource resource = ts.getResource()
        Metric metric = ts.getMetric()

        if (metric.getType() == "spanner.googleapis.com/instance/cpu/utilization"
                && resource.getType() == "spanner_instance"
                && resource.getLabelsOrDefault("project_id", "") == projectId
                && resource.getLabelsOrDefault("instance_id", "") == instanceId) {
            timeSeries = ts
            break
        }
    }
} finally {
    if (metricServiceClient != null) {
        metricServiceClient.close()
    }
}

它在本地工作,但出于某些原因,当我在码头容器中的jenkins中运行它时:

代码语言:javascript
复制
docker.image('katalonstudio/katalon:6.1.5').inside('-u root') {
............               
}

我得到了错误:

代码语言:javascript
复制
com.google.api.gax.rpc.DeadlineExceededException: io.grpc.StatusRuntimeException: DEADLINE_EXCEEDED: deadline exceeded after 19999685365ns. [buffered_nanos=19999833833, waiting_for_connection

我假设存在一些与gRPC相关的连接问题。那么,对于这个API,我如何使用http而不是gRPC呢?或者其他建议?

环境详情:

在码头容器'katalonstudio/katalon:6.1.5'

  • dependency:中运行的
  1. 代码

编译‘io.cuccess:黄瓜-pico容器:3.0.2’编译'com.google.code.gson:gson:2.8.5‘编译'org.jdom:jdom2:2.0.6’编译'jaxen:jaxen:1.1.6‘编译'org.apache.ant:ant-jsch:1.10.5’编译'com.google.cloud:google-cloud-monitoring:1.90.0‘编译'io.netty:netty-all:4.1.3.Final'

堆栈跟踪:

代码语言:javascript
复制
22:33:29  com.google.api.gax.rpc.DeadlineExceededException: io.grpc.StatusRuntimeException: DEADLINE_EXCEEDED: deadline exceeded after 19999701924ns. [buffered_nanos=19999820820, waiting_for_connection]
22:33:29    at com.google.api.gax.rpc.ApiExceptionFactory.createException(ApiExceptionFactory.java:51)
22:33:29    at com.google.api.gax.grpc.GrpcApiExceptionFactory.create(GrpcApiExceptionFactory.java:72)
22:33:29    at com.google.api.gax.grpc.GrpcApiExceptionFactory.create(GrpcApiExceptionFactory.java:60)
22:33:29    at com.google.api.gax.grpc.GrpcExceptionCallable$ExceptionTransformingFuture.onFailure(GrpcExceptionCallable.java:97)
22:33:29    at com.google.api.core.ApiFutures$1.onFailure(ApiFutures.java:68)
22:33:29    at com.google.common.util.concurrent.Futures$CallbackListener.run(Futures.java:1365)
22:33:29    at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)
22:33:29    at com.google.common.util.concurrent.AbstractFuture.executeListener(AbstractFuture.java:973)
22:33:29    at com.google.common.util.concurrent.AbstractFuture.complete(AbstractFuture.java:821)
22:33:29    at com.google.common.util.concurrent.AbstractFuture.setException(AbstractFuture.java:685)
22:33:29    at io.grpc.stub.ClientCalls$GrpcFuture.setException(ClientCalls.java:515)
22:33:29    at io.grpc.stub.ClientCalls$UnaryStreamToFuture.onClose(ClientCalls.java:490)
22:33:29    at io.grpc.PartialForwardingClientCallListener.onClose(PartialForwardingClientCallListener.java:39)
22:33:29    at io.grpc.ForwardingClientCallListener.onClose(ForwardingClientCallListener.java:23)
22:33:29    at io.grpc.ForwardingClientCallListener$SimpleForwardingClientCallListener.onClose(ForwardingClientCallListener.java:40)
22:33:29    at io.grpc.internal.CensusStatsModule$StatsClientInterceptor$1$1.onClose(CensusStatsModule.java:700)
22:33:29    at io.grpc.PartialForwardingClientCallListener.onClose(PartialForwardingClientCallListener.java:39)
22:33:29    at io.grpc.ForwardingClientCallListener.onClose(ForwardingClientCallListener.java:23)
22:33:29    at io.grpc.ForwardingClientCallListener$SimpleForwardingClientCallListener.onClose(ForwardingClientCallListener.java:40)
22:33:29    at io.grpc.internal.CensusTracingModule$TracingClientInterceptor$1$1.onClose(CensusTracingModule.java:399)
22:33:29    at io.grpc.internal.ClientCallImpl.closeObserver(ClientCallImpl.java:510)
22:33:29    at io.grpc.internal.ClientCallImpl.access$300(ClientCallImpl.java:66)
22:33:29    at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.close(ClientCallImpl.java:630)
22:33:29    at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.access$700(ClientCallImpl.java:518)
22:33:29    at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInternal(ClientCallImpl.java:692)
22:33:29    at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInContext(ClientCallImpl.java:681)
22:33:29    at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37)
22:33:29    at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:123)
22:33:29    at ?.Customers exists in the system(/tmp/katalon_execute/project/Include/features/OCS_SPANNER_diameter_event.feature:5)
22:33:29    Suppressed: com.google.api.gax.rpc.AsyncTaskException: Asynchronous task failed
22:33:29        at com.google.api.gax.rpc.ApiExceptions.callAndTranslateApiException(ApiExceptions.java:57)
22:33:29        at com.google.api.gax.rpc.UnaryCallable.call(UnaryCallable.java:112)
22:33:29        at com.google.cloud.monitoring.v3.MetricServiceClient.listTimeSeries(MetricServiceClient.java:995)
22:33:29        at com.google.cloud.monitoring.v3.MetricServiceClient$listTimeSeries$0.call(Unknown Source)
22:33:29        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
22:33:29        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
22:33:29        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
22:33:29        at com.optiva.CommonStepDefinition.getSpannerCpuUsage(CommonStepDefinition.groovy:744)
22:33:29        at com.optiva.CommonStepDefinition.checkSpannerCpuUsage(CommonStepDefinition.groovy:786)
22:33:29        at com.optiva.CommonStepDefinition.assertCustomers(CommonStepDefinition.groovy:117)
22:33:29        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
22:33:29        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
22:33:29        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
22:33:29        at java.lang.reflect.Method.invoke(Method.java:498)
22:33:29        at cucumber.runtime.Utils$1.call(Utils.java:26)
22:33:29        at cucumber.runtime.Timeout.timeout(Timeout.java:16)
22:33:29        at cucumber.runtime.Utils.invoke(Utils.java:20)
22:33:29        at cucumber.runtime.java.JavaStepDefinition.execute(JavaStepDefinition.java:48)
22:33:29        at cucumber.runtime.PickleStepDefinitionMatch.runStep(PickleStepDefinitionMatch.java:50)
22:33:29        at cucumber.runner.TestStep.executeStep(TestStep.java:55)
22:33:29        at cucumber.runner.TestStep.run(TestStep.java:42)
22:33:29        at cucumber.runner.PickleStepTestStep.run(PickleStepTestStep.java:53)
22:33:29        at cucumber.runner.TestCase.run(TestCase.java:47)
22:33:29        at cucumber.runner.Runner.runPickle(Runner.java:44)
22:33:29        at cucumber.runtime.Runtime.runFeature(Runtime.java:120)
22:33:29        at cucumber.runtime.Runtime.run(Runtime.java:106)
22:33:29        at cucumber.api.cli.Main.run(Main.java:35)
22:33:29        at cucumber.api.cli.Main$run.call(Unknown Source)
22:33:29        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
22:33:29        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
22:33:29        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)
22:33:29        at 
EN

回答 2

Stack Overflow用户

发布于 2019-09-25 17:45:33

此链接同时讨论了REST和grpc https://cloud.google.com/monitoring/api/v3/

但是Java库和gRPC应该可以工作(以及首选?)因此,最好对此进行调试,因为我不认为grpc和REST在连接需求方面有任何不同(除了http2和http)。您是否从码头容器的外壳发出卷曲以确保从那里连接?

票数 0
EN

Stack Overflow用户

发布于 2020-04-14 09:32:18

我从云运行服务内部使用云监视api,并且我自己观察到频繁的截止日期超过了错误:

代码语言:javascript
复制
com.google.api.gax.rpc.DeadlineExceededException: io.grpc.StatusRuntimeException: DEADLINE_EXCEEDED: deadline exceeded after 12.900875773s. [buffered_nanos=14900102827, waiting_for_connection]
at com.google.api.gax.rpc.ApiExceptionFactory.createException(ApiExceptionFactory.java:51)
at com.google.api.gax.grpc.GrpcApiExceptionFactory.create(GrpcApiExceptionFactory.java:72) 
at com.google.api.gax.grpc.GrpcApiExceptionFactory.create(GrpcApiExceptionFactory.java:60) 
at com.google.api.gax.grpc.GrpcExceptionCallable$ExceptionTransformingFuture.onFailure(GrpcExceptionCallable.java:97) 
at com.google.api.core.ApiFutures$1.onFailure(ApiFutures.java:68) 
at com.google.common.util.concurrent.Futures$CallbackListener.run(Futures.java:1072) 
at com.google.common.util.concurrent.DirectExecutor.execute(DirectExecutor.java:30) 
at com.google.common.util.concurrent.AbstractFuture.executeListener(AbstractFuture.java:1164) 
at com.google.common.util.concurrent.AbstractFuture.complete(AbstractFuture.java:958) 
at com.google.common.util.concurrent.AbstractFuture.setException(AbstractFuture.java:749) 
at io.grpc.stub.ClientCalls$GrpcFuture.setException(ClientCalls.java:522) 
at io.grpc.stub.ClientCalls$UnaryStreamToFuture.onClose(ClientCalls.java:497) 
at io.grpc.internal.ClientCallImpl.closeObserver(ClientCallImpl.java:426) 
at io.grpc.internal.ClientCallImpl.access$500(ClientCallImpl.java:66) 
at io.grpc.internal.ClientCallImpl$1CloseInContext.runInContext(ClientCallImpl.java:416) 
at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37) 
at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:123) 
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) 
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) 
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) 
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) 
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) 
at java.base/java.lang.Thread.run(Thread.java:834)

Suppressed: com.google.api.gax.rpc.AsyncTaskException: Asynchronous task failed
at com.google.api.gax.rpc.ApiExceptions.callAndTranslateApiException(ApiExceptions.java:57) 
at com.google.api.gax.rpc.UnaryCallable.call(UnaryCallable.java:112) 
at com.google.cloud.monitoring.v3.MetricServiceClient.createTimeSeries(MetricServiceClient.java:1145) 
at org.mernst.metrics.ExporterModule$1.lambda$runOneIteration$3(ExporterModule.java:98) 

从同样的任务中再试一次,往往会使它发挥作用。有时,在刚开始的任务中,它会立即生效。

com.google.cloud:google-cloud-monitoring:1.100.0,默认客户端选项。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58102604

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档