grpc-spring-boot-starter icon indicating copy to clipboard operation
grpc-spring-boot-starter copied to clipboard

Expose Metric Counter for Number of Received/Sent Stream Messages

Open jGleitz opened this issue 2 years ago • 2 comments

When using GRPC streams, it’s interesting to see how many messages are sent/received on the stream(s). It would be great if this starter offered such a metric by default. Ideally, this would work analogous to how the grpc.server.calls timer is constructed For example, the new metrics should also consult RequestAwareGRpcMetricsTagsContributor. There should probably also be an analogous ResponseAwareGRpcMetricsTagsContributor.

From my point of view, the new counters will only be necessary on client stream, server stream and bidi requests. For unary requests, the counter of grpc.server.call already gives the number of transfered requests and responses. Hence, the new metrics could be called something like grpc.server.stream.messages.received and grpc.server.stream.messages.sent.

There already is a MetricCollectingServerInterceptor from Micrometer. However, I suspect re-using that will be more complicated than rolling a custom one in this repository.

jGleitz avatar Feb 21 '22 15:02 jGleitz

However, I suspect re-using that will be more complicated than rolling a custom one in this repository.

Have you tried to simply add it as a @Bean @GRpcGlobalInterceptor :

@Configuration
 public class MyConfig{
     @Bean
     @GRpcGlobalInterceptor
     public  ServerInterceptor metricsInterceptor(MeterRegistry registry){
         return new MetricCollectingServerInterceptor(registry);
     }
 }

jvmlet avatar Feb 23 '22 12:02 jvmlet

I have. This is what we are currently using and it is providing metrics. However, we want to add tags depending on the request or response. This is not possible with the Micrometer interceptor

Hence our requirement to integrate with RequestAwareGRpcMetricsTagsContributors.

jGleitz avatar Feb 23 '22 16:02 jGleitz