api-umbrella icon indicating copy to clipboard operation
api-umbrella copied to clipboard

Question: Setting custom rate limits with Admin API

Open jykae opened this issue 9 years ago • 6 comments

I am having problems setting custom rate limit through Admin API.

Docs http://api-umbrella.readthedocs.io/en/latest/admin/api.html say fields are:

ApiSettingsRateLimit {
id (string, optional),
duration (integer, optional),
accuracy (integer, optional),
limit_by (string, optional) = ['ip', 'apiKey'],
distributed (boolean, optional),
response_headers (boolean, optional)
}

Github code: https://github.com/NREL/api-umbrella/blob/222aa383e7b5b56d0f8ed38d58415da8d33f47a9/src/api-umbrella/web-app/app/assets/javascripts/admin/models/api/rate_limit.js

Admin.ApiRateLimit = Ember.Model.extend({
  id: Ember.attr(),
  duration: Ember.attr(Number),
  limitBy: Ember.attr(),
  limit: Ember.attr(),
  responseHeaders: Ember.attr(),

Is there only "duration" field and not "accuracy" field? If so, is duration in seconds, minutes, hours.. ?

In overall, would be great to have more documentation about the fields that are not self-descriptive.

jykae avatar Jul 28 '16 11:07 jykae

As I looked further that Github code, looks like duration is in milliseconds, I got it somehow working by guessing and trying.

jykae avatar Jul 28 '16 13:07 jykae

Sorry for the delay. Yes, duration and accuracy are both given in milliseconds. I'll try to get the docs updated about that.

duration is a required field, while accuracy is optional. In fact, we don't actually expose the accuracy field in our web admin tool, since we haven't really encountered a situation where it needs to be manually tuned.

But for a short description, accuracy essentially dictates how many buckets to divide the duration into for tracking purposes. There's a bit more info here: https://github.com/NREL/api-umbrella/blob/v0.13.0/config/README.md#apisettingsrate_limits You can also see the default accuracy logic based on the duration here: https://github.com/NREL/api-umbrella/blob/v0.13.0/src/api-umbrella/web-app/app/models/api/rate_limit.rb#L46-L74

GUI avatar Aug 02 '16 03:08 GUI

Thanks for answer @GUI How can I set back to default rate limits through Admin API? Rate limit mode allowed values are ["unlimited", "custom"]

jykae avatar Aug 10 '16 06:08 jykae

I believe a null value should also be allowed, which corresponds to the default value. Let us know if that's not the case, though.

GUI avatar Aug 10 '16 06:08 GUI

@GUI Sorry for long delay, we had this task on hold. null works, resets to default rate limits

Please document it though, if others wonder the same.

jykae avatar Sep 30 '16 11:09 jykae

many years passed. Sorry for bringing this issue up.

I tried to apply rate limit to an API user with 30 days (2592000000) duration via Admin API. Although the rate limit seems to be inserted to the database, some fields like _id and id are null and on the dashboard the custom rate limit are not properly reflected (see the screenshot). Another weird behavior I noticed is that the rate limit works only for a day, the next day it resets. Are there any another fields need to be set via Admin API besides the ones under RateLimit? Screen Shot 2021-01-15 at 12 17 19 PM

onaralili avatar Jan 15 '21 08:01 onaralili