Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
FoD
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
David Schmitz
FoD
Commits
ffbe0460
Commit
ffbe0460
authored
1 year ago
by
Nino tsulaia
Committed by
David Schmitz
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Added endpoint to get stats for all routes only with last time stamp
parent
7d62c8e0
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
flowspec/viewsets.py
+54
-0
54 additions, 0 deletions
flowspec/viewsets.py
flowspy/urls.py
+4
-0
4 additions, 0 deletions
flowspy/urls.py
with
58 additions
and
0 deletions
flowspec/viewsets.py
+
54
−
0
View file @
ffbe0460
import
json
import
datetime
from
django.shortcuts
import
get_object_or_404
from
django.conf
import
settings
from
django.contrib.auth.models
import
User
...
...
@@ -496,6 +498,58 @@ class StatsRoutesViewSet(viewsets.ViewSet):
logger
.
info
(
"
StatsRoutesViewSet:::retrieve(): route.name=
"
+
str
(
route
.
name
))
return
routestats
(
request
,
route
.
name
)
class
StatsAllRoutesViewSet
(
viewsets
.
ViewSet
):
"""
A simple Vieset for retrieving statistics of all routes by
an authenticated user.
"""
permission_classes
=
(
IsAuthenticated
,)
def
retrieve
(
self
,
request
):
logger
.
info
(
"
StatsRoutesViewSet:::retrieve():
"
)
queryset
=
Route
.
objects
.
all
()
from
flowspec.views
import
routestats
route_stats
=
[]
for
r
in
queryset
:
route
=
get_object_or_404
(
queryset
,
id
=
r
.
id
)
logger
.
info
(
"
StatsRoutesViewSet:::retrieve(): route.name=
"
+
str
(
route
.
name
))
route_stat
=
routestats
(
request
,
route
.
name
)
route_stats
.
append
(
json
.
loads
(
route_stat
.
content
.
decode
(
'
utf-8
'
)))
return
Response
(
route_stats
,
status
=
status
.
HTTP_200_OK
)
class
StatsAllRoutesLastTSViewSet
(
viewsets
.
ViewSet
):
"""
A simple Vieset for retrieving statistics of all routes with last time stamp by
an authenticated user.
"""
permission_classes
=
(
IsAuthenticated
,)
def
retrieve
(
self
,
request
):
logger
.
info
(
"
StatsRoutesViewSet:::retrieve():
"
)
queryset
=
Route
.
objects
.
all
()
from
flowspec.views
import
routestats
route_stats
=
[]
for
r
in
queryset
:
route
=
get_object_or_404
(
queryset
,
id
=
r
.
id
)
logger
.
info
(
"
StatsRoutesViewSet:::retrieve(): route.name=
"
+
str
(
route
.
name
))
route_stat
=
routestats
(
request
,
route
.
name
)
route_stat_data
=
json
.
loads
(
route_stat
.
content
.
decode
(
'
utf-8
'
))
converted_data
=
list
(
map
(
self
.
time_stamp_converter
,
route_stat_data
[
"
data
"
]))
max_stats
=
max
(
converted_data
,
key
=
lambda
x
:
x
[
"
time_stamp
"
])
del
max_stats
[
"
time_stamp
"
]
route_stat_data
[
"
data
"
]
=
[
max_stats
]
route_stats
.
append
(
route_stat_data
)
return
Response
(
route_stats
,
status
=
status
.
HTTP_200_OK
)
def
time_stamp_converter
(
self
,
item
):
ts
=
datetime
.
datetime
.
strptime
(
item
[
"
ts
"
],
'
%Y-%m-%dT%H:%M:%S.%f
'
)
item
[
"
time_stamp
"
]
=
ts
return
item
#############################################################################
#############################################################################
...
...
This diff is collapsed.
Click to expand it.
flowspy/urls.py
+
4
−
0
View file @
ffbe0460
...
...
@@ -15,6 +15,8 @@ from flowspec.viewsets import (
MatchProtocolViewSet
,
MatchDscpViewSet
,
StatsRoutesViewSet
,
StatsAllRoutesViewSet
,
StatsAllRoutesLastTSViewSet
,
)
from
django_registration
import
views
as
registration_views
...
...
@@ -68,6 +70,8 @@ urlpatterns = [
path
(
'
tinymce/
'
,
include
(
'
tinymce.urls
'
)),
url
(
r
'
^overview/?$
'
,
flowspec_views
.
overview
,
name
=
"
overview
"
),
url
(
r
'
^api/
'
,
include
(
router
.
urls
)),
url
(
r
'
^api/stats/all/routes/$
'
,
StatsAllRoutesViewSet
.
as_view
({
'
get
'
:
'
retrieve
'
}),
name
=
'
statsroutesall
'
),
url
(
r
'
^api/stats/all/routes/last-ts/$
'
,
StatsAllRoutesLastTSViewSet
.
as_view
({
'
get
'
:
'
retrieve
'
}),
name
=
'
statsroutesall_last_ts
'
),
url
(
r
'
^details/(?P<route_slug>[\w\-]+)/$
'
,
flowspec_views
.
routedetails
,
name
=
"
route-details
"
),
url
(
r
'
^routestats/(?P<route_slug>[\w\-]+)/$
'
,
flowspec_views
.
routestats
,
name
=
"
routestats
"
),
url
(
r
'
^setup/
'
,
flowspec_views
.
setup
,
name
=
'
setup
'
),
...
...
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