Skip to content
This repository has been archived by the owner on Dec 23, 2023. It is now read-only.

gRPC RealTimeMetrics values not populated #2081

Open
jordanwu97 opened this issue Aug 4, 2021 · 0 comments
Open

gRPC RealTimeMetrics values not populated #2081

jordanwu97 opened this issue Aug 4, 2021 · 0 comments
Labels

Comments

@jordanwu97
Copy link

Please answer these questions before submitting a bug report.

What version of OpenCensus are you using?

0.28.0

What JVM are you using (java -version)?

openjdk version "11.0.2" 2019-01-15

What did you do?

Use RpcViews.registerRealTimeMetricsViews() with https://github.com/grpc/grpc-java/tree/v1.39.0/examples

I cloned the above repo, and applied this patch

diff --git a/examples/pom.xml b/examples/pom.xml
index 156b11fb7..571b49c5c 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -18,6 +18,7 @@
     <!-- required for jdk9 -->
     <maven.compiler.source>1.7</maven.compiler.source>
     <maven.compiler.target>1.7</maven.compiler.target>
+    <opencensus.version>0.28.0</opencensus.version>
   </properties>
 
   <dependencyManagement>
@@ -46,6 +47,40 @@
       <groupId>io.grpc</groupId>
       <artifactId>grpc-stub</artifactId>
     </dependency>
+
+<!--    Census -->
+    <dependency>
+      <groupId>io.grpc</groupId>
+      <artifactId>grpc-census</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>io.opencensus</groupId>
+      <artifactId>opencensus-exporter-stats-prometheus</artifactId>
+      <version>${opencensus.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>io.opencensus</groupId>
+      <artifactId>opencensus-api</artifactId>
+      <version>${opencensus.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>io.opencensus</groupId>
+      <artifactId>opencensus-contrib-grpc-metrics</artifactId>
+      <version>${opencensus.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>io.opencensus</groupId>
+      <artifactId>opencensus-impl</artifactId>
+      <version>${opencensus.version}</version>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>io.prometheus</groupId>
+      <artifactId>simpleclient_httpserver</artifactId>
+      <version>0.3.0</version>
+    </dependency>
+<!--    -->
+
     <dependency>
       <groupId>com.google.protobuf</groupId>
       <artifactId>protobuf-java-util</artifactId>
diff --git a/examples/src/main/java/io/grpc/examples/routeguide/RouteGuideServer.java b/examples/src/main/java/io/grpc/examples/routeguide/RouteGuideServer.java
index c91544ae4..cd7a3b1ee 100644
--- a/examples/src/main/java/io/grpc/examples/routeguide/RouteGuideServer.java
+++ b/examples/src/main/java/io/grpc/examples/routeguide/RouteGuideServer.java
@@ -28,6 +28,10 @@ import static java.util.concurrent.TimeUnit.NANOSECONDS;
 import io.grpc.Server;
 import io.grpc.ServerBuilder;
 import io.grpc.stub.StreamObserver;
+import io.opencensus.contrib.grpc.metrics.RpcViews;
+import io.opencensus.exporter.stats.prometheus.PrometheusStatsCollector;
+import io.prometheus.client.exporter.HTTPServer;
+
 import java.io.IOException;
 import java.net.URL;
 import java.util.ArrayList;
@@ -49,6 +53,17 @@ public class RouteGuideServer {
   private final int port;
   private final Server server;
 
+  static {
+      RpcViews.registerServerGrpcViews();
+      RpcViews.registerRealTimeMetricsViews();
+      PrometheusStatsCollector.createAndRegister();
+      try {
+          HTTPServer s = new HTTPServer("localhost", 8888, true);
+      } catch (IOException e) {
+          throw new RuntimeException(e);
+      }
+  }
+
   public RouteGuideServer(int port) throws IOException {
     this(port, RouteGuideUtil.getDefaultFeaturesFile());
   }
-- 
2.24.3 (Apple Git-128)

Started the server with

mvn exec:java -Dexec.mainClass=io.grpc.examples.routeguide.RouteGuideServer

Then the client

mvn exec:java -Dexec.mainClass=io.grpc.examples.routeguide.RouteGuideClient

Curled the prometheus endpoint

curl localhost:8888

What did you expect to see?

The counter grpc_io_server_received_messages_per_method having some value for the client-streaming / server-streaming methods.

What did you see instead?

The *_per_method counters are empty / no value. Only the #HELP... and #TYPE... shows up.

$ curl -s localhost:8888 | grep per_method
# HELP grpc_io_client_sent_bytes_per_method Sent bytes per method
# TYPE grpc_io_client_sent_bytes_per_method counter
# HELP grpc_io_client_received_bytes_per_method Received bytes per method
# TYPE grpc_io_client_received_bytes_per_method counter
# HELP grpc_io_client_sent_messages_per_method Number of messages sent
# TYPE grpc_io_client_sent_messages_per_method counter
# HELP grpc_io_client_received_messages_per_method Number of messages received
# TYPE grpc_io_client_received_messages_per_method counter
# HELP grpc_io_server_sent_bytes_per_method Sent bytes per method
# TYPE grpc_io_server_sent_bytes_per_method counter
# HELP grpc_io_server_received_bytes_per_method Received bytes per method
# TYPE grpc_io_server_received_bytes_per_method counter
# HELP grpc_io_server_sent_messages_per_method Number of messages sent
# TYPE grpc_io_server_sent_messages_per_method counter
# HELP grpc_io_server_received_messages_per_method Number of messages received
# TYPE grpc_io_server_received_messages_per_method counter

All other grpc_io_server_* metrics show up and have values.

$ curl -s localhost:8888 | grep grpc_io_server_received_messages_per_rpc_count
grpc_io_server_received_messages_per_rpc_count{grpc_server_method="routeguide.RouteGuide/ListFeatures",} 1.0
grpc_io_server_received_messages_per_rpc_count{grpc_server_method="routeguide.RouteGuide/RouteChat",} 1.0
grpc_io_server_received_messages_per_rpc_count{grpc_server_method="routeguide.RouteGuide/GetFeature",} 2.0
grpc_io_server_received_messages_per_rpc_count{grpc_server_method="routeguide.RouteGuide/RecordRoute",} 1.0

Additional context

N/A

@jordanwu97 jordanwu97 added the bug label Aug 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant