google-cloud-java icon indicating copy to clipboard operation
google-cloud-java copied to clipboard

Cloud Logging library does not work on Java Flex Compat

Open meltsufin opened this issue 9 years ago • 14 comments

protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    final PrintWriter out = resp.getWriter();

    LoggingOptions options = LoggingOptions.newBuilder().build();

    try (Logging logging = options.getService()) {


      LogEntry firstEntry = LogEntry
          .newBuilder(Payload.StringPayload.of("testing direct use of API"))
          .setLogName("test-log")
          .setResource(MonitoredResource.newBuilder("global")
              .addLabel("project_id", options.getProjectId())
              .build())
          .build();
      logging.write(Collections.singleton(firstEntry));

      Page<LogEntry> entries = logging.listLogEntries(
          Logging.EntryListOption
              .filter("logName=projects/" + options.getProjectId() + "/logs/test-log"));
      Iterator<LogEntry> entryIterator = entries.iterateAll();
      while (entryIterator.hasNext()) {
        System.out.println(entryIterator.next());
      }


    } catch (Exception e) {
      e.printStackTrace(out);
      e.printStackTrace();
    }
}
com.google.cloud.logging.LoggingException: io.grpc.StatusRuntimeException: UNKNOWN
	at com.google.cloud.logging.spi.DefaultLoggingRpc$1.apply(DefaultLoggingRpc.java:165)
	at com.google.cloud.logging.spi.DefaultLoggingRpc$1.apply(DefaultLoggingRpc.java:159)
	at com.google.api.gax.grpc.AbstractRpcFuture$2.apply(AbstractRpcFuture.java:65)
	at com.google.api.gax.grpc.AbstractRpcFuture$2.apply(AbstractRpcFuture.java:62)
	at com.google.common.util.concurrent.Futures$CatchingFuture.doFallback(Futures.java:842)
	at com.google.common.util.concurrent.Futures$CatchingFuture.doFallback(Futures.java:834)
	at com.google.common.util.concurrent.Futures$AbstractCatchingFuture.run(Futures.java:789)
	at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:456)
	at com.google.common.util.concurrent.AbstractFuture.executeListener(AbstractFuture.java:817)
	at com.google.common.util.concurrent.AbstractFuture.complete(AbstractFuture.java:753)
	at com.google.common.util.concurrent.AbstractFuture.setException(AbstractFuture.java:634)
	at com.google.common.util.concurrent.SettableFuture.setException(SettableFuture.java:53)
	at com.google.api.gax.grpc.BundlingFuture.setException(BundlingFuture.java:87)
	at com.google.api.gax.grpc.BundlingContext.sendResult(BundlingContext.java:97)
	at com.google.api.gax.grpc.BundleExecutor.processBundle(BundleExecutor.java:89)
	at com.google.api.gax.bundling.ThresholdBundlingForwarder$BundleForwardingRunnable.processBundle(ThresholdBundlingForwarder.java:106)
	at com.google.api.gax.bundling.ThresholdBundlingForwarder$BundleForwardingRunnable.run(ThresholdBundlingForwarder.java:89)
	at java.lang.Thread.run(Thread.java:745)
Caused by: com.google.api.gax.grpc.ApiException: io.grpc.StatusRuntimeException: UNKNOWN
	at com.google.api.gax.grpc.ExceptionTransformingCallable$ExceptionTransformingFuture.onFailure(ExceptionTransformingCallable.java:107)
	at com.google.api.gax.grpc.ListenableFutureDelegate$1.onFailure(ListenableFutureDelegate.java:52)
	at com.google.common.util.concurrent.Futures$6.run(Futures.java:1764)
	at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:456)
	at com.google.common.util.concurrent.AbstractFuture.executeListener(AbstractFuture.java:817)
	at com.google.common.util.concurrent.AbstractFuture.addListener(AbstractFuture.java:595)
	at com.google.common.util.concurrent.ForwardingListenableFuture.addListener(ForwardingListenableFuture.java:47)
	at com.google.common.util.concurrent.Futures.addCallback(Futures.java:1776)
	at com.google.common.util.concurrent.Futures.addCallback(Futures.java:1713)
	at com.google.api.gax.grpc.ListenableFutureDelegate.addCallback(ListenableFutureDelegate.java:47)
	at com.google.api.gax.grpc.ExceptionTransformingCallable.futureCall(ExceptionTransformingCallable.java:63)
	at com.google.api.gax.grpc.RetryingCallable$RetryingResultFuture.issueCall(RetryingCallable.java:214)
	at com.google.api.gax.grpc.RetryingCallable.futureCall(RetryingCallable.java:82)
	at com.google.api.gax.grpc.UnaryCallable.futureCall(UnaryCallable.java:243)
	at com.google.api.gax.grpc.UnaryCallable.futureCall(UnaryCallable.java:254)
	at com.google.api.gax.grpc.UnaryCallable.call(UnaryCallable.java:282)
	at com.google.api.gax.grpc.BundleExecutor.processBundle(BundleExecutor.java:82)
	... 3 more
Caused by: io.grpc.StatusRuntimeException: UNKNOWN
	at io.grpc.Status.asRuntimeException(Status.java:545)
	at io.grpc.stub.ClientCalls$UnaryStreamToFuture.onClose(ClientCalls.java:442)
	at io.grpc.ClientInterceptors$CheckedForwardingClientCall.start(ClientInterceptors.java:203)
	at io.grpc.ForwardingClientCall.start(ForwardingClientCall.java:47)
	at com.google.api.gax.grpc.HeaderInterceptor$1.start(HeaderInterceptor.java:62)
	at io.grpc.stub.ClientCalls.startCall(ClientCalls.java:273)
	at io.grpc.stub.ClientCalls.asyncUnaryRequestCall(ClientCalls.java:252)
	at io.grpc.stub.ClientCalls.futureUnaryCall(ClientCalls.java:189)
	at com.google.api.gax.grpc.DirectCallable.futureCall(DirectCallable.java:58)
	at com.google.api.gax.grpc.ExceptionTransformingCallable.futureCall(ExceptionTransformingCallable.java:60)
	... 9 more
Caused by: java.lang.IllegalStateException: Request threads can only be created within the context of a running request.
	at com.google.appengine.repackaged.com.google.common.base.Preconditions.checkState(Preconditions.java:446)
	at com.google.apphosting.vmruntime.VmRequestThreadFactory.newThread(VmRequestThreadFactory.java:79)
	at com.google.common.util.concurrent.ThreadFactoryBuilder$1.newThread(ThreadFactoryBuilder.java:162)
	at java.util.concurrent.ThreadPoolExecutor$Worker.<init>(ThreadPoolExecutor.java:612)
	at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:925)
	at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1368)
	at io.grpc.internal.DnsNameResolver.resolve(DnsNameResolver.java:202)
	at io.grpc.internal.DnsNameResolver.start(DnsNameResolver.java:120)
	at io.grpc.internal.ManagedChannelImpl$1NameResolverStartTask.run(ManagedChannelImpl.java:268)
	at io.grpc.internal.ManagedChannelImpl.exitIdleModeAndGetLb(ManagedChannelImpl.java:233)
	at io.grpc.internal.ManagedChannelImpl$2.get(ManagedChannelImpl.java:310)
	at io.grpc.internal.ClientCallImpl.start(ClientCallImpl.java:213)
	at io.grpc.auth.ClientAuthInterceptor$1.checkedStart(ClientAuthInterceptor.java:104)
	at io.grpc.ClientInterceptors$CheckedForwardingClientCall.start(ClientInterceptors.java:195)
	... 16 more

Note, I'm using a custom Dockerfile:

FROM gcr.io/google-appengine/jetty9-compat:githubheadasync
ADD . /app/

I think the problem stems from the library trying to use com.google.apphosting.vmruntime.VmRequestThreadFactory that is configured in the compat runtime.

GRPC is checking for the com.google.appengine.runtime.environment system property and is going into the App Engine branch.

Interestingly, if I clear the system property with System.clearProperty("com.google.appengine.runtime.environment"), logging seems to work, but that's just a hack.

@garrettjonesgoogle @ludoch @gregw

meltsufin avatar Feb 07 '17 21:02 meltsufin

We should also test it on GAE Standard (Java7 and Java8) and fix whatever issues we see there... Who is supposed to test cloud-java on GAE standard?

ludoch avatar Feb 07 '17 21:02 ludoch

We should figure out the right way to check and get everyone on the same page.

lesv avatar Feb 07 '17 22:02 lesv

Should I move forward on the branch https://github.com/GoogleCloudPlatform/jetty-runtime/pull/81 to add in testing for remote logging - ie were we have tests that should log and use the API to verify the logs were received OK?

gregw avatar Feb 08 '17 03:02 gregw

@gregw I think on the jetty-runtime side, we should make sure that our default logging configuration works for sending logs to Stackdriver with the metadata. However, I don't think it's a good place for testing just whether the logging API works on Flex.

meltsufin avatar Feb 08 '17 15:02 meltsufin

Does this block GA?

garrettjonesgoogle avatar Feb 09 '17 19:02 garrettjonesgoogle

Mike can say for sure, but I think so.

lesv avatar Feb 09 '17 21:02 lesv

Yes, I would say so.

meltsufin avatar Feb 09 '17 22:02 meltsufin

@jabubake Can you look at this.

lesv avatar Mar 13 '17 22:03 lesv

@meltsufin could you see if this is still an issue? We have upgraded to a newer grpc (1.0.3 -> 1.2.0).

garrettjonesgoogle avatar Apr 13 '17 23:04 garrettjonesgoogle

Will do.

meltsufin avatar Apr 14 '17 17:04 meltsufin

com.google.cloud.logging.LoggingException: java.lang.NullPointerException
	at com.google.cloud.logging.LoggingOptions$DefaultLoggingRpcFactory.create(LoggingOptions.java:65)
	at com.google.cloud.logging.LoggingOptions$DefaultLoggingRpcFactory.create(LoggingOptions.java:57)
	at com.google.cloud.ServiceOptions.getRpc(ServiceOptions.java:450)
	at com.google.cloud.logging.LoggingOptions.getLoggingRpcV2(LoggingOptions.java:132)
	at com.google.cloud.logging.LoggingImpl.<init>(LoggingImpl.java:96)
	at com.google.cloud.logging.LoggingOptions$DefaultLoggingFactory.create(LoggingOptions.java:45)
	at com.google.cloud.logging.LoggingOptions$DefaultLoggingFactory.create(LoggingOptions.java:40)
	at com.google.cloud.ServiceOptions.getService(ServiceOptions.java:441)
	at com.test.LogServlet.doGet(LogServlet.java:27)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:837)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1689)
	at com.google.apphosting.utils.servlet.ParseBlobUploadFilter.doFilter(ParseBlobUploadFilter.java:125)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1676)
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:581)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:524)
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:226)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1160)
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:511)
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1092)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
	at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:213)
	at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:119)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:134)
	at org.eclipse.jetty.server.Server.handle(Server.java:518)
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:308)
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:244)
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:273)
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95)
	at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:93)
	at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceAndRun(ExecuteProduceConsume.java:246)
	at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:156)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:654)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:572)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.IOException: java.lang.NullPointerException
	at com.google.cloud.logging.spi.v2.GrpcLoggingRpc.<init>(GrpcLoggingRpc.java:121)
	at com.google.cloud.logging.LoggingOptions$DefaultLoggingRpcFactory.create(LoggingOptions.java:63)
	... 37 more
Caused by: java.lang.NullPointerException
	at com.google.cloud.logging.spi.v2.GrpcLoggingRpc.<init>(GrpcLoggingRpc.java:86)
	... 38 more

with this code:

  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    final PrintWriter out = resp.getWriter();

    LoggingOptions options = LoggingOptions.newBuilder().build();

    try (Logging logging = options.getService()) {


      LogEntry firstEntry = LogEntry
          .newBuilder(Payload.StringPayload.of("testing direct use of API"))
          .setLogName("test-log")
          .setResource(MonitoredResource.newBuilder("global")
              .addLabel("project_id", options.getProjectId())
              .build())
          .build();
      logging.write(Collections.singleton(firstEntry));

      Page<LogEntry> entries = logging.listLogEntries(
          Logging.EntryListOption
              .filter("logName=projects/" + options.getProjectId() + "/logs/test-log"));
      Iterable<LogEntry> entryIterator = entries.iterateAll();
      for (LogEntry logEntry : entryIterator) {
        System.out.println(logEntry);
      }


    } catch (Exception e) {
      e.printStackTrace(out);
      e.printStackTrace();
    }
  }

meltsufin avatar Apr 14 '17 21:04 meltsufin

It looks like options.getCredentials is returning null:

      if (options.getHost().contains("localhost")
          || options.getCredentials().equals(NoCredentials.getInstance())) {

I think this is exactly the issue in https://github.com/GoogleCloudPlatform/google-cloud-java/issues/1565 .

garrettjonesgoogle avatar Apr 17 '17 15:04 garrettjonesgoogle

Assigning to @neozwu since the cause is likely to be https://github.com/GoogleCloudPlatform/google-cloud-java/issues/1565 , which is already assigned to him.

garrettjonesgoogle avatar Apr 19 '17 00:04 garrettjonesgoogle

Withi this PR #1961, NPE error should be fixed.

neozwu avatar Apr 24 '17 16:04 neozwu