-
Notifications
You must be signed in to change notification settings - Fork 1
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
@Outlinevpn Process Daily usage statistics #870
Conversation
@m453h refer to this when reviewing implementation plan. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏽
--
Think about naming and structuring things e.g. in lib, may be there should be an outline.js
file that handles pulling data from the VPN backend. API end points, may be they can be a bit more RESTful i.e. /api/statics with PUT or POST updating the stats and GET returning the stats, etc.
Update 1
On APIs, I think the processGSheet
is the biggest offender ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
Thanks @koechkevin , I've gained further context after carefully reading through the implementation plan and it looks solid. I could be missing something but looking at the Table, I was thinking that UPSERT could simplify the whole operation of calculating and inserting the user stats if we keep userId
and date
as unique constraints.
The key ( I think lets remove |
Latest updated Preview URL
|
The data usage API was hardcoded only to obtain data transferred in the last (30 * 24) hours creating a sliding window problem, which makes the daily computations we have proposed in this PR inaccurate. We may have to open a PR for the above fix or fork the repository to deploy. |
Not sure I fully follow @koechkevin (or have full context) but:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🚀
Just an additional thought, the Filters
interface could have stricter types for orderBy
since we know the fields we would expect
Description
Currently, Outline vpn manager statistics are generated monthly by running this script.
We are currently proposing a solution that allows a user get these stats easily without always having the intervention of tech team devs.
Here is the proposed implementation plan
This PR introduces 2 API endpoints.
POST /api/userStatistics
: To query outline vpn API for the statistics, calculate daily usage then store it in a local database for analysis. This endpoint will be executed via a cron.GET /api/userStatistics
: Gets the stored statistics in the database as per the queries sent.Process Daily User Statistics.
This action is triggered by
POST /api/userStatistics
. Since The Outline VPN API returns only userId and total data transferred by the user over time, we need to find a way to calculate daily usage by finding the difference from last fetch.Get statistics.
GET /api/userStatistics
This API allows users to fetch stored statistics from the database based on various filters. The records can be filtered by date, email, date range, user ID, and record ID. Results can also be grouped and ordered based on specific fields.
date
string
YYYY-MM-DD
format.?date=2024-09-03
email
string
[email protected]
dateBetween.start
string
dateBetween.end
.?dateBetween.start=2024-09-03
dateBetween.end
string
dateBetween.start
.?dateBetween.end=2024-09-04
ID
number
?ID=45
userId
number
?userId=107
orderBy
string
ASC
) or descending (DESC
) order.?orderBy=usage DESC
groupBy
*string
email
,date
.?groupBy=email
The response will return records in the format
Grouped by Email
Grouped by Date
Fixes #875
Type of change
New feature (non-breaking change which adds functionality)
This change requires a documentation update
Screenshots
Checklist: