Stream responses where appropriate#10554
Conversation
There was a problem hiding this comment.
Looks good. The change to return http::status::accepted instead seems reasonable, but shouldn't that be documented somewhere?
I didn't find much referencing the status codes to expect from our API, except the example client code for the various languages. At least those should be adapted. Maybe adding a small paragraph/table detailing which handlers return 200 and which return 202 would be a good idea.
Edit: The "Responses" section needs to be adapted.
Not that I know of. Of course, this is kinda a breaking change, so it should definitely be mentioned in the changelog, but I don't think that we have a specific place for documenting changes to the API return codes.
Ok! |
On second thought, I think it is basically fine as it is. The next section "HTTP Statuses" mentions that everything from 200 to 299 is a success. Maybe a short mention that most handlers return either 200 or 202 in case of success, depending on whether the result is known at the time the Header is sent. But the example code snippets definitely need to be fixed, currently they all check for Ok/200 specifically on "v1/objects/services", which would fail now. Even though that's easy to notice what's wrong, that'd not be a good documentation experience for the user. |
f7d1e99 to
128746b
Compare
jschmidt-icinga
left a comment
There was a problem hiding this comment.
I haven't verified the changes to the golang snippet, but otherwise the documentation changes look great. I also gave each handler a quick test yesterday and everything works as expected.
After looking through the remaining handlers, another one that could be streamed is /v1/templates. The change would be minimal, I think freezing the Array and adding the yc to SendJsonBody() should be enough now. Same for the GET side of /v1/config/packages and /v1/config/stages. Those are probably not strictly necessary, but I'd say about on the same level as /v1/types and /v1/variables and since you did those, you might as well do these.
That handler holds a locked mutex while generating the body, so can't use streaming. Plus, the response is minimal, so it doesn't need any workaround. |
128746b to
5a8c46b
Compare
Done! I've frozen the results array for the |
5a8c46b to
e6d91b2
Compare
|
Does one of you understand why this test failed? It says The exception could be from the Edit: It might be because of a clock anomaly where the runner might have adjusted time back a second which would affect |
I think, I have seen the error with #10550 before I changed it to use |
Was this also on Windows?
Sounds plausible, but also like it would take quite some digging to confirm. Anyway, this PR only touches HTTP handlers, which aren't even accessed by that test case (it only creates a idle connection), so really nothing to do here in this PR. Either #10550 just fixes it and we're happy, or if it happens again, we might want to take a closer look. |
e6d91b2 to
93421a8
Compare
Apparently, Windows has some serious issues. Now, Win64 is failing due to the newly changed timer/invoke intervals. It didn't fail before in the PR that changed the intervals, but now it does. I don't understand this ** OS at all. |
jschmidt-icinga
left a comment
There was a problem hiding this comment.
I think the new ValueGenerator is a good improvement on the interface side without complicating the implementation by much. But I do have one small request about the test cases (see below).
97d1004 to
620949f
Compare
jschmidt-icinga
left a comment
There was a problem hiding this comment.
Unless you've changed anything besides resolving the merge-conflicts, this is still fine from my side.
Yes, I didn't change anything apart from resolving the conflicts, which involved removing some codes regarding the ticket salt and the generator being able to skip elements. |
|
Oh, and it has merge conflicts now that need to be resolved as well 😅 |
julianbrost
left a comment
There was a problem hiding this comment.
See #10554 (review). With that, this PR probably shouldn't show as approved in lists :)
08b5776 to
508dc60
Compare
72e5b9b to
b6ffce1
Compare
b6ffce1 to
78b89f9
Compare
|
The end result of our discussion from today about this is as follows: We won't break any existing handler by changing their HTTP status code to 202. Instead, the End of the discussion. If I missed anything please extend this message with the missing information. |
This commit refactors the ValueGenerator class to be a template that can work with any container type. Previously, one has to manually take care of the used container by lazily iterating over it within a lambda. Now, the `ValueGenerator` class itself takes care of all the iteration, making it easier to use and less error-prone. The new base `Generator` class is required to allow the `JsonEncoder` to handle generators in a type-erased manner.
78b89f9 to
72abc59
Compare
72abc59 to
d4d46a9
Compare
julianbrost
left a comment
There was a problem hiding this comment.
Looks good to me now, thank you! I know, it's not really what we all had hoped for in the beginning, but sometimes things aren't as simple as one thought, for everything else not done in this PR, there's now #10717.
I'm not merging this immediately as there were quite some changes recently. So if anyone wants to take another look, now is your chance.
I've now removed this from the PR description as this PR no longer contradicts that issue. |
jschmidt-icinga
left a comment
There was a problem hiding this comment.
Also gave it another quick look and still looks fine to me.
This PR changes some of our HTTP handlers to stream responses instead of buffering them in memory, just like how @jschmidt-icinga did for the
ObjectQueryHandlerin #10516.fixes #10544
fixes #10407