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
Client API: don't read entire response into a buffer before parsing it #977
Comments
Thanks for bringing it up. I'm happy to accept any changes for the API part. It is still considered experimental and we have wiggle room to experiment. |
Right now I don't expect to start on this. It's quite a big job and not critical to what I'm doing. There was some discussion in #763 of code-generating the API, which seems an attractive way to make such structural changes. |
Hey @kakkoyun, can I take this up? This is basically changing the methods to return parsed data instead of |
The current code calls My idea was to parse JSON from |
The Full flow through which I reached here: DoGetFallback -> apiClientImpl.Do -> httpClient.Do |
Had some discussion on this thread on Slack that the aim is likely to parse
|
I think we need to check the codebase for this. If the result of this method is always consumed as JSON, we should unmarshal once and as early as possible. In any case, we should do this by introducing a new method and marking older methods as deprecated. We can remove them with v2. |
The main API is methods like:
this returns structured data, not JSON. My proposal is to change how we arrive at the structured data. No public API needs to change to achieve this. |
Signed-off-by: Ujjwal Goyal <importujjwal@gmail.com>
Signed-off-by: Ujjwal Goyal <importujjwal@gmail.com>
I've just noticed that the code calls the JSON parser twice to read each request. Once in `apiClientImpl.Do: client_golang/api/prometheus/v1/api.go Line 1140 in 618194d
and once in the individual API methods like client_golang/api/prometheus/v1/api.go Line 859 in 618194d
Then, different data types make nested calls: client_golang/api/prometheus/v1/api.go Line 584 in 618194d
I suspect the first two could be merged without major change, but the last kind needs the code rewritten in "streaming" style to avoid building an intermediate buffer. |
The API client functions all follow this pattern, where they make an http call to get back a
[]byte
then decode the JSON:client_golang/api/prometheus/v1/api.go
Lines 830 to 836 in f63e219
For larger responses, this buffer gets quite expensive (see #976).
I propose that instead we parse JSON from the response body as it comes in.
I can see that this would make handling timeouts more complicated.
The text was updated successfully, but these errors were encountered: