我正在尝试使用 google 监控 API 通过使用 java 客户端库来获取 stackdriver 指标。我的代码如下:
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()
}
}
它在本地工作,但由于某些原因,当我在 docker 容器内的 jenkins 中运行它时:
docker.image('katalonstudio/katalon:6.1.5').inside('-u root') {
............
}
我得到错误:
com.google.api.gax.rpc.DeadlineExceededException: io.grpc.StatusRuntimeException: DEADLINE_EXCEEDED: deadline exceeded after 19999685365ns. [buffered_nanos=19999833833, waiting_for_connection
我假设存在一些与 gRPC 相关的连接问题。那么我该如何使用 http 而不是 gRPC 来实现这个 API 呢?或任何其他建议?
环境细节:
- 在 docker 容器 'katalonstudio/katalon:6.1.5' 中运行的代码
依赖:
编译'io.cucumber:cucumber-picocontainer: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.最后'
堆栈跟踪:
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