Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix prometheus interceptors not converting context errors to gRPC codes #571

Conversation

vtermanis
Copy link
Contributor

@vtermanis vtermanis commented Apr 21, 2023

First of all - thank you for a great library!


  • I added CHANGELOG entry for this change. (I don't see a changelog file - what am I missing?)
  • Change is not relevant to the end user.

Changes

fix prometheus interceptors not converting context errors to gRPC codes

  • Previously context.(Canceled|DeadlineExceeded) would result in an "Unknown" grpc_code.

We use the interceptors to not only track failures but also identify when we've accidentally passed back non-grpc errors. With this fix the context errors are correctly mapped to their gRPS status counterparts. This behaves the same as what happens in the golang server code. Something similar but old existed in your deprecated repo (grpc-ecosystem/go-grpc-prometheus#84) but it was never released nor did it make it across, it would appear.

Verification

Added unit test which triggers context.Canceled to verify it's no longer recorded as grpc_code="Unknown"

@google-cla
Copy link

google-cla bot commented Apr 21, 2023

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link
Collaborator

@johanbrandhorst johanbrandhorst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, could you make this change against v2? v1 is kinda maintenance mode.

@vtermanis vtermanis force-pushed the fix-context-error-status-handling branch from d80851e to e4751c0 Compare May 3, 2023 20:10
@vtermanis vtermanis changed the base branch from main to v2 May 3, 2023 20:10
@vtermanis
Copy link
Contributor Author

vtermanis commented May 3, 2023

@johanbrandhorst - is this what you meant? (I didn't realise v2 branch was current given main also had activity on it)

Edit: But how does that work with the releases for the prometheus interceptor - e.g. here it's against the main branch not v2 - from what I can tell. How will that work with the v2 branch? (Or maybe I'm missing something obvious.)

@vtermanis
Copy link
Contributor Author

The unit & lint test checks don't run for some reason. Any chance one of the maintainers could take a look why that is? (I don't believe I have access to see.)

@vtermanis
Copy link
Contributor Author

@johanbrandhorst - apologies for the ping but it would be great to for this to be considered.

The unit & lint test checks don't run for some reason (they do pass). Any chance you or one of the maintainers could take a look why that is? (I don't believe I have access to see/re-run the tests)

@johanbrandhorst
Copy link
Collaborator

@johanbrandhorst - apologies for the ping but it would be great to for this to be considered.

The unit & lint test checks don't run for some reason (they do pass). Any chance you or one of the maintainers could take a look why that is? (I don't believe I have access to see/re-run the tests)

Sorry to have missed this - we merged v2 into main so this should be targeted at main now. Please update again 😅.

@vtermanis vtermanis force-pushed the fix-context-error-status-handling branch from e4751c0 to 8779b13 Compare June 23, 2023 17:28
@vtermanis vtermanis changed the base branch from v2 to main June 23, 2023 17:29
@vtermanis vtermanis force-pushed the fix-context-error-status-handling branch from 8779b13 to 87b051a Compare June 23, 2023 17:32
@vtermanis
Copy link
Contributor Author

note: Do not merge - the added failing test still shows the suite as passing (which obv. is wrong). I'll try to figure out what is wrong.

@vtermanis vtermanis marked this pull request as draft June 23, 2023 17:45
- Previously context.(Canceled|DeadlineExceeded) would result in an
  "Unknown" grpc_code
@vtermanis vtermanis force-pushed the fix-context-error-status-handling branch from 87b051a to a5213e5 Compare June 23, 2023 21:18
@vtermanis
Copy link
Contributor Author

Ok, now it passes:

  • Corrected labels to use bidi_stream (instead of server_stream)
  • Fixed typo of Canceled (was Cancelled)

Ready for review

@vtermanis vtermanis marked this pull request as ready for review June 23, 2023 21:21
@johanbrandhorst johanbrandhorst merged commit e895693 into grpc-ecosystem:main Jun 28, 2023
6 checks passed
@johanbrandhorst
Copy link
Collaborator

Thanks for your contribution!

@vtermanis vtermanis deleted the fix-context-error-status-handling branch July 24, 2023 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants