question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Server metrics are tagged with the wrong status codes

See original GitHub issue

The context

I’d like to get the metric values for grpc.server.processing.duration and distinguish different status codes, e.g. OK, NOT_FOUND, INVALID_ARGUMENT, UNKNOWN

The bug

If my gRPC service is called three times, and it responds twice with an OK status and once with with an NOT_FOUND status, I’d expect the tags that are captured for the metrics grpc.server.processing.duration to be “OK” and “NOT_FOUND”. But instead, the “NOT_FOUND” error seems to be reported as an “UNKNOWN” error.

Stacktrace and logs

I don’t know

Steps to Reproduce

I created a very simple example project, with one gRPC service and one GrpcAdvice that translates my “business” exception into a NOT_FOUND status.

Please check out the integration test, that shows how to reproduce the issue: https://github.com/harti2006/grpc-metrics-demo/blob/trunk/src/test/java/com/github/harti2006/grpc/metrics/GrpcMetricsDemoApplicationTests.java

The application’s environment

Which versions do you use?

  • Spring (boot): 2.7.5
  • grpc-java: 1.51.0
  • grpc-spring-boot-starter: 2.14.0.RELEASE
  • java: 11

Additional context

  • It used to work fine with the previous release 2.13.1.RELEASE. When downgrading to this version, the above mentioned integration test works fine

Issue Analytics

  • State:open
  • Created 10 months ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
harti2006commented, Nov 24, 2022

Yeah, I found these places while debugging the problem. And I saw that funny behavior: The responseCode is only updated in the close method, but that method was only called when the grpc handler method completed successfully. On errors, the close method wasn’t called at all, so the default value “UNKNOWN” was reported. Tomorrow, I will be able to add another case to my example to verify if this happens only when using the GrpcAdvice approach of sending errors, or if it’s a general problem.

0reactions
harti2006commented, Nov 25, 2022

Thanks for investigating. As promised I added another case to the example project where I send the exception directly via streamObserver:

responseObserver.onError(Status.NOT_FOUND.withDescription("goodbye message not found").asException());

I did the same test as before and with this approach, the metrics were reported correctly. See https://github.com/harti2006/grpc-metrics-demo/blob/933c29641a3c813db649cdd275ba022e08637820/src/test/java/com/github/harti2006/grpc/metrics/GrpcMetricsDemoApplicationTests.java#L72

I also tried your suggestion with changing the order of the MetricCollectingServerInterceptor bean, but it made things even worse: No metrics were reported at all.

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTTP Status Codes List | HTTP Error Codes Explained
Learn about all the HTTP status codes. Read about the HTTP status codes and their descriptions. Quickly understand client and server errors.
Read more >
HTTP Status Codes, Network and DNS Errors, and Google ...
This page describes how different HTTP status codes, network errors, and DNS errors affect Google Search. We cover the top 20 status codes...
Read more >
What are HTTP Status Codes? List Of Important Status ... - Moz
An HTTP status code is a server response to a browser's request. When you visit a website, your browser sends a request to...
Read more >
List of HTTP status codes - Wikipedia
4xx client error – the request contains bad syntax or cannot be fulfilled; 5xx server error – the server failed to fulfil an...
Read more >
HTTP Status Codes and SEO: what you need to know
HTTP status codes are three-digit responses that a server returns at the request of a client (a browser or search engine). There are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found