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
bugfix: API: encode empty Vector/Matrix as [] not null #13997
Conversation
06eb3a5
to
b04fc88
Compare
If the code is not exported it can be removed |
It is registered with jsoniter as a side-effect of importing the package, so we don't know if someone expects it to be there. |
Could we change the default branch to |
@bboreham, I believe a few extra commits were added to the PR after you switched the base branch. Do you mind adjusting it? |
Since we already use require.JSONEq in similar cases. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
So that tests use the same encoding as the api. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
When we want to check just the json encoding. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
The typed versions are used when we call from one marshaller to another. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
If the underlying data is `nil` the default encoding will render `"null"` which is not accepted by (some) Prometheus client libraries. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
b04fc88
to
5c8ffaa
Compare
Sorry, have rebased and force-pushed. |
Can we also merge this on main? :) |
Im trying to get the release out today, just need some approvals 😬 I'll open a PR to merge the release branch back to main immediately after |
This is an alternative approach to fix the problem described in #13993 - where a query returns no data we should return
and not:
The key idea is to add marshallers for
Vector
andMatrix
injson_codec.go
which will achieve this effect, regardless of whether the underlying data isnil
or a zero-length slice.However I discovered that the api tests don't actually use these marshallers, so some modifications were needed to address that.
After these changes, we probably don't need to register
unsafeMarshalFPointJSON
,unsafeMarshalHPointJSON
andunsafeMarshalSampleJSON
, since Prometheus doesn't attempt to marshal single instances of those objects. But I left the code in place to avoid surprises, perhaps in a 3rd-party downstream.