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

Plan listings don't react on page and per_page #69

Open
antoninrykalsky opened this issue Dec 21, 2023 · 7 comments
Open

Plan listings don't react on page and per_page #69

antoninrykalsky opened this issue Dec 21, 2023 · 7 comments

Comments

@antoninrykalsky
Copy link

antoninrykalsky commented Dec 21, 2023

Listing all plans returns 100 items. API does not respond to page or per_page query parameters.

Found while developing an ansible collection,
equinix/ansible-collection-equinix#146

@t0mk t0mk changed the title Paging in Plans API Plan listings don't react on page and per_page Dec 22, 2023
@t0mk
Copy link
Contributor

t0mk commented Dec 22, 2023

example check:

curl -H "X-Auth-Token: $METAL_AUTH_TOKEN"  "https://api.equinix.com/metal/v1/plans?per_page=90" | jq ".plans | length"

@t0mk
Copy link
Contributor

t0mk commented Dec 22, 2023

Page doesn't change:

Page doesn't change
curl -H "X-Auth-Token: $METAL_AUTH_TOKEN"  "https://api.equinix.com/metal/v1/plans?page=2" | md5sum -
curl -H "X-Auth-Token: $METAL_AUTH_TOKEN"  "https://api.equinix.com/metal/v1/plans?page=1" | md5sum -

@t0mk
Copy link
Contributor

t0mk commented Dec 22, 2023

type probably works:

curl -s -H "X-Auth-Token: $METAL_AUTH_TOKEN"  "https://api.equinix.com/metal/v1/plans?type=standard" | jq ".plans | length"
15

@ctreatma
Copy link
Contributor

I only get 63 plans, which indicates that I'm getting all plans back; it's possible that the same is happening in your case, and there really are exactly 100 plans available to you.

I also see that the API is not responding to pagination params, but on closer inspection, according to the spec, that endpoint doesn't support pagination parameters and the response schema doesn't include pagination metadata.

For categories, it appears that the spec is incorrect; the parameter name should be categories[]:

curl -H "X-Auth-Token: $METAL_AUTH_TOKEN"  "https://api.equinix.com/metal/v1/plans?categories[]=storage" | jq ".plans | length"

@t0mk
Copy link
Contributor

t0mk commented Dec 22, 2023

Oh I see what's going on there for me. I get duplicate entries in the plans listing, two entries are the same, they differ only in slug:

Duplicate 0:

{"id": "b2c4d757-d9b9-58cd-8380-393e0f4a16cb", "slug": "w3tintel.8358.512.6080",...}

Duplicate 1:

{"id": "b2c4d757-d9b9-58cd-8380-393e0f4a16cb", "slug": "w3tintel.8358.512.6080.x86",...}

There's 68 unique entries for me. I put python script that verifies this in next comment.

@t0mk
Copy link
Contributor

t0mk commented Dec 22, 2023

plans.json

#!/usr/bin/env python3

import json

with open("plans.json") as f:
    plans = json.load(f)['plans']


print("Number of plans:", len(plans))

ids = [p['id'] for p in plans]
print("Number of unique plans IDs:", len(set(ids)))

last_id = ids[-1]

dupes = [p for p in plans if p['id'] == last_id]

print("Number of plans with ID %s: %d" % (last_id, len(dupes)))

for i, d in enumerate(dupes):
    print("Duplicate %d:" % i)
    print(d)

print()

for k in dupes[0]:
    v0 = dupes[0][k]
    v1 = dupes[1][k]
    if v0 != v1:
        print("Same-ID plans differ in \"%s\": \"%s\" != \"%s\"" % (k, v0, v1))

print()


d = {}

for i in set(ids):
    ps = [p for p in plans if p['id'] == i]
    n = len(ps)
    d[ps[0]['slug']] = n
print("Number of plans in listing per slug:")
print("===================================")
for k, v in d.items():
    print(k, v)

@displague
Copy link
Member

displague commented Jan 18, 2024

Considering how unconventional this syntax is for the EM API, this may be an upstream defect. Another reason to question these results is that only one plan takes advantage of categories to report compute or legacy_gen.

$ emget '/plans?categories[]=compute' | jq -e '.plans[] .slug'
"c3.small.x86"

t0mk added a commit that referenced this issue Jan 18, 2024
This PR changes name of plans listing param `categories` to
`categories[]`.

discovered by @ctreatma 

#69 (comment)

related to #69 

I wonder if we should this also for devices lookup. @ctreatma has this
been fixed in metal-go?
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

No branches or pull requests

4 participants