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

rate_limit endpoint throws if over rate limit (LOL?) #856

Closed
miketaylr opened this issue Dec 11, 2015 · 10 comments
Closed

rate_limit endpoint throws if over rate limit (LOL?) #856

miketaylr opened this issue Dec 11, 2015 · 10 comments

Comments

@miketaylr
Copy link
Member

STR:

  1. Be at Mozlando on shared wifi
  2. Probably get GitHub to think we're DDOSing its API servers
    3):
python run.py 
 * Running on http://localhost:5000/ (Press CTRL+C to quit)
 * Restarting with stat
127.0.0.1 - - [11/Dec/2015 14:19:03] "GET /rate_limit HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/Users/miket/dev/compat/webcompat.com/env/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File "/Users/miket/dev/compat/webcompat.com/env/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/Users/miket/dev/compat/webcompat.com/env/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/miket/dev/compat/webcompat.com/env/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/miket/dev/compat/webcompat.com/env/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/miket/dev/compat/webcompat.com/env/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/miket/dev/compat/webcompat.com/env/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/miket/dev/compat/webcompat.com/env/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/miket/dev/compat/webcompat.com/webcompat/views.py", line 225, in show_rate_limit
    rl = json.loads(get_rate_limit())
  File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 366, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
TypeError: expected string or buffer
@hallvors
Copy link
Contributor

Does it work at all? :)

@hallvors
Copy link
Contributor

rl = json.loads(get_rate_limit())

should probably be

rl = json.loads(get_rate_limit()[0])

@hallvors
Copy link
Contributor

So, actually the root /rate_limit endpoint is always broken, the /api/rate_limit one is broken only when GitHub is not playing along. (The fix above will ensure both endpoints are broken only when GitHub acts up)

@miketaylr
Copy link
Member Author

Does it work at all? :)

We must have broken it at some point, it used to work in the past yes.

@miketaylr
Copy link
Member Author

s/We/I/ -- I think I unintentionally broke this when I refactored stuff into api_request.

@karlcow
Copy link
Member

karlcow commented Dec 15, 2015

The API changed. https://developer.github.com/v3/rate_limit/ rate will be dropped at a point.

But indeed the get sends back a list:

get_rate_limit() sends

('{ 
  "resources":{
    "core":{
      "limit":5000,
      "remaining":5000,
      "reset":1450157538
    },
    "search":{
      "limit":30,
      "remaining":30,
      "reset":1450153998
    }
  },
  "rate":{
    "limit":5000,
    "remaining":5000,
    "reset":1450157538
  }
}', 
200, 
{'etag': None, 
 'content-type': 'application/json', 
 'cache-control': 'no-cache'}
)

And the refactoring happened when working on #827
e655005#diff-b9ca02974fd8e51b2c21afc1f20d62b5L310

We were returning rl.content and now we return the full request with status_code, etc.

@miketaylr
Copy link
Member Author

Thanks for the diagnosis, @karlcow.

@karlcow
Copy link
Member

karlcow commented Dec 16, 2015

/me is looking at a fix and a test.

karlcow added a commit to karlcow/webcompat.com that referenced this issue Dec 16, 2015
karlcow added a commit to karlcow/webcompat.com that referenced this issue Dec 16, 2015
@karlcow karlcow self-assigned this Dec 16, 2015
@karlcow
Copy link
Member

karlcow commented Dec 16, 2015

Pull request done.

I have another worry which is not totally related to this issue.

Current user: webcompat-bot

Core resources rate limit: 4993 / 5000 requests.
Reset in 39 minutes.

Search rate limit: 30 / 30 requests.
Reset in 1 minute.

No matter how many search I tried to execute in 1 minute, I don't get a change on the search rate limit. Weird.

See http://localhost:5000/api/rate_limit

@miketaylr
Copy link
Member Author

No matter how many search I tried to execute in 1 minute, I don't get a change on the search rate limit. Weird.

Hm, maybe we never end up using those webcompat bot search requests. If you're logged in, it goes through webcompat as your account. If you're logged out, we bypass webcompat and make those requests via the client as unauthenticated ones.

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

No branches or pull requests

3 participants