Skip to content
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

Merged
merged 7 commits into from Apr 29, 2024

Conversation

bboreham
Copy link
Member

This is an alternative approach to fix the problem described in #13993 - where a query returns no data we should return

{"resultType":"matrix","result":[]}

and not:

{"resultType":"matrix","result":null}

The key idea is to add marshallers for Vector and Matrix in json_codec.go which will achieve this effect, regardless of whether the underlying data is nil 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 and unsafeMarshalSampleJSON, 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.

@roidelapluie
Copy link
Member

If the code is not exported it can be removed

@bboreham
Copy link
Member Author

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.

@ArthurSens
Copy link
Member

Could we change the default branch to release-2.52 to include the fix in the release? :)

@bboreham bboreham changed the base branch from main to release-2.52 April 29, 2024 12:24
@ArthurSens
Copy link
Member

@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>
@bboreham
Copy link
Member Author

Sorry, have rebased and force-pushed.

@ArthurSens ArthurSens merged commit 3d42466 into prometheus:release-2.52 Apr 29, 2024
29 checks passed
@alanprot
Copy link
Contributor

Can we also merge this on main? :)

@ArthurSens
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants