-
Notifications
You must be signed in to change notification settings - Fork 13
add code snippet for Watch API #137
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
Conversation
9b3e0b0 to
f915ccd
Compare
tstirrat15
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we either put it in the examples directory or additionally put it in the examples dir? https://github.com/authzed/authzed-java/tree/main/examples/v1
|
@tstirrat15 why "additionally"? What value does having it in the "examples" directory bring? Personal opinion, but it seems quite hidden |
f915ccd to
393cf64
Compare
README.md
Outdated
| } | ||
| ``` | ||
|
|
||
| ### Calling `Watch` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we perhaps move this to the examples directory so it can be compiled and updated as needed? Then we can link the example from the readme. Same for check permissions.
README.md
Outdated
| builder.setOptionalStartCursor(lastZedToken); | ||
| } | ||
|
|
||
| WatchRequest request = builder.build(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest enabling heartbeats. This solves the confusion around idle timeouts and long-lived gRPC streaming APIs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to update the API first.
README.md
Outdated
|
|
||
| } catch (Exception e) { | ||
| if (e instanceof StatusRuntimeException sre && sre.getStatus().getCode().equals(Status.UNAVAILABLE.getCode()) && | ||
| (sre.getMessage().contains("stream timeout") || sre.getMessage().contains("RST_STREAM closed stream"))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't be checking the message to trigger retries - these could be subject to change. I assume those have INTERNAL grpc code, so those are safe to be retried.
In addition to this manual handling, we could add retry policies, which is built into the Java gRPC SDK. Please note that retry policies are only supported for server-streaming APIs (like the Watch API), but are not supported for client-streaming and bidirectional APIs. I'm also not fully sure server-streaming is retried once data has been streamed back to the client.
|
@miparnisari i realize that it isn't often a place you would look, but when it's in a |
a13c387 to
fa39172
Compare
7add8f9 to
6095dc4
Compare
6095dc4 to
f239482
Compare
|
|
||
| } catch (Exception e) { | ||
| if (e instanceof StatusRuntimeException sre && (sre.getStatus().getCode().equals(Status.UNAVAILABLE.getCode()) || | ||
| (sre.getStatus().getCode().equals(Status.INTERNAL.getCode())) && sre.getMessage().contains("stream timeout"))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO we should just do this on the Internal code alone
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't we also retry on Unavailable?
ecordell
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, with the caveat I haven't run this locally myself. But we can follow up if we find issues.
Description
Streaming APIs such as Watch can get disconnected. This PR provides a code snippet that can be used to automatically re-connect.
Testing
Locally, with https://github.com/miparnisari/authzed-java-client-test