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

Arrays in HTTP API responses are not sorted #327

Closed
victorb opened this issue Mar 5, 2018 · 4 comments · Fixed by #878
Closed

Arrays in HTTP API responses are not sorted #327

victorb opened this issue Mar 5, 2018 · 4 comments · Fixed by #878
Assignees
Labels
exp/novice Someone with a little familiarity can pick up help wanted Seeking public contribution on this issue kind/enhancement A net-new feature or improvement to an existing feature P1 High: Likely tackled by core team if no one steps up status/ready Ready to be worked
Milestone

Comments

@victorb
Copy link

victorb commented Mar 5, 2018

Somewhat annoying but minor issue.

When making API requests to ipfs-cluster, it seems that the response sometimes changes the order of the arrays. So the first request returns {"peers": ["A", "B"]} and the second one could return {"peers": ["B", "A"]} randomly. This is a bit annoying since responses are harder to cache, since the ordering in arrays are important.

Sorting the arrays before letting the HTTP endpoint respond, would solve this issue.

The endpoints I've found so far not properly sorting before responding:

Endpoint Attributes(s) not sorted
/id addresses, cluster_peers_addresses and ipfs.addresses
/allocations Response is non-sorted array
/peers Each peer has the same response from /id so needs sorting on the same attributes

I'm sure I missed others, but I've not used all API endpoints.

@victorb victorb added the kind/bug A bug in existing code (including security flaws) label Mar 5, 2018
@hsanjuan hsanjuan added kind/enhancement A net-new feature or improvement to an existing feature exp/novice Someone with a little familiarity can pick up status/ready Ready to be worked P2 Medium: Good to have, but can wait until someone steps up and removed kind/bug A bug in existing code (including security flaws) labels Mar 5, 2018
@hsanjuan
Copy link
Collaborator

hsanjuan commented Mar 5, 2018

Some things might be worth sorting in the ToSerial() methods in api/types.go for convenience.

I don't think we'll sort Allocations, as that can grow significantly to the point it might affect performance.

@hsanjuan
Copy link
Collaborator

One other thing that should be sorted is the map of peers in PinInfo when printed. We don't have ToSerial() methods anymore though, so this would be purely an ipfs-cluster-ctl thing.

@hsanjuan hsanjuan added this to the Q2 2019 Easy milestone Apr 25, 2019
@hsanjuan hsanjuan added the help wanted Seeking public contribution on this issue label Apr 25, 2019
@kishansagathiya
Copy link
Contributor

I am assuming that there number of pins will be much more than number of peers. So, I see only two outputs that we can sort without affecting performance.

At API level:
[]*api.ID could be sorted by peers for peer listing (GET /peers)
[]api.Metric could be sorted by peers

@hsanjuan
Copy link
Collaborator

See if you can find why peers ls or status comes out unsorted at all. You probably arrive to Peers() giving an unsorted list of peers so that the responses to the broadcast request to those peers are in different order everytime. And this might come to the monitor giving metrics in different order on crdts.

Also worth sorting the addresses as mentioned at the top.

@hsanjuan hsanjuan added P1 High: Likely tackled by core team if no one steps up and removed P2 Medium: Good to have, but can wait until someone steps up labels Jul 23, 2019
@kishansagathiya kishansagathiya self-assigned this Aug 28, 2019
@hsanjuan hsanjuan mentioned this issue Sep 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
exp/novice Someone with a little familiarity can pick up help wanted Seeking public contribution on this issue kind/enhancement A net-new feature or improvement to an existing feature P1 High: Likely tackled by core team if no one steps up status/ready Ready to be worked
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants