Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
GraceDB Server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michael William Coughlin
GraceDB Server
Commits
2d1f0982
Commit
2d1f0982
authored
9 years ago
by
Branson Craig Stephens
Browse files
Options
Downloads
Patches
Plain Diff
Added throttling classes and some basic rates.
parent
46974c1c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
gracedb/api.py
+7
-0
7 additions, 0 deletions
gracedb/api.py
gracedb/throttles.py
+53
-0
53 additions, 0 deletions
gracedb/throttles.py
settings/default.py
+12
-1
12 additions, 1 deletion
settings/default.py
with
72 additions
and
1 deletion
gracedb/api.py
+
7
−
0
View file @
2d1f0982
...
...
@@ -31,6 +31,8 @@ from forms import CreateEventForm
from
permission_utils
import
user_has_perm
,
filter_events_for_user
from
guardian.models
import
GroupObjectPermission
from
throttles
import
EventCreationThrottle
,
AnnotationThrottle
from
alert
import
issueAlertForUpdate
from
buildVOEvent
import
buildVOEvent
,
VOEventBuilderException
...
...
@@ -384,6 +386,7 @@ class EventList(APIView):
permission_classes
=
(
IsAuthenticated
,
IsAuthorizedForPipeline
)
parser_classes
=
(
parsers
.
MultiPartParser
,)
renderer_classes
=
(
JSONRenderer
,
BrowsableAPIRenderer
,
LigoLwRenderer
,
TSVRenderer
,)
throttle_classes
=
(
EventCreationThrottle
,)
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
...
...
@@ -729,6 +732,7 @@ class EventLogList(APIView):
"""
authentication_classes
=
(
LigoAuthentication
,)
permission_classes
=
(
IsAuthenticated
,
IsAuthorizedForEvent
,)
throttle_classes
=
(
AnnotationThrottle
,)
@event_and_auth_required
def
get
(
self
,
request
,
event
):
...
...
@@ -847,6 +851,7 @@ class EMBBEventLogList(APIView):
"""
authentication_classes
=
(
LigoAuthentication
,)
permission_classes
=
(
IsAuthenticated
,
IsAuthorizedForEvent
,)
throttle_classes
=
(
AnnotationThrottle
,)
@event_and_auth_required
def
get
(
self
,
request
,
event
):
...
...
@@ -917,6 +922,7 @@ class EMObservationList(APIView):
"""
authentication_classes
=
(
LigoAuthentication
,)
permission_classes
=
(
IsAuthenticated
,
IsAuthorizedForEvent
,)
throttle_classes
=
(
AnnotationThrottle
,)
@event_and_auth_required
def
get
(
self
,
request
,
event
):
...
...
@@ -1667,6 +1673,7 @@ class VOEventList(APIView):
"""
authentication_classes
=
(
LigoAuthentication
,)
permission_classes
=
(
IsAuthenticated
,
IsAuthorizedForEvent
,)
throttle_classes
=
(
AnnotationThrottle
,)
@event_and_auth_required
def
get
(
self
,
request
,
event
):
...
...
This diff is collapsed.
Click to expand it.
gracedb/throttles.py
0 → 100644
+
53
−
0
View file @
2d1f0982
from
rest_framework.throttling
import
UserRateThrottle
class
PostOrPutUserRateThrottle
(
UserRateThrottle
):
def
allow_request
(
self
,
request
,
view
):
"""
This is mostly copied from the Rest Framework
'
s SimpleRateThrottle
except we now pass the request to throttle_success
"""
if
self
.
rate
is
None
:
return
True
self
.
key
=
self
.
get_cache_key
(
request
,
view
)
if
self
.
key
is
None
:
return
True
self
.
history
=
self
.
cache
.
get
(
self
.
key
,
[])
self
.
now
=
self
.
timer
()
# Drop any requests from the history which have now passed the
# throttle duration
while
self
.
history
and
self
.
history
[
-
1
]
<=
self
.
now
-
self
.
duration
:
self
.
history
.
pop
()
if
len
(
self
.
history
)
>=
self
.
num_requests
:
return
self
.
throttle_failure
()
return
self
.
throttle_success
(
request
)
def
throttle_success
(
self
,
request
):
"""
Inserts the current request
'
s timestamp along with the key
into the cache. Except we only do this if the request is a
writing method (POST or PUT). That
'
s why we needed the request.
"""
if
request
.
method
in
[
'
POST
'
,
'
PUT
'
]:
self
.
history
.
insert
(
0
,
self
.
now
)
self
.
cache
.
set
(
self
.
key
,
self
.
history
,
self
.
duration
)
return
True
def
wait
(
self
):
"""
The HTTPError exception includes a little message with the recommended
wait time. However, this doesn
'
t seem to work very well with fractional
seconds. Returning
'
None
'
will prevent it from trying to recommend a
wait time.
"""
return
None
class
EventCreationThrottle
(
PostOrPutUserRateThrottle
):
scope
=
'
event_creation
'
class
AnnotationThrottle
(
PostOrPutUserRateThrottle
):
scope
=
'
annotation
'
This diff is collapsed.
Click to expand it.
settings/default.py
+
12
−
1
View file @
2d1f0982
...
...
@@ -105,6 +105,13 @@ DATABASES = {
}
}
CACHES
=
{
'
default
'
:
{
'
BACKEND
'
:
'
django.core.cache.backends.memcached.MemcachedCache
'
,
'
LOCATION
'
:
'
127.0.0.1:11211
'
,
}
}
# SkyAlert
SKYALERT_IVORN_PATTERN
=
"
ivo://gwnet/gcn_sender#%s
"
...
...
@@ -305,7 +312,11 @@ INSTALLED_APPS = (
)
REST_FRAMEWORK
=
{
'
PAGINATE_BY
'
:
10
'
PAGINATE_BY
'
:
10
,
'
DEFAULT_THROTTLE_RATES
'
:
{
'
event_creation
'
:
'
5/second
'
,
'
annotation
'
:
'
10/second
'
,
},
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment