-
Notifications
You must be signed in to change notification settings - Fork 68
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
CosmosStore: Cleanup Cosmos calls #303
Conversation
I couldn't help pulling at the thread ;) |
Ping @ealsur I added some answers to your questions above - I still think there should be some way for the API to provide a ramp between a call that forces deserialization regardless of response code versus requiring the consumer to take on all the burden the minute they are interested in handling non-200 cases |
@ealsur bump - would be nice to conclude this discussion; it feels like this is a common requirement that the SDK does not address cleanly? |
@bartelink Isn't the |
@ealsur Its about avoiding the exception if you are handling a non-200 case. Let me try to explain betrer... The ask is for something like my This enables the conditional reading of the body by first looking at the status code in https://github.com/jet/equinox/blob/tidy-cosmosinit/src/Equinox.CosmosStore/CosmosStore.fs#L392-L398 A pidgin C# translation would be
The point is you want something pithy that lets you deserialize to a specific type after you have checked the StatusCode on the ResponseMessage ( ... figuring out that what How exactly to surface it give the serializer is on the container/client and not known to the ResponseMessage is the fun bit. Things that spring to mind for me are all ugly, i.e. the response including a |
So the ask is how to achieve typed APIs (for example,
This is completely missing the Diagnostics information though, so that needs to be taken in consideration. I don't see the SDK changing the behavior (type APIs not throwing), so the ask is, what is the official snippet or recommendation? |
Yes and no. The ask is:
The problem as I see it now is that any "snippet" / advice involves me having code my side doing Update: Yes, your snippet as above would be acceptable; effectively the ask is to provide some way to extract and deserialize the body as exactly as One thing to call out is that I definitely want to see the full ResponseMessage, to extract the |
I'm truly sorry but there is a part I don't understand in the sequence, the only scenario where the shared Tweet makes sense is from a performance perspective (throwing causes an overhead). Assuming the operation was a failure and an exception was thrown, there is no body to deserialize. The body is only deserialized on the success path (on the failure really the backend did not send any body). Let's run a scenario through the proposed steps, for example, a ReadItem returning 404.
All the error code situations contain a server response whose body is either empty or might contain some extra information of the error itself (case of TransactionalBatch), but nothing that it's useful for the original operation. If your intent is simply to defer serialization only on success cases, then that's what the SDK does already. |
The primary ask is to avoid exceptions - I fully expect and am ready to handle 304. It's not Exceptional. Its like Parse vs TryParse except we want diagnostics for both success and fail cases, not just a As it happens, for my use cases, I want/need the body in all success cases. If one cannot expect the body to be present, then I don't want to read it. Dropping to the Stream API happens to make it possible to do what I need, but in the most abstract sense, the need is some variant of
I am not arguing with this - if the SDK can add a I'm just trying to surface the whole requirement in case there is a better way to have this facility manifest in the API which e.g. covers more use cases and/or is more discoverable. I guess a spike reimplementing |
I see, so basically the ask is an API to invoke the internal serializer with a ResponseMessage response? For point operations it would be simple, but the real issue is for query responses or other feedtype responses. For example, if you have a ResponseMessage that represents a ReadItem, you could call @kirankumarkolli / @j82w - Do you folks have any thoughts on this? |
Yes, that represents the ask well. You raise good points about this only applying for individual Perhaps a "V4"-timescale revised API design can expose it in a way that is discoverable and covers all the cases. ... an, in the interim the |
Would adding an operation type to the ResponseMessage allow it to be handled correctly? |
ReadItemAsync is a wrapper around stream API, doing exactly the two steps mentioned in #303 (comment) It's very simple and straight forward. As in most cases having it as an extension method like ReadItemAsync404NotThrow() on Container also might make it more idiomatic. |
I think the problem here is that, as in my case, you frequently want to handle 304 etc in addition to 404, and having a custom extension for each case won't solve that, and you need to epose the ResponseMessage at some point in order to let people pull out the So for me, any real solution needs to do one of two things:
For example, if there was a:
Then Mathias's example can become:
And mine becomes:
While that also solves the problem, the question is how you feel about a |
Just a comment, 304 does never happen on ReadItem, the only scenario 304 is involved is for Change Feed operations. |
I'm over 99% sure that's not true - Equinox makes extensive use of conditional gets with etags to avoid paying for retrieval of bodies that have not change You can see the condition being applied in this file (Amusingly, I've just spotted I was erroneously labelling and logging as it as 302...) |
6a84812
to
dcc0766
Compare
This is super interesting, I was not aware a Read Item could return 304 using ETag (I was under the assumption that ETag was mainly used for optimistic concurrency), and could not find this use case in our documentation either, thanks for sharing. Having a generic deserializing method in my opinion will bring a deal of issues due to mis-use, there is no amount of documentation we can write that will avoid it. |
Yeah, I can't ague with that. If an API with a callback to extract from the ResponseMessage was to be provided, I'd definitely use it, but I'll definitely understand if that's not done now ... as long as there is an intent to provide such a facility in the V4 timeframe. It seems at this point that its reasonable to park this discussion for now with the following conclusions:
|
dcc0766
to
b400ca3
Compare
Long overdue cleanup in CosmosStore - initial logic was intentionally matching V2 init logic, but it can be clarified now based on: